cancel
Showing results for 
Search instead for 
Did you mean: 

Reading RTC after wakeup from standby mode

HMull.923
Associate

Good day,

I'm using an STM32L152RE and utilize the standby mode quite often. Upon cold start, I set the RTC and I am able to enter standby mode and wakeup from standby mode based on the RTC time and alarm events.

My problem is this: I don't understand why the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions return wrong values after wakeup from standby mode. Any other time I use these functions, the values returned are as expected.

Here's what I know:

  • I know the shadow registers aren't updated during standby mode and I have to wait for the registers to sync before trusting the values returned.
  • I've therefore tried calling the HAL_RTC_WaitForSynchro() function that clears the RSF flag in the RTC ISR register and waits for it to set.
  • By stepping through the code (with HAL_DBGMCU_EnableDBGStandbyMode() compiled in) I saw that the line where the RSF flag is cleared actually has no effect on the register.
  • I then read that __HAL_RTC_WRITEPROTECTION_DISABLE() must be called before calling the syncro function, but doing this had no effect.
  • I then tried to set the BYPSHAD bit in order to read the time and date directly but again setting this bit actually had no effect - the flag stayed 0.

The only thing that seems to work is to simply call the MX_RTC_Init() function and to NOT set the time. After doing this, the values returned are normal.

Even the values in the RTC BKUP registers are incorrect after standby mode. Only after I call MX_RTC_Init() without setting time the values are correct.

0 REPLIES 0