2024-06-19 10:20 AM
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
Solved! Go to Solution.
2024-06-21 08:32 AM
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:
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.
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)
2024-06-21 08:32 AM
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:
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.
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)
2024-06-24 09:21 AM
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