From 52279dc8d53688a3a47f05b735b7a940affc7cb5 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Thu, 2 Nov 2023 21:28:33 +0000 Subject: [PATCH 1/3] Properly report break conditions A break condition is also a framing error. As it is the more specifc code, return the break error. --- rp2040-hal/src/uart/reader.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index 394deabe4..def3e5469 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -137,10 +137,6 @@ pub(crate) fn read_raw<'b, D: UartDevice>( error = Some(ReadErrorType::Overrun); } - if read.be().bit_is_set() { - error = Some(ReadErrorType::Break); - } - if read.pe().bit_is_set() { error = Some(ReadErrorType::Parity); } @@ -149,6 +145,13 @@ pub(crate) fn read_raw<'b, D: UartDevice>( error = Some(ReadErrorType::Framing); } + // A break condition is also a framing error. + // As it is the more specifc code, return + // the break error. + if read.be().bit_is_set() { + error = Some(ReadErrorType::Break); + } + if let Some(err_type) = error { return Err(Other(ReadError { err_type, From bd98b5feb0fc25f37d2be079dade786d639ef1f5 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Thu, 2 Nov 2023 21:35:23 +0000 Subject: [PATCH 2/3] Fix typo --- rp2040-hal/src/uart/reader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index def3e5469..d17ecd3cb 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -146,7 +146,7 @@ pub(crate) fn read_raw<'b, D: UartDevice>( } // A break condition is also a framing error. - // As it is the more specifc code, return + // As it is the more specific code, return // the break error. if read.be().bit_is_set() { error = Some(ReadErrorType::Break); From 6a1a0a2989d2961c8dabf3d24745c4d0b56094ac Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 5 Nov 2023 19:33:32 +0000 Subject: [PATCH 3/3] Improve handling of UART status bits If multiple status bits are set, report the most serious or most specific condition. --- rp2040-hal/src/uart/reader.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index d17ecd3cb..6e53a2fec 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -133,25 +133,20 @@ pub(crate) fn read_raw<'b, D: UartDevice>( let read = device.uartdr.read(); + // If multiple status bits are set, report + // the most serious or most specific condition, + // in the following order of precedence: + // overrun > break > parity > framing if read.oe().bit_is_set() { error = Some(ReadErrorType::Overrun); - } - - if read.pe().bit_is_set() { + } else if read.be().bit_is_set() { + error = Some(ReadErrorType::Break); + } else if read.pe().bit_is_set() { error = Some(ReadErrorType::Parity); - } - - if read.fe().bit_is_set() { + } else if read.fe().bit_is_set() { error = Some(ReadErrorType::Framing); } - // A break condition is also a framing error. - // As it is the more specific code, return - // the break error. - if read.be().bit_is_set() { - error = Some(ReadErrorType::Break); - } - if let Some(err_type) = error { return Err(Other(ReadError { err_type,