@@ -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
0 commit comments