Skip to content

Commit 80d6e2f

Browse files
Throw away UART bytes with errors in reception (#1036)
Fixes #1021 The UART hardware will push characters into the receive FIFO even if there are parity, framing, or other errors. These are invalid and shouldn't be returned to the application, so drop them if errors detected. This will also avoid the glitch-induced initial garbage character.
1 parent d35e938 commit 80d6e2f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cores/rp2040/SerialUART.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,12 @@ void __not_in_flash_func(SerialUART::_handleIRQ)(bool inIRQ) {
390390
// ICR is write-to-clear
391391
uart_get_hw(_uart)->icr = UART_UARTICR_RTIC_BITS | UART_UARTICR_RXIC_BITS;
392392
while (uart_is_readable(_uart)) {
393-
auto val = uart_getc(_uart);
393+
uint32_t raw = uart_get_hw(_uart)->dr;
394+
if (raw & 0x700) {
395+
// Framing, Parity, or Break. Ignore this bad char
396+
continue;
397+
}
398+
uint8_t val = raw & 0xff;
394399
auto next_writer = _writer + 1;
395400
if (next_writer == _fifoSize) {
396401
next_writer = 0;

0 commit comments

Comments
 (0)