Skip to content

Commit 033c7eb

Browse files
committed
fix: RTC Alarm with Lowpower (example STM32LowPower -> TimedWakeup)
* RTC_initClock() must be called after reset of backup domain * NVIC interrupt enable is done within RTC_StartAlarm() to avoid cases where alarm is pending but never cleared by ISR handler * STM32RTC::begin() should get format parameter instead of period * If timer is not already set, configure an arbitrary time for Lowpower usage Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
1 parent a2793ad commit 033c7eb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/STM32RTC.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ void STM32RTC::configForLowPower(Source_Clock source)
948948
end();
949949
_clockSource = source;
950950
// Enable RTC
951-
begin(period);
951+
begin(_format);
952952
// Restore config
953953
setTime(seconds, minutes, hours, subSeconds, period);
954954
setDate(weekDay, day, month, years);
@@ -958,6 +958,11 @@ void STM32RTC::configForLowPower(Source_Clock source)
958958
enableAlarm(alarmMatch);
959959
}
960960
}
961+
962+
if (!isTimeSet()) {
963+
// Set arbitrary time for Lowpower; if not already set
964+
setTime(12, 0, 0, 0, AM);
965+
}
961966
#endif
962967
}
963968

src/rtc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
355355

356356
if (reset) {
357357
resetBackupDomain();
358+
RTC_initClock(source);
358359
}
359360

360361
#if defined(STM32F1xx)
@@ -402,9 +403,6 @@ bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
402403
HAL_RTCEx_EnableBypassShadow(&RtcHandle);
403404
#endif
404405

405-
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_IRQ_PRIO, RTC_IRQ_SUBPRIO);
406-
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
407-
408406
return reinit;
409407
}
410408

@@ -654,6 +652,8 @@ void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds
654652

655653
/* Set RTC_Alarm */
656654
HAL_RTC_SetAlarm_IT(&RtcHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN);
655+
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_IRQ_PRIO, RTC_IRQ_SUBPRIO);
656+
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
657657
}
658658
}
659659

0 commit comments

Comments
 (0)