Skip to content

Commit b047ba3

Browse files
committed
app: log_flush called when log backend initialized
log_flush() can only be called when log backend has been initialized. Jira: SM-304 Signed-off-by: Tommi Rantanen <tommi.rantanen@nordicsemi.no>
1 parent 8bb736e commit b047ba3

11 files changed

Lines changed: 53 additions & 8 deletions

File tree

app/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "sm_util.h"
2020
#include "sm_ctrl_pin.h"
2121
#include "sm_uart_handler.h"
22+
#include "sm_log.h"
2223

2324
LOG_MODULE_REGISTER(sm, CONFIG_SM_LOG_LEVEL);
2425

@@ -291,7 +292,7 @@ static int sm_main(void)
291292
return ret;
292293

293294
exit_reboot:
294-
log_flush();
295+
sm_log_flush();
295296
sys_reboot(SYS_REBOOT_COLD);
296297
}
297298
SYS_INIT(sm_main, APPLICATION, 100);

app/src/sm_at_commands.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "sm_at_fota.h"
3232
#include "sm_version.h"
3333
#include "sm_at_nrfcloud.h"
34+
#include "sm_log.h"
3435

3536
LOG_MODULE_REGISTER(sm_at, CONFIG_SM_LOG_LEVEL);
3637

@@ -161,7 +162,7 @@ FUNC_NORETURN void sm_reset(void)
161162
{
162163
sm_at_host_uninit();
163164
sm_power_off_modem();
164-
log_flush();
165+
sm_log_flush();
165166
sys_reboot(SYS_REBOOT_COLD);
166167
}
167168

app/src/sm_at_dfu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "sm_at_dfu.h"
2323
#include "sm_settings.h"
2424
#include "sm_uart_handler.h"
25+
#include "sm_log.h"
2526

2627
LOG_MODULE_REGISTER(sm_dfu, CONFIG_SM_LOG_LEVEL);
2728

@@ -331,7 +332,7 @@ static int handle_at_xdfu_init(enum at_parser_cmd_type cmd_type, struct at_parse
331332

332333
(void)set_full_mfw_dfu_segment_type(DFU_FULL_MFW_SEGMENT_BOOTLOADER);
333334

334-
log_flush();
335+
sm_log_flush();
335336
sys_reboot(SYS_REBOOT_COLD);
336337
default:
337338
LOG_ERR("Invalid target type: %d", type);
@@ -622,7 +623,7 @@ static int handle_at_xdfu_apply(enum at_parser_cmd_type cmd_type, struct at_pars
622623
(void)set_full_mfw_dfu_segment_type(
623624
DFU_FULL_MFW_SEGMENT_BOOTLOADER);
624625
LOG_INF("Firmware update successful, rebooting...");
625-
log_flush();
626+
sm_log_flush();
626627
sys_reboot(SYS_REBOOT_COLD);
627628
}
628629
}

app/src/sm_at_fota.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "sm_at_host.h"
2525
#include "sm_at_fota.h"
2626
#include "sm_defines.h"
27+
#include "sm_log.h"
2728

2829
LOG_MODULE_REGISTER(sm_fota, CONFIG_SM_LOG_LEVEL);
2930

@@ -582,7 +583,7 @@ FUNC_NORETURN static void handle_full_fota_activation_fail(int ret)
582583
LOG_INF("External flash erase succeeded");
583584

584585
LOG_WRN("Rebooting...");
585-
log_flush();
586+
sm_log_flush();
586587
sys_reboot(SYS_REBOOT_COLD);
587588
}
588589

app/src/sm_at_host.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,6 @@ SYS_INIT(sm_at_host_init, APPLICATION, 0);
21082108
void sm_at_host_uninit(void)
21092109
{
21102110
/* TODO: implement this */
2111-
LOG_ERR("at_host uninit not yet implemented");
21122111
}
21132112

21142113
SM_AT_CMD_CUSTOM(xdatactrl, "AT#XDATACTRL", handle_at_datactrl);

app/src/sm_ctrl_pin.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sm_defines.h"
1616
#include "sm_util.h"
1717
#include "sm_ctrl_pin.h"
18+
#include "sm_log.h"
1819

1920
LOG_MODULE_REGISTER(sm_ctrl_pin, CONFIG_SM_LOG_LEVEL);
2021

@@ -101,7 +102,7 @@ void sm_ctrl_pin_enter_sleep_no_uninit(bool at_host_power_off)
101102
}
102103

103104
LOG_INF("Entering sleep. No uninit.");
104-
log_flush();
105+
sm_log_flush();
105106

106107
k_sleep(K_MSEC(100));
107108

@@ -155,7 +156,7 @@ void sm_ctrl_pin_enter_idle(void)
155156
void sm_ctrl_pin_enter_shutdown(void)
156157
{
157158
LOG_INF("Entering shutdown.");
158-
log_flush();
159+
sm_log_flush();
159160
k_sleep(K_MSEC(100));
160161

161162
nrf_regulators_system_off(NRF_REGULATORS_NS);

app/src/sm_log.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ static bool uart_is_active(void)
6969
return state == PM_DEVICE_STATE_ACTIVE;
7070
}
7171

72+
void sm_log_flush(void)
73+
{
74+
const struct log_backend *log_be = log_backend_get_by_name("log_backend_uart");
75+
76+
if (log_be && log_be->cb && log_be->cb->initialized) {
77+
log_flush();
78+
}
79+
}
80+
7281
SM_AT_CMD_CUSTOM(xlog, "AT#XLOG", handle_at_log);
7382
STATIC int handle_at_log(enum at_parser_cmd_type cmd_type, struct at_parser *parser, uint32_t)
7483
{

app/src/sm_log.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef SM_LOG_
8+
#define SM_LOG_
9+
10+
/**@file sm_log.h
11+
*
12+
* @brief Log functions for Serial Modem
13+
* @{
14+
*/
15+
16+
void sm_log_flush(void);
17+
18+
/** @} */
19+
20+
#endif /* SM_LOG_ */

app/tests/at_commands/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ target_sources(app PRIVATE
6464
../stubs/tfm_stubs.c
6565
../stubs/at_cmd_custom_stubs.c
6666
../stubs/sm_workq.c
67+
../stubs/sm_log_stubs.c
6768
../../src/sm_util.c
6869
../../src/sm_at_commands.c
6970
../../src/sm_at_host.c

app/tests/at_socket/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ target_sources(app PRIVATE
6868
../stubs/tfm_stubs.c
6969
../stubs/at_cmd_custom_stubs.c
7070
../stubs/sm_workq.c
71+
../stubs/sm_log_stubs.c
7172
../../src/sm_util.c
7273
../../src/sm_at_socket.c
7374
../../src/sm_at_host.c

0 commit comments

Comments
 (0)