Skip to content

Commit

Permalink
Switch to MSI to prevent problems with PLL configuration (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Disasm authored Jan 16, 2022
1 parent a7ec26d commit e483546
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ impl CFGR {
pub fn freeze(&self, acr: &mut ACR, pwr: &mut Pwr) -> Clocks {
let rcc = unsafe { &*RCC::ptr() };

// Switch to MSI to prevent problems with PLL configuration.
if rcc.cr.read().msion().bit_is_clear() {
// Turn on MSI and configure it to 4MHz.
rcc.cr.modify(|_, w| {
w.msirgsel().set_bit(); // MSI Range is provided by MSIRANGE[3:0].
w.msirange().range4m();
w.msipllen().clear_bit();
w.msion().set_bit()
});

// Wait until MSI is running
while rcc.cr.read().msirdy().bit_is_clear() {}
}
if rcc.cfgr.read().sws().bits() != 0 {
// Set MSI as a clock source, reset prescalers.
rcc.cfgr.reset();
// Wait for clock switch status bits to change.
while rcc.cfgr.read().sws().bits() != 0 {}
}

//
// 1. Setup clocks
//
Expand Down

0 comments on commit e483546

Please sign in to comment.