cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid reset RTC after wake up from standby mode

WPong.1
Associate II

Hello, everyone. I try to use standby mode and use RTC to wake up but I found that after wake up everything was reset. How can I avoid RTC reset after wake up? I want it to keep running.

6 REPLIES 6

Don't use Cube/HAL's RTC init function.

JW

TDK
Guru

In MX_RTC_Init, in the first user code section, detect if the RTC is already enabled and, if so, return from the function rather than initializing it.

If you feel a post has answered your question, please click "Accept as Solution".
HSagh.1
Associate II

static void MX_RTC_Init(void)

{

...

/* USER CODE BEGIN Check_RTC_BKUP */

if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) == 0x5A5AA5A5)

{

return;

}

else

{

HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x5A5AA5A5);

}

/* USER CODE END Check_RTC_BKUP */

...

}

Hi, could you please elaborate on the values 0x5A5AA5A5? 
This bit of code helped and now the rtc works and keeps time even after waking up from Standby Mode,
Im just a bit confused why. 
Thank you!

> Hi, could you please elaborate on the values 0x5A5AA5A5?

That's just some "magic number", used with a hope, that the backup register won't contain that value by "mistake".

Btw. backup registers are zeroed upon backup domain reset; but so are other registers in RTC; so there's not much reason to use the backup registers for this purpose. In fact, RTC does have a dedicated bit exactly for this purpose - RTC_ISR.INITS - although in some cases it may be better to use RTC_BDCR.RTCEN.

> I'm just a bit confused why.

Apparently, ST has reasons why the Cube-generated initialization is deliberately written to reset RTC.

I don't use Cube.

JW

Been here before, Done this already, Don't do it again, flagging value...

Can be any non-zero value, something non-trivial the better. Use your pin number twice?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..