Skip to content

Commit 08678cc

Browse files
Disasmmvertescher
authored andcommitted
Switch to fail-safe clock settings first
1 parent 51f720a commit 08678cc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/rcc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ impl CFGR {
263263
let flash = unsafe { &(*FLASH::ptr()) };
264264
let rcc = unsafe { &(*RCC::ptr()) };
265265

266+
// Switch to fail-safe clock settings.
267+
// This is useful when booting from a bootloader that alters clock tree configuration.
268+
// Turn on HSI
269+
rcc.cr.modify(|_, w| w.hsion().set_bit());
270+
while rcc.cr.read().hsirdy().bit_is_clear() {}
271+
// Switch to HSI
272+
rcc.cfgr.modify(|_, w| w.sw().hsi());
273+
266274
// If HSE is provided by the user
267275
let hse_freq: u32 = self.hse.as_ref().map_or(0, |c| c.freq);
268276
// SYSCLK, must be <= 216 Mhz. By default, HSI frequency is chosen

0 commit comments

Comments
 (0)