Skip to content

Commit 6348dfa

Browse files
committed
rcc: Fix I2S/SAI PLL configuration.
The PLLSRC needs to be set even if the main PLL is not enabled, because the source is also used by the other PLLs. The old code also did not correctly set M, destroying all other values in the process.
1 parent 05a70a5 commit 6348dfa

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/rcc/pll.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ impl MainPll {
1919
) -> MainPll {
2020
let sysclk = pllsysclk.unwrap_or(pllsrcclk);
2121
if pllsysclk.is_none() && !pll48clk {
22+
// Even if we do not use the main PLL, we still need to set the PLL source as that setting
23+
// applies to the I2S and SAI PLLs as well.
24+
unsafe { &*RCC::ptr() }
25+
.pllcfgr
26+
.write(|w| w.pllsrc().bit(use_hse));
27+
2228
return MainPll {
2329
use_pll: false,
2430
pllsysclk: None,
@@ -307,7 +313,8 @@ impl I2sPll {
307313
fn apply_config(config: SingleOutputPll) {
308314
let rcc = unsafe { &*RCC::ptr() };
309315
// "M" may have been written before, but the value is identical.
310-
rcc.pllcfgr.write(|w| unsafe { w.pllm().bits(config.m) });
316+
rcc.pllcfgr
317+
.modify(|_, w| unsafe { w.pllm().bits(config.m) });
311318
rcc.plli2scfgr
312319
.modify(|_, w| unsafe { w.plli2sn().bits(config.n).plli2sr().bits(config.outdiv) });
313320
}
@@ -429,16 +436,19 @@ impl SaiPll {
429436
#[cfg(not(feature = "stm32f446"))]
430437
fn apply_config(config: SingleOutputPll, saidiv: u32) {
431438
let rcc = unsafe { &*RCC::ptr() };
432-
rcc.dckcfgr.modify(|_, w| w.pllsaidivq().bits(saidiv as u8));
439+
rcc.dckcfgr
440+
.modify(|_, w| w.pllsaidivq().bits(saidiv as u8 - 1));
433441
// "M" may have been written before, but the value is identical.
434-
rcc.pllcfgr.write(|w| unsafe { w.pllm().bits(config.m) });
442+
rcc.pllcfgr
443+
.modify(|_, w| unsafe { w.pllm().bits(config.m) });
435444
rcc.pllsaicfgr
436445
.modify(|_, w| unsafe { w.pllsain().bits(config.n).pllsaiq().bits(config.outdiv) });
437446
}
438447
#[cfg(feature = "stm32f446")]
439448
fn apply_config(config: SingleOutputPll, saidiv: u32) {
440449
let rcc = unsafe { &*RCC::ptr() };
441-
rcc.dckcfgr.modify(|_, w| w.pllsaidivq().bits(saidiv as u8));
450+
rcc.dckcfgr
451+
.modify(|_, w| w.pllsaidivq().bits(saidiv as u8 - 1));
442452
rcc.pllsaicfgr.modify(|_, w| unsafe {
443453
w.pllsaim()
444454
.bits(config.m)

0 commit comments

Comments
 (0)