2019-05-02 04:20 PM
Hi there,
I want the calendar/clock to retain its value after a watchdog or other non-power-on reset.
Here is my code, near the beginning of main.c:
// and same for the real time clock, but don't intialise it unless it's a power-on reset
if (LL_RCC_IsActiveFlag_PORRST()) {
MX_RTC_Init();
}
// update the RTC shadow registers in the event it's not a power on reset and we need the existing calendar values
hrtc.Instance = RTC;
HAL_RTC_WaitForSynchro(&hrtc);
// clear the reset flags
LL_RCC_ClearResetFlags();
In my MX_RTC_Init function (as generated by Cube) I set the year to 2005 as a debugging aid.
Later in my code I set today's date and time, and can read this back OK.
After a watchdog reset, the MX_RTC_Init function does NOT get executed, but the RTC gets set to the default calendar of year 2000 etc.
Many thanks for any help on this one,
Steve
2019-05-02 04:24 PM
I'd probably add extra guarding of the RTC reset, or remove it, perhaps a GPIO or user console, perhaps !standby and !watchdog
2019-05-02 07:20 PM
Thanks Clive, those are good suggestions.
However, the real solution is a lot simpler than that :-). Without asking me, Cube had slipped the following lines into System_Clock_Config:
LL_PWR_EnableBkUpAccess();
LL_RCC_ForceBackupDomainReset();
LL_RCC_ReleaseBackupDomainReset();
I guess it reinforces the adage: never trust what Cube is going to do...
Steve