From 4b518fb841345d723266d37dcb68a9f95838fd8f Mon Sep 17 00:00:00 2001 From: Markus Lassila Date: Wed, 25 Mar 2026 13:07:53 +0200 Subject: [PATCH] app: Do not call LOG_PANIC() with reset or shutdown Calling LOG_PANIC() can lead to RTT trace corruption and assert as the RTT trace is intended to be sent only from logging thread. This was observed with full modem FOTA. Signed-off-by: Markus Lassila --- app/src/main.c | 2 +- app/src/sm_at_commands.c | 3 +-- app/src/sm_at_dfu.c | 4 ++-- app/src/sm_at_fota.c | 2 +- app/src/sm_at_host.c | 1 - app/src/sm_ctrl_pin.c | 3 ++- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index d4662c53..defc139e 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -308,7 +308,7 @@ static int sm_main(void) return ret; exit_reboot: - LOG_PANIC(); + log_flush(); sys_reboot(SYS_REBOOT_COLD); } SYS_INIT(sm_main, APPLICATION, 100); diff --git a/app/src/sm_at_commands.c b/app/src/sm_at_commands.c index afc0becb..391ed8f0 100644 --- a/app/src/sm_at_commands.c +++ b/app/src/sm_at_commands.c @@ -141,7 +141,6 @@ static void sm_shutdown(void) { sm_at_host_uninit(); sm_power_off_modem(); - LOG_PANIC(); sm_ctrl_pin_enter_shutdown(); } @@ -160,7 +159,7 @@ FUNC_NORETURN void sm_reset(void) { sm_at_host_uninit(); sm_power_off_modem(); - LOG_PANIC(); + log_flush(); sys_reboot(SYS_REBOOT_COLD); } diff --git a/app/src/sm_at_dfu.c b/app/src/sm_at_dfu.c index 03c30510..d1480178 100644 --- a/app/src/sm_at_dfu.c +++ b/app/src/sm_at_dfu.c @@ -312,7 +312,7 @@ static int handle_at_xdfu_init(enum at_parser_cmd_type cmd_type, struct at_parse (void)set_full_mfw_dfu_segment_type(DFU_FULL_MFW_SEGMENT_BOOTLOADER); - LOG_PANIC(); + log_flush(); sys_reboot(SYS_REBOOT_COLD); default: LOG_ERR("Invalid target type: %d", type); @@ -566,7 +566,7 @@ static int handle_at_xdfu_apply(enum at_parser_cmd_type cmd_type, struct at_pars (void)set_full_mfw_dfu_segment_type( DFU_FULL_MFW_SEGMENT_BOOTLOADER); LOG_INF("Firmware update successful, rebooting..."); - LOG_PANIC(); + log_flush(); sys_reboot(SYS_REBOOT_COLD); } } diff --git a/app/src/sm_at_fota.c b/app/src/sm_at_fota.c index db3dcf26..3b04a6dd 100644 --- a/app/src/sm_at_fota.c +++ b/app/src/sm_at_fota.c @@ -524,7 +524,7 @@ FUNC_NORETURN static void handle_full_fota_activation_fail(int ret) LOG_INF("External flash erase succeeded"); LOG_WRN("Rebooting..."); - LOG_PANIC(); + log_flush(); sys_reboot(SYS_REBOOT_COLD); } diff --git a/app/src/sm_at_host.c b/app/src/sm_at_host.c index 9c9b48e2..ba653d94 100644 --- a/app/src/sm_at_host.c +++ b/app/src/sm_at_host.c @@ -599,7 +599,6 @@ static void handle_bootloader_at_cmd(uint8_t *buf, size_t buf_size, char *at_cmd } } else if (strncasecmp(at_cmd, AT_XRESET_CMD, sizeof(AT_XRESET_CMD) - 1) == 0) { LOG_INF("Rebooting device via %s command", AT_XRESET_CMD); - LOG_PANIC(); final_call(sm_reset); } else { LOG_ERR("AT command not supported in bootloader mode: %s", at_cmd); diff --git a/app/src/sm_ctrl_pin.c b/app/src/sm_ctrl_pin.c index 45217788..d547f837 100644 --- a/app/src/sm_ctrl_pin.c +++ b/app/src/sm_ctrl_pin.c @@ -101,7 +101,7 @@ void sm_ctrl_pin_enter_sleep_no_uninit(bool at_host_power_off) } LOG_INF("Entering sleep. No uninit."); - LOG_PANIC(); + log_flush(); k_sleep(K_MSEC(100)); @@ -155,6 +155,7 @@ void sm_ctrl_pin_enter_idle(void) void sm_ctrl_pin_enter_shutdown(void) { LOG_INF("Entering shutdown."); + log_flush(); k_sleep(K_MSEC(100)); nrf_regulators_system_off(NRF_REGULATORS_NS);