Skip to content

Commit e355e29

Browse files
anhmoltfellerts
authored 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 c2b0622 commit e355e29

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ Modem libraries
627627

628628
* Removed references to HERE location services.
629629

630+
* :ref:`lib_at_host` library:
631+
632+
* Fixed a bug where AT responses would erroneously be written to the logging UART instead of being written to the chosen ``ncs,at-host-uart`` UART device when the :kconfig:option:`CONFIG_LOG_BACKEND_UART` Kconfig option was set.
633+
630634
Multiprotocol Service Layer libraries
631635
-------------------------------------
632636

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)