samples: drivers: uart: Read until FIFO empty in echo_bot

The RX ready condition is unspecified with regard to being level or edge
triggered, so all available data should then be read once the RX ready
condition is detected. This change brings the sample into agreement with
the documentation and tests.

Signed-off-by: Brett Witherspoon <brett@witherspoon.engineering>
This commit is contained in:
Brett Witherspoon 2022-10-21 06:06:40 -04:00 committed by Stephanos Ioannidis
parent 6708b139ab
commit 5ec1b4d1b2

View file

@ -36,10 +36,12 @@ void serial_cb(const struct device *dev, void *user_data)
return;
}
while (uart_irq_rx_ready(uart_dev)) {
uart_fifo_read(uart_dev, &c, 1);
if (!uart_irq_rx_ready(uart_dev)) {
return;
}
/* read until FIFO empty */
while (uart_fifo_read(uart_dev, &c, 1) == 1) {
if ((c == '\n' || c == '\r') && rx_buf_pos > 0) {
/* terminate string */
rx_buf[rx_buf_pos] = '\0';