Skip to main content
APann
Associate
April 19, 2019
Solved

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

  • April 19, 2019
  • 1 reply
  • 1097 views

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

This topic has been closed for replies.
Best answer by APann

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

1 reply

APann
APannAuthorBest answer
Associate
April 19, 2019

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