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 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]>
  • Loading branch information
anhmolt and fellerts committed Feb 14, 2025
1 parent a144e1e commit efada76
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/at_host/at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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.
*/

Check warning on line 58 in lib/at_host/at_host.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

lib/at_host/at_host.c:58 Block comments should align the * on each line
LOG_RAW("%s", str);
return;
}
Expand Down

0 comments on commit efada76

Please sign in to comment.