Skip to content

Commit 3a71f31

Browse files
authored
Merge pull request #13907 from petroborys/master
Workaround to fix RTC-reset issue on the EFM32GG11_STK3701
2 parents e5e315e + e37aeb0 commit 3a71f31

File tree

1 file changed

+17
-1
lines changed
  • targets/TARGET_Silicon_Labs/TARGET_EFM32

1 file changed

+17
-1
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/rtcc.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,25 @@ void rtc_init(void)
5151
RMU_ResetControl(rmuResetPin, rmuResetModeFull);
5252

5353
/* Set up the RTCC and let it run, Forrest, run */
54+
55+
/* Save time if it has been set */
56+
time_t t = 0;
57+
if (RTCC->RET[1].REG == 0) {
58+
t = rtc_read();
59+
}
60+
5461
RTCC_Reset();
5562
RTCC_Init_TypeDef rtcc_init = RTCC_INIT_DEFAULT;
5663
rtcc_init.presc = rtccCntPresc_32768;
5764
RTCC_Init(&rtcc_init);
5865
RTCC_Enable(true);
59-
RTCC->RET[0].REG = 0;
66+
67+
/* Update time */
68+
if (RTCC->RET[1].REG == 0) {
69+
rtc_write(t);
70+
} else {
71+
RTCC->RET[0].REG = 0;
72+
}
6073
}
6174

6275
void rtc_free(void)
@@ -79,6 +92,9 @@ void rtc_write(time_t t)
7992
{
8093
core_util_critical_section_enter();
8194
RTCC->RET[0].REG = t - RTCC_CounterGet();
95+
96+
/* Record that the time has been set */
97+
RTCC->RET[1].REG = 0;
8298
core_util_critical_section_exit();
8399
}
84100

0 commit comments

Comments
 (0)