Skip to content

Commit b209fed

Browse files
app: Enable boot logging
B0, MCUboot and application log from the boot. The logging is disabled after the application is initialized, so that the application can enter low-power states. Logging can be re-enabled with AT#XLOG=1, which also enables the logging UART. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no> Co-authored-by: Divya S Pillai <91891495+divipillai@users.noreply.github.com>
1 parent 2cbb3ad commit b209fed

9 files changed

Lines changed: 67 additions & 46 deletions

File tree

app/prj.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ CONFIG_EVENTFD=y
1717
# Enable UART logging by default.
1818
CONFIG_UART_CONSOLE=y
1919
CONFIG_LOG_BACKEND_UART=y
20-
# Logging does not start until activated via AT#XLOG=1 and is deactivated with AT#XLOG=0.
21-
CONFIG_LOG_BACKEND_UART_AUTOSTART=n
20+
# Logging starts automatically, but it is disabled after bootup.
21+
CONFIG_LOG_BACKEND_UART_AUTOSTART=y
2222

2323
# Disable Segger RTT logging by default.
2424
CONFIG_USE_SEGGER_RTT=n

app/src/sm_log.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,37 @@ STATIC int handle_at_log(enum at_parser_cmd_type cmd_type, struct at_parser *par
133133
return -EINVAL;
134134
}
135135

136+
/* Whether bootloader mode is enabled. */
137+
extern bool sm_bootloader_mode_enabled;
138+
136139
static int sm_log_init(void)
137140
{
138-
if (!IS_ENABLED(CONFIG_LOG_BACKEND_UART) ||
139-
!IS_ENABLED(CONFIG_LOG_BACKEND_UART_AUTOSTART)) {
140-
/* Start with UART log backend disabled. */
141-
if (uart_suspend()) {
142-
LOG_ERR("Failed to suspend UART log backend");
143-
sm_init_failed = true;
144-
return -EFAULT;
145-
}
146-
} else {
141+
if (sm_bootloader_mode_enabled) {
142+
/* Keep the logging (and logging UART) enabled in bootloader mode */
147143
log_active = true;
144+
return 0;
145+
}
146+
147+
const struct log_backend *log_be = log_backend_get_by_name("log_backend_uart");
148+
149+
if (log_be) {
150+
LOG_DBG("Use AT#XLOG=1 to enable UART logging");
151+
sm_log_flush();
152+
log_backend_disable(log_be);
153+
}
154+
155+
/* Suspend the UART device that is shared by application log and modem trace */
156+
int ret = uart_suspend();
157+
158+
if (ret) {
159+
urc_send(SM_SYNC_ERR_STR);
160+
return ret;
148161
}
149162

150163
return 0;
151164
}
152165

153-
SYS_INIT(sm_log_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
166+
/* Runs after application initialization */
167+
SYS_INIT(sm_log_init, APPLICATION, 101);
154168

155169
#endif /* DT_HAS_CHOSEN(zephyr_console) */

app/src/sm_trace_backend_uart.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,3 @@ STATIC int handle_at_trace(enum at_parser_cmd_type cmd_type, struct at_parser *p
271271

272272
return -EINVAL;
273273
}
274-
275-
static int sm_trace_backend_uart_init(void)
276-
{
277-
/* Allow UART to be active if CONFIG_LOG_BACKEND_UART_AUTOSTART=y */
278-
if (!IS_ENABLED(CONFIG_LOG_BACKEND_UART_AUTOSTART)) {
279-
/* Start the trace backend disabled. */
280-
if (uart_suspend()) {
281-
LOG_ERR("Failed to suspend UART trace backend");
282-
sm_init_failed = true;
283-
return -EFAULT;
284-
}
285-
}
286-
287-
return 0;
288-
}
289-
290-
SYS_INIT(sm_trace_backend_uart_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,console = &uart1;
10+
};
11+
};
12+
13+
&uart1 {
14+
current-speed = <1000000>;
15+
status = "okay";
16+
};

app/sysbuild/b0/prj.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ CONFIG_ASSERT=n
2929

3030
# Avoid triggering IRQs from the RTC
3131
CONFIG_NRF_RTC_TIMER=n
32-
33-
# Serial Modem specific changes:
34-
# Disable logging so that Ready-message is the first one in startup.
35-
CONFIG_LOG=n
36-
CONFIG_CONSOLE=n
37-
CONFIG_UART_CONSOLE=n
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,console = &uart1;
10+
};
11+
};
12+
13+
&uart1 {
14+
current-speed = <1000000>;
15+
status = "okay";
16+
};

app/sysbuild/mcuboot/prj.conf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,17 @@ CONFIG_FPROTECT=y
2626

2727
CONFIG_LOG=y
2828
CONFIG_LOG_MODE_MINIMAL=y
29-
### Ensure Zephyr logging changes don't use more resources
30-
CONFIG_LOG_DEFAULT_LEVEL=0
31-
### Use info log level by default
3229
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
3330
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
3431
CONFIG_CBPRINTF_NANO=y
3532
CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0
3633

3734
### Serial Modem
38-
# Do not use UART, for power saving
35+
# Enable mcuboot traces
3936
CONFIG_CONSOLE=y
4037
CONFIG_MCUBOOT_SERIAL=n
4138
CONFIG_BOOT_SERIAL_UART=n
42-
CONFIG_UART_CONSOLE=n
43-
CONFIG_LOG_BACKEND_UART=n
39+
CONFIG_UART_CONSOLE=y
4440
CONFIG_CONSOLE_HANDLER=n
4541

4642
# Enable software downgrade prevention for the application.

doc/app/at_trace.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ See :ref:`sm_logging_uart_backend` for a full description of the feature.
1919

2020
The Zephyr application log backend (``AT#XLOG``) and the modem trace backend (``AT#XTRACE``) share a single UART.
2121
They are mutually exclusive: enabling one while the other is active returns an error.
22-
The trace UART is suspended when neither backend is active and resumed automatically when either backend is enabled.
22+
During boot, the UART outputs logs from B0, MCUboot, and the application.
23+
After initialization, the UART is suspended when no backend is active and resumed when at least one backend is enabled.
2324

2425
The trace UART is configured at 1000000 baud rate to support the high data rate required for the modem traces.
2526
Trace data is available through the UART1 interface (VCOM1 on the nRF9151 DK).

doc/app/sm_logging.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Logs often refer to the |SM| application logging while the modem logs are referr
1313
Application logging
1414
*******************
1515

16-
|SM| outputs application logs over ``UART1`` (VCOM1 on the nRF9151 DK) by default.
17-
The UART is kept suspended at startup and activated at runtime using the ``AT#XLOG=1`` command.
18-
This avoids any UART power overhead when logs are not needed.
16+
|SM| outputs B0, MCUboot, and application logs over ``UART1`` (VCOM1 on the nRF9151 DK) during boot.
17+
After the application is initialized, the log backend is disabled, and the UART is suspended.
18+
Use ``AT#XLOG=1`` to enable application logs and resume the UART.
19+
This avoids UART power overhead when logs are not needed during normal operation.
1920
See :ref:`SM_AT_trace` for the full command reference.
2021

2122
.. note::
@@ -83,7 +84,7 @@ To also enable the modem trace backend (``AT#XTRACE``), build with the Kconfig o
8384
8485
west build -p -b nrf9151dk/nrf9151/ns -- -DEXTRA_CONF_FILE="overlay-trace-backend-uart.conf"
8586
86-
After flashing, the UART is suspended at startup.
87+
After the application is initialized, the UART is suspended.
8788
Use ``AT#XLOG=1`` to activate application logs and ``AT#XTRACE=1`` to activate modem traces.
8889
See :ref:`SM_AT_trace` for the full command reference.
8990

0 commit comments

Comments
 (0)