Use found divider instead of re-reading brr
This commit is contained in:
parent
f616b22159
commit
cb5df138d6
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user