Skip to content

Commit

Permalink
Fix issue 129; check RTC clock source and set prescaler value
Browse files Browse the repository at this point in the history
  • Loading branch information
chwon64 committed Jul 19, 2019
1 parent 25cdc42 commit abbb9e0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/CatenaSamd21.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class CatenaSamd21 : public CatenaBase

virtual void Sleep(uint32_t howLongInSeconds) override;

CatenaRTC::CalendarTime GetCalendarTime(void)
{
return this->m_Rtc.GetTime();
}

protected:
virtual void registerCommands(void);

Expand Down
5 changes: 5 additions & 0 deletions src/CatenaStm32L0.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class CatenaStm32L0 : public CatenaStm32

virtual void Sleep(uint32_t howLongInSeconds) override;

CatenaStm32L0Rtc::CalendarTime GetCalendarTime(void)
{
return this->m_Rtc.GetTime();
}

protected:
// methods
virtual void registerCommands(void);
Expand Down
28 changes: 20 additions & 8 deletions src/lib/stm32/stm32l0/CatenaStm32L0Rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,32 @@ bool CatenaStm32L0Rtc::begin(bool fResetTime)
{
RTC_TimeTypeDef Time;
RTC_DateTypeDef Date;
uint32_t RtcClock;

// memset(&this->m_hRtc, 0, sizeof(this->m_hRtc));

this->m_hRtc.Instance = RTC;
this->m_hRtc.Init.HourFormat = RTC_HOURFORMAT_24;
// this->m_hRtc.Init.AsynchPrediv = 37 - 1; /* 37kHz / 37 = 1000Hz */
// this->m_hRtc.Init.SynchPrediv = 1000 - 1; /* 1000Hz / 1000 = 1Hz */

// this->m_hRtc.Init.AsynchPrediv = 64 - 1; /* 40kHz / 64 = 625Hz */
// this->m_hRtc.Init.SynchPrediv = 625 - 1; /* 625Hz / 625 = 1Hz */
RtcClock = __HAL_RCC_GET_RTC_SOURCE();
if (RtcClock == RCC_RTCCLKSOURCE_LSI)
{
this->m_hRtc.Init.AsynchPrediv = 37 - 1; /* 37kHz / 37 = 1000Hz */
this->m_hRtc.Init.SynchPrediv = 1000 - 1; /* 1000Hz / 1000 = 1Hz */
}
else if (RtcClock == RCC_RTCCLKSOURCE_LSE)
{
this->m_hRtc.Init.AsynchPrediv = 128 - 1; /* 32768Hz / 128 = 256Hz */
this->m_hRtc.Init.SynchPrediv = 256 - 1; /* 256Hz / 256 = 1Hz */
}
else
{
/* use HSE clock -- not defined HSE input clock value */
// this->m_hRtc.Init.AsynchPrediv = 64 - 1; /* 40kHz / 64 = 625Hz */
// this->m_hRtc.Init.SynchPrediv = 625 - 1; /* 625Hz / 625 = 1Hz */
Serial.println("RTC clock use HSE and not supported yet!");
return false;
}

this->m_hRtc.Init.AsynchPrediv = 128 - 1; /* 32768Hz / 128 = 256Hz */
// this->m_hRtc.Init.SynchPrediv = 256 - 1; /* 256Hz / 256 = 1Hz */
this->m_hRtc.Init.SynchPrediv = 256; /* 256Hz / 256 = 1Hz */

this->m_hRtc.Init.OutPut = RTC_OUTPUT_DISABLE;
this->m_hRtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
Expand Down

0 comments on commit abbb9e0

Please sign in to comment.