From 8c8d41c32fb5d7a6a965c4cbdfa955d95905cf4a Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Dec 2022 10:47:13 -0800 Subject: [PATCH] samples: drivers: uart: Detect missing FIFO mode in echo_bot Print an error message if the UART doesn't support FIFO mode or FIFO mode is not enabled. Previously the sample would run with no errors, but wouldn't receive or echo any data. Signed-off-by: Trent Piepho --- samples/drivers/uart/echo_bot/src/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/samples/drivers/uart/echo_bot/src/main.c b/samples/drivers/uart/echo_bot/src/main.c index 55623a32487..4d66abaa6f2 100644 --- a/samples/drivers/uart/echo_bot/src/main.c +++ b/samples/drivers/uart/echo_bot/src/main.c @@ -78,7 +78,18 @@ void main(void) } /* configure interrupt and callback to receive data */ - uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL); + int ret = uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL); + + if (ret < 0) { + if (ret == -ENOTSUP) { + printk("Interrupt-driven UART API support not enabled\n"); + } else if (ret == -ENOSYS) { + printk("UART device does not support interrupt-driven API\n"); + } else { + printk("Error setting UART callback: %d\n", ret); + } + return; + } uart_irq_rx_enable(uart_dev); print_uart("Hello! I'm your echo bot.\r\n");