This is an old revision of the document!
Wake Up Timer
The wakeup timer is a programmable 16 bit down-counter.
The wakeup timer range can be extended to 17 bits.
Programming Instructions
RTC register write protection
After a reset the backup domain is write protected.
Unlock access to backup domain:
- Set the
DBP
bit (disable backup protection) inPWR→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
toRTC→WPR
. - Write
0x53
toRTC→WPR
.
Enable RTC clock
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
.
Setup wakeup timer
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 inRTC→ISR
. - Program reload value in
RTC→WUTR
. - Program prescaler value in
RTC→CR
. - 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
toRTC→WPR
.
Configuration Registers
CR
Configuration register
WUCKSEL | 000 | fWUT ⇒ RTCCLK/16 (reset state) | 10x | fWUT ⇒ ck_spre (1Hz) |
001 | fWUT ⇒ RTCCLK/8 | |||
010 | fWUT ⇒ RTCCLK/4 | 11x | fWUT ⇒ ck_spre (1Hz), 216 added to WUTR | |
011 | fWUT ⇒ RTCCLK/2 | |||
WUTE | 0 | Wake up timer disabled (reset state) | ||
1 | Wake up timer enabled | |||
WUTIE | 0 | Wake up timer interrupt disabled (reset state) | ||
1 | Wake up timer interrupt enabled |