STM32 wake up from standby by RTC
Asked Answered
D

1

9

I am programming STM32L051R8 and have next problem. I'm trying use standby mode in most part of time, and sometimes wake up by RTC, it is an auto wake-up. If I work without sleep - all works perfectly, I got an RTC interrupt every time, but when I use standby - don't.

If I use standby, I have a good first cycle:

  1. reset
  2. set RTC
  3. enter standby
  4. waiting for interrupt
  5. wake-up

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

Dropper answered 13/2, 2017 at 14:5 Comment(3)
Hard to tell, so it would be good if you could show your code, but it seems that you forgot to clear the WakeUp flag.Constriction
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); something like this is missing on start up.Constriction
Oh, thanks so much, I tryed clear flags in rtc. I can't check comment like resolving. If you right it like answer, I'll check it.Dropper
C
17

When the microcontroller is in Standby mode and an RTC interrupt occurs the WUF: Wakeup flag will be set by the hardware in the PWR control/status register (Page 162).

Bit 0 WUF: Wakeup flag

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

0: No wakeup event occurred

1: A wakeup event was received from the WKUP pin or from the RTC alarm (Alarm A or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup).

Initially this is cleared by a system reset so that is why your first cycle is OK. But after a wake-up from standby you have to clear it manually using the CWUF bit in the PWR control register. If you do not do this then the controller will wake up at once as the this bit signals an occurred wake-up event.

You can access the register directly to set this bit or with HAL library the following macro can be used:

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
Constriction answered 14/2, 2017 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.