STM32 wakes up from RTC standby

I am programming STM32L051R8 and have the following problem. I try to use standby mode most of the time, and sometimes I wake up RTC, it is an automatic wakeup. If I work without sleep, everything works fine, I get an RTC interrupt every time, but when I use standby mode, do not do this.

If I use standby, I have a nice first loop:

  • reset
  • install RTC
  • enter standby
  • Waiting for interruption
  • wake-up

But the second and next cycles wake up immediately after entering standby mode (3).

+7
timer microcontroller wakeup stm32 real-time-clock
source share
1 answer

When the microcontroller is in standby mode and an RTC interrupt occurs, the WUF: Wakeup flag will be set by the hardware to the PWR / Status Register (Page 162).

Bit 0 WUF: Alarm Flag

This bit is set by hardware and cleared by the system reset, or by setting the CWUF bit in the power control PWR register (PWR_CR)

0: Awakening event did not occur.

1: Awakening event was received from a WKUP pin or from an RTC signal (Alarm A or Alarm B), RTC Tamper event, RTC TimeStamp event, or RTC awakening).

This is initially cleared by the reset system, so your first loop is fine. But after waking from standby, you must clear it manually using the CWUF bit in the PWR control register. If you do not, the controller will wake up immediately when this bit signals a wake-up event.

You can access the register directly to set this bit or to the HAL library, you can use the following macro:

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 
+10
source share

All Articles