@@ -134,19 +134,27 @@ void rtc_init_start(bool force_init) {
134134 if (!force_init ) {
135135 bool rtc_running = false;
136136 #if defined(STM32N6 )
137+ // Note: the low-level boot on the N6 seems to always enable the RTC and the LSI, and
138+ // switch the RTC to LSI mode. So the logic below needs to account for that:
139+ // - if LSE is ready then switch back to the LSE
140+ // - even if LSI is ready, don't use it if the board is configured to use LSE
141+ uint32_t rtc_clock_source = LL_RCC_GetRTCClockSource ();
137142 if (LL_RCC_IsEnabledRTC ()
138- && LL_RCC_GetRTCClockSource () == LL_RCC_RTC_CLKSOURCE_LSE
139143 && LL_RCC_LSE_IsReady ()) {
140144 // LSE is enabled & ready --> no need to (re-)init RTC
141145 rtc_running = true;
146+ if (rtc_clock_source != LL_RCC_RTC_CLKSOURCE_LSE ) {
147+ LL_RCC_SetRTCClockSource (LL_RCC_RTC_CLKSOURCE_LSE );
148+ }
142149 // remove Backup Domain write protection
143150 HAL_PWR_EnableBkUpAccess ();
144151 // Clear source Reset Flag
145152 __HAL_RCC_CLEAR_RESET_FLAGS ();
146153 // provide some status information
147154 rtc_info |= 0x40000 ;
148- } else if (LL_RCC_IsEnabledRTC ()
149- && LL_RCC_GetRTCClockSource () == LL_RCC_RTC_CLKSOURCE_LSI ) {
155+ } else if (!rtc_use_lse
156+ && LL_RCC_IsEnabledRTC ()
157+ && rtc_clock_source == LL_RCC_RTC_CLKSOURCE_LSI ) {
150158 // LSI configured as the RTC clock source --> no need to (re-)init RTC
151159 rtc_running = true;
152160 // remove Backup Domain write protection
0 commit comments