I have imxrt1166 eval board and trying to understand RTC. Although SNVS portion is powered by a seperate LDO regulator, It resets its counter whenever I press reset button. During reset, VDD_SNVS_IN input stays at 3.3V. It works as expected. I observed with oscilloscope.
The counter starts running from the date 2023.12.31 and time 23.58.00 after every reset/power cycle. These values are my initial config values.
I am studying "evkmimxrt1160_snvs_hp_rtc_cm7" example in SDK. How can I fix it and keeps retaining its date/time values in case unexpected crash happens?
P.S : I searched if anyone has encountered similar problem. I saw that one must say to save LPGPR register while GPR_Z_DIS bit enabled. I did it as the following;
status_t SNVS_HP_RTC_SetDatetime(SNVS_Type *base, const snvs_hp_rtc_datetime_t *datetime)
{
......
.......
base->LPCR |= SNVS_LPCR_GPR_Z_DIS_MASK;
base->LPGPR[0] = (uint32_t)(1U);
.......
}
Before the entry into the main loop, I added below lines;
rtcDate.year = 2023;
rtcDate.month = 12;
rtcDate.day = 31;
rtcDate.hour = 23;
rtcDate.minute = 58;
rtcDate.second = 0;
if ( SNVS->LPGPR[0] != 1U)
{
SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate);
}
SNVS_HP_RTC_StartTimer(SNVS);
while (true)
{
......
}
I can now set the LPGPR register value. But this time when I reset the board, it counts starting from 1970-01-01 00:00:00
Do I have to save current date and time infos to LPGPR registers every time? If yes, when an unpected crash occurs, it will not show the exact time after reset. I need the RTC working similar to in STM32 series.