Skip to content

Commit a5d85f9

Browse files
committed
Add RTC clock source parameter for low power config
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent b0faddc commit a5d85f9

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/STM32RTC.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -936,30 +936,43 @@ void STM32RTC::setY2kEpoch(uint32_t ts)
936936
* @brief configure RTC source clock for low power
937937
* @param none
938938
*/
939-
void STM32RTC::configForLowPower(void)
939+
void STM32RTC::configForLowPower(RTC_Source_Clock source)
940940
{
941941
#if defined(HAL_PWR_MODULE_ENABLED)
942942
if (!_configured){
943-
// LSE must be selected as clock source to wakeup the device from shutdown mode
944-
_clockSource = RTC_LSE_CLOCK;
943+
_clockSource = source;
945944
// Enable RTC
946945
begin();
947946
} else {
948-
if (_clockSource != RTC_LSE_CLOCK) {
947+
if (_clockSource != source) {
949948
// Save current config
950-
RTC_AM_PM period;
949+
RTC_AM_PM period, alarmPeriod = _alarmPeriod;
951950
uint32_t subSeconds;
952951
uint8_t seconds, minutes, hours, weekDay, day, month, years;
952+
uint8_t alarmSeconds, alarmMinutes, alarmHours, alarmDay;
953+
Alarm_Match alarmMatch = _alarmMatch;
954+
bool alarmEnabled = _alarmEnabled;
955+
956+
alarmDay = _alarmDay;
957+
alarmHours = _alarmHours;
958+
alarmMinutes = _alarmMinutes;
959+
alarmSeconds = _alarmSeconds;
960+
953961
getDate(&weekDay, &day, &month, &years);
954962
getTime(&seconds, &minutes, &hours, &subSeconds, &period);
963+
955964
end();
956-
// LSE must be selected as clock source to wakeup the device from shutdown mode
957-
_clockSource = RTC_LSE_CLOCK;
965+
_clockSource = source;
958966
// Enable RTC
959967
begin(period);
960968
// Restore config
961969
setTime(seconds, minutes, hours, subSeconds, period);
962970
setDate(weekDay, day, month, years);
971+
setAlarmTime(alarmHours, alarmMinutes, alarmSeconds, alarmPeriod);
972+
setAlarmDay(alarmDay);
973+
if(alarmEnabled) {
974+
enableAlarm(alarmMatch);
975+
}
963976
}
964977
}
965978
#endif

src/STM32RTC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class STM32RTC {
213213

214214
RTC_Source_Clock _clockSource;
215215

216-
void configForLowPower(void);
216+
void configForLowPower(RTC_Source_Clock source);
217217

218218
void syncTime(void);
219219
void syncDate(void);

0 commit comments

Comments
 (0)