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) {}