Wake Up Timer

The wakeup timer is a programmable 16 bit auto-reload down-counter.
The wakeup timer range can be extended to 17 bits.




The wakeup timer can be used to generate a periodic interrupt through the wakeup timer flag (WUTF). Additionally the WUTF flag can be output (through signals WKUP, RTC_ALARM and on to RTC_AF1) to pin PC13.

The wakeup timer clock input can be

  • RTCCLK (usually 32.768 kHz) divided by 2, 4, 8 or 16.
    As a result this allows wakeup interrupt periods from 122 us to 32 s, with a resolution down to 61 us.
  • ck_spre (usually 1 Hz internal clock).
    As a result this allows wakeup interrupt periods from 1 s to around 36 hours.

After a reset the backup domain is write protected. The backup domain encompasses: RTC, LSE oscillator, backup SRAM, I/O pins PC13 to PC15 and PI8. The backup domain is powered through VBAT even if VDD is turned off.
Unlock access to backup domain:

  • Set the DBP bit (disable backup protection) in PWR→CR.

After a backup domain reset (not a system reset) most of the RTC registers are write protected.
Disable the write protection by writing the unlock key to RTC→WPR:

  • Write 0xCA to RTC→WPR.
  • Write 0x53 to RTC→WPR.

The RTC clock is disabled by default. Select a clock source and enable the RTC clock.
Make sure that the clock source is available while in power down mode.

  • Setup / enable an appropriate clock source, e.g. LSI.
  • Select clock source for RTCCLK in RCC→BDCR.
  • Enable RTCCLK in RCC→BDCR.

To configure the auto wakeup timer proceed as follows:

  • Disable wakeup timer in RTC→CR.
  • Wait until configuration of RTC is allowed.
    Check corresponding bit in RTC→ISR.
  • Program prescaler value in RTC→CR.
  • Program reload value in RTC→WUTR.
  • Enable wakeup interrupt in RTC→CR.

To use the wakeup interrupt, you need to configure the EXTI channel
and enable it in the NVIC:

  • Clear any pending wakeup interrupt flag in RTC→ISR.
  • Configure the dedicated EXTI interrupt channel for the RTC.
    I.e. select edge and enable.
  • Enable the RTC wakeup interrupt in the NVIC.

Start the wakeup timer:

  • Enable wakeup timer in RTC→CR.

Reenable RTC write protection:

  • Write 0xff to RTC→WPR.





WUCKSEL000fWUT ⇒ RTCCLK/16 (reset state)10xfWUT ⇒ ck_spre (1Hz)
001fWUT ⇒ RTCCLK/8
010fWUT ⇒ RTCCLK/411xfWUT ⇒ ck_spre (1Hz), 216 added to WUTR
011fWUT ⇒ RTCCLK/2
WUTE0Wake up timer disabled (reset state)
1Wake up timer enabled
WUTIE0Wake up timer interrupt disabled (reset state)
1Wake up timer interrupt enabled







WUTWF*0Wake up timer configuration not allowed
1Wake up timer configuration allowed
WUTFWake up timer flag is set by hardware when wakeup counter reaches 0 and cleared by software by writing 0.

* This bit is set, after the WUTE bit (control register) has been set to 0, and reset by hardware.




RTCEN*0RTC clock disabled
1RTC clock enabled
RTCSEL00No clock
01LSE oscillator clock used as the RTC clock
10LSI oscillator clock used as the RTC clock
11HSE oscillator clock divided by a programmable prescaler(selection Through RTCPRE[4:0] bits in the RCC clock configuration register (RCC_CFGR)) used as the RTC clock
  • stm32/peripherals/rtc_wakeup.txt
  • Last modified: 2022/12/27 18:42
  • by ruan