cancel
Showing results for 
Search instead for 
Did you mean: 

Where to read length of sleep time on RTC WUT

LWill.4
Associate

We are using the STM32L071RB, currently have the firmware set to go to sleep (stop mode) and wake up after ~5 minutes with the RTC WUT (see section 22.4.6 and A13.3 in RM0377). This works great, however this timer isn't the only wakeup source. If the device wakes up due to a external interrupt, the timer restarts back to another 5 minutes. So, for these external interrupt events we need to know how long it's already been asleep to compensate and have the periodic wakeup keep the same interval. My first thought was that we could just read the "wakeup timer" register to see how long it's been asleep, but can't find any information on where that is located... (RTC_WUTR is simply the reload register, so it doesn't change)

Does anyone know where the mcu is storing that counter/timer?

 

Alternatively we could set up with an alarm or store the RTC value before going to sleep and compare, but we are low on space and don't want to rewrite deployed code unless necessary

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @LWill.4 

There is no direct access to the wake-up timer to read its content.

As a workaround, if the wake-up timer is clocked via the synchronous prescaler (WUCKSEL [2:1] = 10 or 11 in the RTC_CR), you can read the RTC_TIME register:

  • first, when the wake-up timer is reloaded,
  • second, when the CPU wakes up from the low power mode,
  • then, calculate the difference. 

This is to answer the question.

However, it sounds unusual that the wake-up timer is reinitialized for 5 more minutes after each wake-up from low power mode, unless the application is explicitly doing it.

Indeed, as show in the table below (extract from RM0367), low power modes have no impact on RTC features and its registers that keep their values.

Saket_Om_1-1718983579912.jpeg

If it is the application that is reinitializing the wake-up timer after the wake-up from a low power mode, it should no longer do it.

Instead, after wake-up from low power modes, the application shall check the PWR flags (i.e., SBF and WUF in PWR_CSR)

  • If either or both are set, then the application shall not reinitialize the wake-up timer.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

View solution in original post

2 REPLIES 2
Saket_Om
ST Employee

Hello @LWill.4 

There is no direct access to the wake-up timer to read its content.

As a workaround, if the wake-up timer is clocked via the synchronous prescaler (WUCKSEL [2:1] = 10 or 11 in the RTC_CR), you can read the RTC_TIME register:

  • first, when the wake-up timer is reloaded,
  • second, when the CPU wakes up from the low power mode,
  • then, calculate the difference. 

This is to answer the question.

However, it sounds unusual that the wake-up timer is reinitialized for 5 more minutes after each wake-up from low power mode, unless the application is explicitly doing it.

Indeed, as show in the table below (extract from RM0367), low power modes have no impact on RTC features and its registers that keep their values.

Saket_Om_1-1718983579912.jpeg

If it is the application that is reinitializing the wake-up timer after the wake-up from a low power mode, it should no longer do it.

Instead, after wake-up from low power modes, the application shall check the PWR flags (i.e., SBF and WUF in PWR_CSR)

  • If either or both are set, then the application shall not reinitialize the wake-up timer.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Yeah, the application is resetting the timer, will have to correct that. I just love inheriting code...

And thanks for the info! Will update for posterity if anything interesting comes up