diff options
| author | Damien George <damien@micropython.org> | 2025-11-26 13:02:16 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-29 23:57:10 +1100 |
| commit | 41acdd8083effcd513ee245075280b78af1ad938 (patch) | |
| tree | 3e6bb0f2b7bbd99b0938b635d92eb470e6e1a325 | |
| parent | 63c94fe73ed5c52d4d7ccbf4ddcc2a1e3178d21b (diff) | |
stm32/rtc: Make sure RTC is using LSE on N6 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/stm32/rtc.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c index 72abcd75f..ae33f834c 100644 --- a/ports/stm32/rtc.c +++ b/ports/stm32/rtc.c @@ -134,19 +134,27 @@ void rtc_init_start(bool force_init) { if (!force_init) { bool rtc_running = false; #if defined(STM32N6) + // Note: the low-level boot on the N6 seems to always enable the RTC and the LSI, and + // switch the RTC to LSI mode. So the logic below needs to account for that: + // - if LSE is ready then switch back to the LSE + // - even if LSI is ready, don't use it if the board is configured to use LSE + uint32_t rtc_clock_source = LL_RCC_GetRTCClockSource(); if (LL_RCC_IsEnabledRTC() - && LL_RCC_GetRTCClockSource() == LL_RCC_RTC_CLKSOURCE_LSE && LL_RCC_LSE_IsReady()) { // LSE is enabled & ready --> no need to (re-)init RTC rtc_running = true; + if (rtc_clock_source != LL_RCC_RTC_CLKSOURCE_LSE) { + LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); + } // remove Backup Domain write protection HAL_PWR_EnableBkUpAccess(); // Clear source Reset Flag __HAL_RCC_CLEAR_RESET_FLAGS(); // provide some status information rtc_info |= 0x40000; - } else if (LL_RCC_IsEnabledRTC() - && LL_RCC_GetRTCClockSource() == LL_RCC_RTC_CLKSOURCE_LSI) { + } else if (!rtc_use_lse + && LL_RCC_IsEnabledRTC() + && rtc_clock_source == LL_RCC_RTC_CLKSOURCE_LSI) { // LSI configured as the RTC clock source --> no need to (re-)init RTC rtc_running = true; // remove Backup Domain write protection |
