Unable to re-enter standby after clearing standby and wakup flags
I am having touble re-entering standby after a RTC wakup. I am using the STM32L412 (Nucleo-32)
I have written some code that enables and sets the RTC, then sets alarm A and alarm B, before going into standby. After the correct time has elapsed, alarm A wakes up mcu. I then check to see if the system was resumed by standby, and if it has clear the standby and wakup flag, before entering standby again to wait for alarm B to be triggered. The problem is that the mcu instantly wakes up and again clears the flags and goes into standby. It keeps looping round this indefinitely.
The only thing I have found to stop the mcu for instantly waking back up is to run:
HAL_PWREx_DisableInternalWakeUpLine();
This however sets it so that alarm B does not now wake up, ie I believe all wakups are disabled.
My code is:
/* Check and handle if the system was resumed from StandBy mode */
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
/* Clear wakeup flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Enter standby */
HAL_PWR_EnterSTANDBYMode();
}
else
{
MX_RTC_Init();
HAL_Delay(1000);
HAL_PWR_EnterSTANDBYMode();
}
