cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0: updating RTC calendar after wake-up from standby fails.

APann
Associate

Hi all,

I'm faced with a strange issue: updating the RTC calendar does not seem to be possible after a wake-up from standby mode.

I have a piece of code that updates the RTC calendar (date and time are uint32_t):

//  rtc disable write protection
  RTC->WPR = 0xCA;
  RTC->WPR = 0x53;
 
 
// rtc enable calendar init
   RTC->ISR |= RTC_ISR_INIT;
   while ((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) {}
 
// set the time         
  rtc_set_time(time);
  rtc_set_date(date);
 
// rtc disable calendar init
  RTC->ISR &= ~RTC_ISR_INIT;
  
// rtc enable write protection
  RTC->WPR = 0XFF;
 
    

This piece of code can be called multiple times to change the RTC calendar without any issue. It works well.

However if the MCU enters standby mode and then exists that mode, this code won't work anymore, because the following loop of code never ends:

while ((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) {}

I can still read the calendar and it works fine, but I can't update it.

My RTC initialisation code behaves slightly differently when it starts from a "cold" boot versus when it wakes up from standby:

  • When starting from "cold" boot, it does a full reset of the RTC, configures the LSE, etc.
  • When waking up from standby, the code only enables write acccess to the backup domain (with PWR->CR |= PWR_CR_DBP), all the rest is supposed to remain configured.

The only way I have found to get around this issue is to perform a full reset of the RTC domain each time the MCU boots. Since this reset also erases the date and time, I backup them up and restore them after the reset. However this feels like a terrible hack.

Any ideas what I'm doing wrong?

Best regards,

Alain

1 ACCEPTED SOLUTION

Accepted Solutions
APann
Associate

OK. It was my bad. Write access to the backup register was not correctly setup on wakeup. After correction it all works now.

Apologies for the distraction. :(

Best regards,

Alain

View solution in original post

1 REPLY 1
APann
Associate

OK. It was my bad. Write access to the backup register was not correctly setup on wakeup. After correction it all works now.

Apologies for the distraction. :(

Best regards,

Alain