Skip to content

Commit 215f395

Browse files
authored
Merge pull request #118 from davidlattimore/reconfigure-pll
Make sure system isn't clocked from PLL before disabling it
2 parents 2cf638d + 864a323 commit 215f395

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/rcc/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ impl Rcc {
207207
assert!(pll_cfg.m > 0 && pll_cfg.m <= 8);
208208
assert!(pll_cfg.r > 1 && pll_cfg.r <= 8);
209209

210+
// If the system is currently clocked from the PLL, then switch back to
211+
// the HSI before we disable the PLL, otherwise the PLL will refuse to
212+
// switch off.
213+
self.cfgr.modify(|r, w| {
214+
if r.sw().bits() == 0b010 {
215+
unsafe { w.sw().bits(0b000) };
216+
}
217+
w
218+
});
219+
210220
// Disable PLL
211221
self.cr.modify(|_, w| w.pllon().clear_bit());
212222
while self.cr.read().pllrdy().bit_is_set() {}

0 commit comments

Comments
 (0)