diff --git a/embassy-stm32/src/rcc/f1.rs b/embassy-stm32/src/rcc/f1.rs index e667dbf90..1c14429fc 100644 --- a/embassy-stm32/src/rcc/f1.rs +++ b/embassy-stm32/src/rcc/f1.rs @@ -24,10 +24,15 @@ pub struct Config { pub pclk1: Option, pub pclk2: Option, pub adcclk: Option, + pub pllxtpre: Option, } pub(crate) unsafe fn init(config: Config) { - let pllsrcclk = config.hse.map(|hse| hse.0).unwrap_or(HSI_FREQ.0 / 2); + let pllsrcclk = config.hse.map(|hse| hse.0 / match config.pllxtpre { + Some(b) => if b {2} else {1}, + None => {1}, + }).unwrap_or(HSI_FREQ.0 / 2); + let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk); let pllmul = sysclk / pllsrcclk; @@ -143,6 +148,7 @@ pub(crate) unsafe fn init(config: Config) { } if let Some(pllmul_bits) = pllmul_bits { + RCC.cfgr().modify(|w| w.set_pllxtpre(Pllxtpre(config.pllxtpre.is_some() as u8))); // enable PLL and wait for it to be ready RCC.cfgr().modify(|w| { w.set_pllmul(Pllmul(pllmul_bits));