Created
June 5, 2020 22:08
-
-
Save tstellanova/8ce3c317fa98ace01b0fe0c4d93c5cb7 to your computer and use it in GitHub Desktop.
stm32f3xx_hal serial reading sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In practice, at low baud rates, we get
nb::Error::WouldBlock
frequently between characters.