From 35536233f9a15cbc47ada6b682106875c0130e62 Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Fri, 31 Jul 2020 23:15:06 +0200 Subject: [PATCH] cpu/saml1x: fix RTT issue in init process RTT module may get stuck during the init process if the RTC was running from a previous boot. Unsure we don't remove the peripheral clock during the CPU init if RTC is active from a previous boot and add a workaround to disable this module as it will be re-init at some point later by the auto_init module or by the user's application. --- cpu/saml1x/cpu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpu/saml1x/cpu.c b/cpu/saml1x/cpu.c index c5c5693484..24c246bf6e 100644 --- a/cpu/saml1x/cpu.c +++ b/cpu/saml1x/cpu.c @@ -135,9 +135,21 @@ void cpu_init(void) #endif #ifdef MODULE_PERIPH_GPIO | MCLK_APBAMASK_PORT +#endif +#ifdef MODULE_PERIPH_RTC_RTT + | MCLK_APBAMASK_RTC #endif ; + + /* Disable the RTC module to prevent synchronization issues during CPU init + if the RTC was running from a previous boot (e.g wakeup from backup) + as the module will be re-init during the boot process */ + if (RTC->MODE2.CTRLA.bit.ENABLE && IS_ACTIVE(MODULE_PERIPH_RTC_RTT)) { + while (RTC->MODE2.SYNCBUSY.reg) {} + RTC->MODE2.CTRLA.bit.ENABLE = 0; + while (RTC->MODE2.SYNCBUSY.reg) {} + } /* Software reset the GCLK module to ensure it is re-initialized correctly */ GCLK->CTRLA.reg = GCLK_CTRLA_SWRST; while (GCLK->CTRLA.reg & GCLK_CTRLA_SWRST) {}