Skip to content

Commit 6a1a0a2

Browse files
committed
Improve handling of UART status bits
If multiple status bits are set, report the most serious or most specific condition.
1 parent bd98b5f commit 6a1a0a2

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

rp2040-hal/src/uart/reader.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,20 @@ pub(crate) fn read_raw<'b, D: UartDevice>(
133133

134134
let read = device.uartdr.read();
135135

136+
// If multiple status bits are set, report
137+
// the most serious or most specific condition,
138+
// in the following order of precedence:
139+
// overrun > break > parity > framing
136140
if read.oe().bit_is_set() {
137141
error = Some(ReadErrorType::Overrun);
138-
}
139-
140-
if read.pe().bit_is_set() {
142+
} else if read.be().bit_is_set() {
143+
error = Some(ReadErrorType::Break);
144+
} else if read.pe().bit_is_set() {
141145
error = Some(ReadErrorType::Parity);
142-
}
143-
144-
if read.fe().bit_is_set() {
146+
} else if read.fe().bit_is_set() {
145147
error = Some(ReadErrorType::Framing);
146148
}
147149

148-
// A break condition is also a framing error.
149-
// As it is the more specific code, return
150-
// the break error.
151-
if read.be().bit_is_set() {
152-
error = Some(ReadErrorType::Break);
153-
}
154-
155150
if let Some(err_type) = error {
156151
return Err(Other(ReadError {
157152
err_type,

0 commit comments

Comments
 (0)