From cb5df138d6048878a4311ecec63a632c7e20e34a Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 26 May 2023 23:48:49 +0200 Subject: [PATCH] Use found divider instead of re-reading brr --- embassy-stm32/src/usart/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 565416c7..061c859a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -836,7 +836,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: #[cfg(not(usart_v1))] let mut over8 = false; - let mut found = false; + let mut found = None; for &(presc, _presc_val) in &DIVS { let denom = (config.baudrate * presc as u32) as u64; let div = (pclk_freq.0 as u64 * mul + (denom / 2)) / denom; @@ -858,26 +858,26 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: #[cfg(usart_v4)] r.presc().write(|w| w.set_prescaler(_presc_val)); } - found = true; + found = Some(div); break; } panic!("USART: baudrate too high"); } if div < brr_max { + let div = div as u32; unsafe { - r.brr().write_value(regs::Brr(div as u32)); + r.brr().write_value(regs::Brr(div)); #[cfg(usart_v4)] r.presc().write(|w| w.set_prescaler(_presc_val)); } - found = true; + found = Some(div); break; } } - assert!(found, "USART: baudrate too low"); + let div = found.expect("USART: baudrate too low"); - let brr = unsafe { r.brr().read().brr() as u32 }; #[cfg(not(usart_v1))] let oversampling = if over8 { "8 bit" } else { "16 bit" }; #[cfg(usart_v1)] @@ -886,7 +886,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: "Using {} oversampling, desired baudrate: {}, actual baudrate: {}", oversampling, config.baudrate, - pclk_freq.0 / brr + pclk_freq.0 / div ); unsafe {