From 5158014f3f77b20db34dd398633fc26e8e7d2e60 Mon Sep 17 00:00:00 2001 From: Marco Pastrello Date: Thu, 4 May 2023 22:59:52 +0200 Subject: [PATCH] PPLXTPRE is a bool. This flag for example permits the following clock tree configuration on stm32f103r8 let mut config = Config::default(); config.rcc.hse = Some(Hertz(16_000_000)); config.rcc.sys_ck = Some(Hertz(72_000_000)); config.rcc.pclk1 = Some(Hertz(36_000_000)); config.rcc.pclk2 = Some(Hertz(72_000_000)); config.rcc.pllxtpre = true; Init fails if pllxtpre is false. --- embassy-stm32/src/rcc/f1.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/embassy-stm32/src/rcc/f1.rs b/embassy-stm32/src/rcc/f1.rs index 1c14429fc..620638abd 100644 --- a/embassy-stm32/src/rcc/f1.rs +++ b/embassy-stm32/src/rcc/f1.rs @@ -24,14 +24,11 @@ pub struct Config { pub pclk1: Option, pub pclk2: Option, pub adcclk: Option, - pub pllxtpre: Option, + pub pllxtpre: bool, } pub(crate) unsafe fn init(config: Config) { - 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 pllsrcclk = config.hse.map(|hse| hse.0 / if config.pllxtpre {2} else {1}).unwrap_or(HSI_FREQ.0 / 2); let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk); let pllmul = sysclk / pllsrcclk; @@ -148,7 +145,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))); + RCC.cfgr().modify(|w| w.set_pllxtpre(Pllxtpre(if config.pllxtpre {1u8} else {0u8}))); // enable PLL and wait for it to be ready RCC.cfgr().modify(|w| { w.set_pllmul(Pllmul(pllmul_bits));