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))]
|
#[cfg(not(usart_v1))]
|
||||||
let mut over8 = false;
|
let mut over8 = false;
|
||||||
let mut found = false;
|
let mut found = None;
|
||||||
for &(presc, _presc_val) in &DIVS {
|
for &(presc, _presc_val) in &DIVS {
|
||||||
let denom = (config.baudrate * presc as u32) as u64;
|
let denom = (config.baudrate * presc as u32) as u64;
|
||||||
let div = (pclk_freq.0 as u64 * mul + (denom / 2)) / denom;
|
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)]
|
#[cfg(usart_v4)]
|
||||||
r.presc().write(|w| w.set_prescaler(_presc_val));
|
r.presc().write(|w| w.set_prescaler(_presc_val));
|
||||||
}
|
}
|
||||||
found = true;
|
found = Some(div);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
panic!("USART: baudrate too high");
|
panic!("USART: baudrate too high");
|
||||||
}
|
}
|
||||||
|
|
||||||
if div < brr_max {
|
if div < brr_max {
|
||||||
|
let div = div as u32;
|
||||||
unsafe {
|
unsafe {
|
||||||
r.brr().write_value(regs::Brr(div as u32));
|
r.brr().write_value(regs::Brr(div));
|
||||||
#[cfg(usart_v4)]
|
#[cfg(usart_v4)]
|
||||||
r.presc().write(|w| w.set_prescaler(_presc_val));
|
r.presc().write(|w| w.set_prescaler(_presc_val));
|
||||||
}
|
}
|
||||||
found = true;
|
found = Some(div);
|
||||||
break;
|
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))]
|
#[cfg(not(usart_v1))]
|
||||||
let oversampling = if over8 { "8 bit" } else { "16 bit" };
|
let oversampling = if over8 { "8 bit" } else { "16 bit" };
|
||||||
#[cfg(usart_v1)]
|
#[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: {}",
|
"Using {} oversampling, desired baudrate: {}, actual baudrate: {}",
|
||||||
oversampling,
|
oversampling,
|
||||||
config.baudrate,
|
config.baudrate,
|
||||||
pclk_freq.0 / brr
|
pclk_freq.0 / div
|
||||||
);
|
);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
Reference in New Issue
Block a user