cancel
Showing results for 
Search instead for 
Did you mean: 

RTC in STML151 always resets to default after watchdog reset

Krenek.Steve
Associate III

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

2 REPLIES 2

I'd probably add extra guarding of the RTC reset, or remove it, perhaps a GPIO or user console, perhaps !standby and !watchdog

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

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