cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a RTC Wakeup event to wake up the MCU from sleep mode?

BCora.1
Associate III

I'm using a Nucleo L152RE.

I've read the 900 pages manual multiple times but I still miss a clear view of what needs to be done to create a RTC Wakeup event.

I read in the manual:

"""

To enable the RTC Wakeup interrupt, the following sequence is required:

1. Configure and enable the EXTI Line 20 in interrupt mode and select the rising edge

   sensitivity.

2. Configure and enable the RTC_WKUP IRQ channel in the NVIC.

3. Configure the RTC to generate the RTC wakeup timer event.

"""

But I don't understand what all that means.

Could you translate it for me in terms of operations that need to be done?

All of the three tasks I quoted start with "configure", this is way too vague for me. What does that mean, "configure" ? What needs to be done? I guess some registers, or bits somewhere must be modified. Which ones? How exactly do you "configure" those things?

Maybe all the 3 steps is too much, so, let's start with step 1:

"Configure and enable the EXTI Line 20 in interrupt mode"

What does that mean? What do I do?

"and select the rising edge sensitivity"

What is that? How do I select it?

Just step 1 will do for now.

Please help.

The whole manual is like that.

30 REPLIES 30
BCora.1
Associate III

I'm gonna go with 0x40010400 as the base address for the EXTI registers. I'm inferring that from the memory map on page 47.

BCora.1
Associate III

Step 2: "Configure and enable the RTC_WKUP IRQ channel in the NVIC.".

"Configure"...

BCora.1
Associate III

Do you think there's really two substeps here? Configure then enable? Or is that just enable?

BCora.1
Associate III

The only thing in the manual about RTC_WKUP is its position in the vector table. So I guess what they mean is that you should put the address of your interrupt handler code at the RTC_WKUP position (RTC_WKUP is at position 0x0000_004C , that's the 20th word in the code if you start counting words from 0).

BCora.1
Associate III

Still, they say to "configure and enable". That seems like two steps. And what I plan to do doesn't sound like "enabling". Maybe there's something else to do. I remember from the documentation of the Cortex M3 CPU, that you have to set the least significant bit of the address of your interrupt handler to 1. It's probably not what they mean by "enabling" though.

BCora.1
Associate III

I'm going to move on to step 3. Let's hope I'm not missing something in step 2.

Step 3 is: "Configure the RTC to generate the RTC wakeup timer event."

I wish they could give a slight idea about how to do that here, or maybe even, just an idea of how simple or complicated that is going to be.

BCora.1
Associate III

I think the relevant part of the manual is the following, on page 512.

https://www.st.com/resource/en/reference_manual/cd00240193-stm32l100xx-stm32l151xx-stm32l152xx-and-stm32l162xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf#page=512

So it's actually a periodic-auto wake-up?

There's no way to just say "please wake me up 8 hours from now"? It has to be "wake me up every 8 hours" ?

BCora.1
Associate III

"The wakeup function is enabled through the WUTE bit in the RTC_CR register."

I'm going to try to find out what they mean by that. "enabled through". That's vague. Do they mean you have to set the WUTE bit to 1 to enable the wakeup function?

BCora.1
Associate III

A look at the page that describes the RTC control register (RTC_CR) confirms my supposition. They just mean you have to set the WUTE bit to 1 to enable wakeup functionality. Would have been clearer to say just that rather than to say "is enabled through".

BCora.1
Associate III

I'm still on page 512.

"""

The wakeup timer clock input can be:

• RTC clock (RTCCLK) divided by 2, 4, 8, or 16. When RTCCLK is LSE(32.768kHz), this allows configuring the wakeup interrupt period from 122 µs to 32 s, with a resolution down to 61µs.

• ck_spre (usually 1 Hz internal clock)

When ck_spre frequency is 1Hz, this allows achieving a wakeup time from 1 s to around 36 hours with one-second resolution. This large programmable time range is divided in 2 parts:

– from 1s to 18 hours when WUCKSEL [2:1] = 10

– and from around 18h to 36h when WUCKSEL[2:1] = 11. In this last case 216 is added to the 16-bit counter current value.When the initialization sequence is complete (see Programming the wakeup timer on page 514), the timer starts counting down. When the wakeup function is enabled, the down-counting remains active in low-power modes. In addition, when it reaches 0, the WUTF flag is set in the RTC_ISR register, and the wakeup counter is automatically reloaded with its reload value (RTC_WUTR register value).

"""

"The wakeup timer clock input": it took me very long to parse that. What did they mean? If you analyze both possibilities for that "wakeup timer clock input", you realize both possibilities are frequencies. They are talking about the wakeup timer clock frequency.

When I had set myself to program a wakeup timer, I didn't suspect this could be important. I figured I would just enter a number of microseconds somewhere and the RTC would deal with the rest. I was naive.

So I'm going to have to use `ck_spre` since I want the RTC to wake up my program after 8 hours of sleep.

How can I make sure `ck_spre` is actually 1Hz (it "usually" is but how can I make sure it actually is?). Anybody can help me with that?

Is anybody still reading my posts at this point?