Skip to content

Commit

Permalink
lib: at_host: Write AT responses to correct UART device
Browse files Browse the repository at this point in the history
Ensure that AT responses are written to the correct UART device when
CONFIG_LOG_BACKEND_UART=y and ncs,at-host-uart is not uart0 (default).

Signed-off-by: Fredrik Flornes Ellertsen <[email protected]>
  • Loading branch information
fellerts committed Feb 7, 2025
1 parent e24e07c commit feb6253
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/at_host/at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,28 @@ static const struct device *const uart_dev = DEVICE_DT_GET(DT_CHOSEN(ncs_at_host
#else
static const struct device *const uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));
#endif

#if DT_HAS_CHOSEN(zephyr_log_uart)
static const bool host_uart_is_log_uart = \
(uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_log_uart)));
#elif DT_HAS_CHOSEN(zephyr_console)
static const bool host_uart_is_log_uart = \
(uart_dev == DEVICE_DT_GET(DT_CHOSEN(zephyr_console)));
#else
static const bool host_uart_is_log_uart = false;
#endif

static bool at_buf_busy; /* Guards at_buf while processing a command */
static char at_buf[AT_BUF_SIZE]; /* AT command and modem response buffer */
static struct k_work_q at_host_work_q;
static struct k_work cmd_send_work;

static inline void write_uart_string(const char *str)
{
if (IS_ENABLED(CONFIG_LOG_BACKEND_UART)) {
if (host_uart_is_log_uart && IS_ENABLED(CONFIG_LOG_BACKEND_UART)) {
/* The chosen UART device is also the UART log backend device, so that's
* where the AT response must go.
*/
LOG_RAW("%s", str);
return;
}
Expand Down Expand Up @@ -233,7 +247,6 @@ static int at_host_init(void)
int err;
enum term_modes mode = CONFIG_AT_HOST_TERMINATION;


/* Choosing the termination mode */
if (mode < MODE_COUNT) {
term_mode = mode;
Expand Down

0 comments on commit feb6253

Please sign in to comment.