From efada76cba3cc23531be5cb10d93d0b4c41ff592 Mon Sep 17 00:00:00 2001 From: Andreas Moltumyr Date: Fri, 14 Feb 2025 13:04:29 +0100 Subject: [PATCH] lib: at_host: write AT responses to correct UART device Ensure that AT responses are written to the correct UART device when CONFIG_LOG_BACKEND_UART is enabled and ncs,at-host-uart is not uart0 (default). Co-authored-by: Fredrik Flornes Ellertsen Signed-off-by: Andreas Moltumyr --- lib/at_host/at_host.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/at_host/at_host.c b/lib/at_host/at_host.c index 767d09b5e13b..9552f89139b5 100644 --- a/lib/at_host/at_host.c +++ b/lib/at_host/at_host.c @@ -37,6 +37,12 @@ enum term_modes { DEVICE_DT_GET(COND_CODE_1(DT_HAS_CHOSEN(ncs_at_host_uart), \ (DT_CHOSEN(ncs_at_host_uart)), (DT_NODELABEL(uart0)))) +#define IS_LOG_BACKEND_UART(_uart_dev) \ + (IS_ENABLED(CONFIG_LOG_BACKEND_UART) && COND_CODE_1(DT_HAS_CHOSEN(zephyr_log_uart), \ + (_uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_log_uart))), \ + (COND_CODE_1(DT_HAS_CHOSEN(zephyr_console), \ + (_uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_console))), (false))))) + static enum term_modes term_mode; static const struct device *const uart_dev = AT_HOST_UART_DEV_GET(); static bool at_buf_busy; /* Guards at_buf while processing a command */ @@ -46,7 +52,10 @@ static struct k_work cmd_send_work; static inline void write_uart_string(const char *str) { - if (IS_ENABLED(CONFIG_LOG_BACKEND_UART)) { + if (IS_LOG_BACKEND_UART(uart_dev)) { + /* The chosen AT host UART device is also the UART log backend device. + * Therefore, log the AT response instead of writing directly to the UART device. + */ LOG_RAW("%s", str); return; }