2021-08-03 01:37 AM
2021-08-03 02:02 AM
Don't use Cube/HAL's RTC init function.
JW
2021-08-03 06:36 AM
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.
2023-12-04 04:39 AM
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 */
...
}
2024-01-25 09:35 AM
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!
2024-01-25 10:37 AM
> 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
2024-01-25 10:45 AM
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?