Skip to content

Commit efada76

Browse files
anhmoltfellerts
andcommitted
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 <[email protected]> Signed-off-by: Andreas Moltumyr <[email protected]>
1 parent a144e1e commit efada76

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/at_host/at_host.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ enum term_modes {
3737
DEVICE_DT_GET(COND_CODE_1(DT_HAS_CHOSEN(ncs_at_host_uart), \
3838
(DT_CHOSEN(ncs_at_host_uart)), (DT_NODELABEL(uart0))))
3939

40+
#define IS_LOG_BACKEND_UART(_uart_dev) \
41+
(IS_ENABLED(CONFIG_LOG_BACKEND_UART) && COND_CODE_1(DT_HAS_CHOSEN(zephyr_log_uart), \
42+
(_uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_log_uart))), \
43+
(COND_CODE_1(DT_HAS_CHOSEN(zephyr_console), \
44+
(_uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_console))), (false)))))
45+
4046
static enum term_modes term_mode;
4147
static const struct device *const uart_dev = AT_HOST_UART_DEV_GET();
4248
static bool at_buf_busy; /* Guards at_buf while processing a command */
@@ -46,7 +52,10 @@ static struct k_work cmd_send_work;
4652

4753
static inline void write_uart_string(const char *str)
4854
{
49-
if (IS_ENABLED(CONFIG_LOG_BACKEND_UART)) {
55+
if (IS_LOG_BACKEND_UART(uart_dev)) {
56+
/* The chosen AT host UART device is also the UART log backend device.
57+
* Therefore, log the AT response instead of writing directly to the UART device.
58+
*/
5059
LOG_RAW("%s", str);
5160
return;
5261
}

0 commit comments

Comments
 (0)