Merge pull request #13907 from petroborys/master

Workaround to fix RTC-reset issue on the EFM32GG11_STK3701
pull/13959/head
Martin Kojtal 2020-12-09 08:57:08 +00:00 committed by GitHub
commit 3a71f314d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -51,12 +51,25 @@ void rtc_init(void)
RMU_ResetControl(rmuResetPin, rmuResetModeFull);
/* Set up the RTCC and let it run, Forrest, run */
/* Save time if it has been set */
time_t t = 0;
if (RTCC->RET[1].REG == 0) {
t = rtc_read();
}
RTCC_Reset();
RTCC_Init_TypeDef rtcc_init = RTCC_INIT_DEFAULT;
rtcc_init.presc = rtccCntPresc_32768;
RTCC_Init(&rtcc_init);
RTCC_Enable(true);
RTCC->RET[0].REG = 0;
/* Update time */
if (RTCC->RET[1].REG == 0) {
rtc_write(t);
} else {
RTCC->RET[0].REG = 0;
}
}
void rtc_free(void)
@ -79,6 +92,9 @@ void rtc_write(time_t t)
{
core_util_critical_section_enter();
RTCC->RET[0].REG = t - RTCC_CounterGet();
/* Record that the time has been set */
RTCC->RET[1].REG = 0;
core_util_critical_section_exit();
}