I am running a STM32F072ZB into standbye mode. The MCU sleeps most of the time (waking up every 1hr to read sensors). As I have the watchdog running, I am using RTC to generate an alarm every 25s (watchdog period is ~28s). So when I am sleeping for 1hr, I am setting the alarm in time now + 25s, then go to standby, woken up by the alarm kick the watchdog and set the alarm to the next 25s etc...
It is working almost fine but for some reason, sometimes the MCU resets because of the watchdog not kicked. That means I have missed the alarm for some reason. I have been doing some tests and over 24 hours it happened 6 times.
As anyone ever experienced this kind of issue?
The code goes here:
// Set RTC_Alarm
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
util_msDelay(10);
/*To configure the wake up timer to 25s the WakeUpCounter is set to 0xC738:
Wakeup Time Base = 16 /(32.768 kHz RC) = ~0.49 ms
Wakeup Time = ~0.49 ms * WakeUpCounter
Therefore, with wake-up counter = 0xC738 = 51.000
Wakeup Time = 0.49 ms * 51,000 = ~ 25 sec. */
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0xC738, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
util_msDelay(10);
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
}
/* Clear Wake-up timer flag if it is set */
/* Flag will set after exiting from Standby */
if (LL_RTC_IsActiveFlag_WUT(RTC) == 1) {
LL_RTC_ClearFlag_WUT(RTC);
}
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
util_msDelay(10);