Skip to content

Commit 1a5705e

Browse files
Fix configuration of PLLQ and PLLP (#114)
* Relayout PLL configuration code * Fix configuration of PLLQ and PLLP The pllqend and pllpen bits weren't being set. Also, the value written to pllsyscfgr was being overwritten by the subsequent write call.
1 parent 050ac85 commit 1a5705e

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/rcc/mod.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,37 +228,30 @@ impl Rcc {
228228

229229
let pll_freq = freq / (pll_cfg.m as u32) * (pll_cfg.n as u32);
230230
let r = (pll_freq / (pll_cfg.r as u32)).Hz();
231-
let q = match pll_cfg.q {
232-
Some(div) if div > 1 && div <= 8 => {
233-
self.pllsyscfgr
234-
.write(move |w| unsafe { w.pllq().bits(div - 1) });
231+
let mut q = None;
232+
let mut p = None;
233+
234+
self.pllsyscfgr.write(|w| unsafe {
235+
w.pllsrc().bits(pll_sw_bits);
236+
w.pllm().bits(pll_cfg.m - 1);
237+
w.plln().bits(pll_cfg.n);
238+
w.pllr().bits(pll_cfg.r - 1);
239+
w.pllren().set_bit();
240+
if let Some(div) = pll_cfg.q {
241+
assert!(div > 1 && div <= 8);
242+
w.pllq().bits(div - 1);
243+
w.pllqen().set_bit();
235244
let req = pll_freq / div as u32;
236-
Some(req.Hz())
245+
q = Some(req.Hz());
237246
}
238-
_ => None,
239-
};
240-
241-
let p = match pll_cfg.p {
242-
Some(div) if div > 1 && div <= 8 => {
243-
self.pllsyscfgr
244-
.write(move |w| unsafe { w.pllp().bits(div - 1) });
247+
if let Some(div) = pll_cfg.p {
248+
assert!(div > 1 && div <= 8);
249+
w.pllp().bits(div - 1);
250+
w.pllpen().set_bit();
245251
let req = pll_freq / div as u32;
246-
Some(req.Hz())
252+
p = Some(req.Hz());
247253
}
248-
_ => None,
249-
};
250-
251-
self.pllsyscfgr.write(move |w| unsafe {
252-
w.pllsrc()
253-
.bits(pll_sw_bits)
254-
.pllm()
255-
.bits(pll_cfg.m - 1)
256-
.plln()
257-
.bits(pll_cfg.n)
258-
.pllr()
259-
.bits(pll_cfg.r - 1)
260-
.pllren()
261-
.set_bit()
254+
w
262255
});
263256

264257
// Enable PLL

0 commit comments

Comments
 (0)