Skip to content

Commit 79f634e

Browse files
authored
Merge pull request #5 from fpistm/LP
Add private method to configure RTC for low power
2 parents ca0911e + b1fbc08 commit 79f634e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/STM32RTC.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,39 @@ void STM32RTC::setY2kEpoch(uint32_t ts)
892892
}
893893
}
894894

895+
/**
896+
* @brief configure RTC source clock for low power
897+
* @param none
898+
*/
899+
void STM32RTC::configForLowPower(void)
900+
{
901+
#if defined(HAL_PWR_MODULE_ENABLED)
902+
if (!_configured){
903+
// LSE must be selected as clock source to wakeup the device from shutdown mode
904+
_clockSource = RTC_LSE_CLOCK;
905+
// Enable RTC
906+
begin();
907+
} else {
908+
if (_clockSource != RTC_LSE_CLOCK) {
909+
// Save current config
910+
RTC_AM_PM period;
911+
uint32_t subSeconds;
912+
uint8_t seconds, minutes, hours, weekDay, day, month, years;
913+
getDate(&weekDay, &day, &month, &years);
914+
getTime(&seconds, &minutes, &hours, &subSeconds, &period);
915+
end();
916+
// LSE must be selected as clock source to wakeup the device from shutdown mode
917+
_clockSource = RTC_LSE_CLOCK;
918+
// Enable RTC
919+
begin(period);
920+
// Restore config
921+
setTime(seconds, minutes, hours, subSeconds, period);
922+
setDate(weekDay, day, month, years);
923+
}
924+
}
925+
#endif
926+
}
927+
895928
/**
896929
* @brief synchronise the time from the current RTC one
897930
* @param none

src/STM32RTC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ class STM32RTC {
183183
return _configured;
184184
}
185185

186+
friend class STM32LowPower;
187+
186188
private:
187189
STM32RTC(void): _clockSource(RTC_LSI_CLOCK) {}
188190

@@ -208,6 +210,8 @@ class STM32RTC {
208210

209211
RTC_Source_Clock _clockSource;
210212

213+
void configForLowPower(void);
214+
211215
void syncTime(void);
212216
void syncDate(void);
213217
void syncAlarmTime(void);

0 commit comments

Comments
 (0)