Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstellanova/8ce3c317fa98ace01b0fe0c4d93c5cb7 to your computer and use it in GitHub Desktop.
Save tstellanova/8ce3c317fa98ace01b0fe0c4d93c5cb7 to your computer and use it in GitHub Desktop.
stm32f3xx_hal serial reading sample
let ( _tx, mut rx) = serial_port.split();
rprintln!("loopstart!");
loop {
let mut err_count = 0;
let mut block_count = 0;
let mut burst_count = 0;
loop {
let rc = rx.read();
match rc {
Ok(byte) => {
rprint!("{:x},",last_char);
last_char = byte;
err_count = 0;
block_count = 0;
burst_count += 1;
}
Err(nb::Error::WouldBlock) => {
if burst_count > 10 {
rprintln!("");
}
burst_count = 0;
block_count += 1;
}
Err(nb::Error::Other(foo)) => {
err_count += 1;
if err_count > 100 {
rprintln!("err: {:?}",foo);
delay_source.delay_ms(100u8);
}
}
}
}
}
@tstellanova
Copy link
Author

In practice, at low baud rates, we get nb::Error::WouldBlock frequently between characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment