Skip to content

Commit

Permalink
Increased max computable lpuart baud. Added associated test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tprice02 authored and mciantyre committed Nov 1, 2024
1 parent 33612dc commit 41ab636
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/common/lpuart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ impl Baud {
let mut best_osr = 0;
let mut best_sbr = 0;

let mut osr = 8;
let mut osr = if baud > 3_000_000 { 4 } else { 8 };
while osr <= 32 {
let mut sbr = 1;
while sbr < 8192 {
Expand Down Expand Up @@ -1086,6 +1086,24 @@ mod tests {
assert!(!BAUD.bothedge);
}

#[test]
fn max_baud() {
// Assume the 24MHz XTAL clock.
const UART_CLOCK_HZ: u32 = 24_000_000;
// The best baud rate we can get is
const EXPECTED_BAUD: u32 = 6_000_000;
// for a target baud of
const TARGET_BAUD: u32 = 6_000_000;

const BAUD: Baud = Baud::compute(UART_CLOCK_HZ, TARGET_BAUD);

assert_eq!(BAUD.value(UART_CLOCK_HZ), EXPECTED_BAUD);

assert_eq!(BAUD.osr, 4, "OSR: {}", BAUD.osr);
assert_eq!(BAUD.sbr, 1, "SBR: {}", BAUD.sbr);
assert!(BAUD.bothedge);
}

#[test]
fn read_data_flags() {
let read_data = ReadData(1 << 15 | 1 << 13);
Expand Down

0 comments on commit 41ab636

Please sign in to comment.