Skip to content

Commit e483546

Browse files
authored
Switch to MSI to prevent problems with PLL configuration (#286)
1 parent a7ec26d commit e483546

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/rcc.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@ impl CFGR {
451451
pub fn freeze(&self, acr: &mut ACR, pwr: &mut Pwr) -> Clocks {
452452
let rcc = unsafe { &*RCC::ptr() };
453453

454+
// Switch to MSI to prevent problems with PLL configuration.
455+
if rcc.cr.read().msion().bit_is_clear() {
456+
// Turn on MSI and configure it to 4MHz.
457+
rcc.cr.modify(|_, w| {
458+
w.msirgsel().set_bit(); // MSI Range is provided by MSIRANGE[3:0].
459+
w.msirange().range4m();
460+
w.msipllen().clear_bit();
461+
w.msion().set_bit()
462+
});
463+
464+
// Wait until MSI is running
465+
while rcc.cr.read().msirdy().bit_is_clear() {}
466+
}
467+
if rcc.cfgr.read().sws().bits() != 0 {
468+
// Set MSI as a clock source, reset prescalers.
469+
rcc.cfgr.reset();
470+
// Wait for clock switch status bits to change.
471+
while rcc.cfgr.read().sws().bits() != 0 {}
472+
}
473+
454474
//
455475
// 1. Setup clocks
456476
//

0 commit comments

Comments
 (0)