Skip to content

Commit 108cf12

Browse files
simensrostadnordicjm
authored andcommitted
modules: memfault: Add automatic sending of coredumps over LTE
Add automatic sending of coredumps over LTE: - Add new file memfault_lte_coredump.c that uses LTE cereg and PDN to determine if the device is connected to the network. If connected, the layer will trigger sending of a stored coredump. Library is implemented with retry logic and backoff. - Add overlay file to SLM that enables Memfault features - Update Memfault sample to use the new coredump feature. - Add missing features to Memfault sample - Enable assertions by default in SLM, there is no reason why it should be enabled as long as there is space. Signed-off-by: Simen S. Røstad <[email protected]>
1 parent 71b516c commit 108cf12

File tree

18 files changed

+652
-12
lines changed

18 files changed

+652
-12
lines changed

applications/serial_lte_modem/doc/slm_description.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ The following configuration files are provided:
336336
It can be customized to fit your configuration (UART, baud rate, and so on).
337337
By default, it sets the baud rate of the PPP UART to 1 000 000.
338338

339+
* :file:`overlay-memfault.conf` - Configuration file that enables `Memfault`_.
340+
For more information about Memfault features in |NCS|, see :ref:`mod_memfault`.
341+
339342
* :file:`overlay-zephyr-modem.conf`, :file:`overlay-zephyr-modem-external-mcu.conf`, :file:`overlay-zephyr-modem-nrf9160dk-nrf52840.conf`, :file:`overlay-external-mcu.overlay`, and :file:`overlay-zephyr-modem-nrf9160dk-nrf52840.overlay` - These configuration files are used when compiling SLM to turn an nRF91 Series SiP into a Zephyr-compatible standalone modem.
340343
See :ref:`slm_as_zephyr_modem` for more information.
341344

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_MEMFAULT=y
8+
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD=y
9+
CONFIG_MODEM_KEY_MGMT=y
10+
CONFIG_MEMFAULT_LOGGING_ENABLE=y
11+
CONFIG_MEMFAULT_HTTP_ENABLE=y
12+
CONFIG_MEMFAULT_NCS_LTE_METRICS=y
13+
CONFIG_MEMFAULT_NCS_STACK_METRICS=y
14+
CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP=y
15+
CONFIG_MEMFAULT_NCS_DEVICE_ID_IMEI=y
16+
CONFIG_MEMFAULT_LOGGING_RAM_SIZE=4096
17+
CONFIG_MEMFAULT_HEAP_STATS=y
18+
CONFIG_MEMFAULT_HTTP_DEDICATED_WORKQUEUE_STACK_SIZE=1560
19+
CONFIG_MEMFAULT_COREDUMP_FULL_THREAD_STACKS=y
20+
CONFIG_MEMFAULT_EVENT_STORAGE_SIZE=2048
21+
CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED=y
22+
CONFIG_PDN=y
23+
CONFIG_LTE_LINK_CONTROL=y
24+
CONFIG_LTE_LC_EDRX_MODULE=y
25+
CONFIG_LTE_LC_PSM_MODULE=y
26+
27+
# Memfault depends on POSIX, disable unneeded POSIX features
28+
CONFIG_POSIX_FILE_SYSTEM=n

applications/serial_lte_modem/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#
66
# General config
77
CONFIG_LOG=y
8+
CONFIG_ASSERT=y
9+
CONFIG_ASSERT_VERBOSE=n
810
CONFIG_LOG_DEFAULT_LEVEL=3
911
CONFIG_STACK_SENTINEL=y
1012
CONFIG_PICOLIBC_IO_FLOAT=y
@@ -118,7 +120,6 @@ CONFIG_SLM_CUSTOMER_VERSION=""
118120
CONFIG_SLM_EXTERNAL_XTAL=n
119121

120122
# debug options
121-
#CONFIG_ASSERT=y
122123
#CONFIG_LOG_BUFFER_SIZE=16384
123124
#CONFIG_SLM_LOG_LEVEL_DBG=y
124125
#CONFIG_LOG_PRINTK=n

applications/serial_lte_modem/sample.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ tests:
2121
tags:
2222
- ci_build
2323
- sysbuild
24+
applications.serial_lte_modem.memfault:
25+
sysbuild: true
26+
build_only: true
27+
extra_args:
28+
- EXTRA_CONF_FILE=overlay-memfault.conf
29+
- CONFIG_MEMFAULT_NCS_PROJECT_KEY="dummy-key"
30+
platform_allow:
31+
- nrf9160dk/nrf9160/ns
32+
- nrf9161dk/nrf9161/ns
33+
- nrf9151dk/nrf9151/ns
34+
- nrf9131ek/nrf9131/ns
35+
integration_platforms:
36+
- nrf9160dk/nrf9160/ns
37+
- nrf9161dk/nrf9161/ns
38+
- nrf9151dk/nrf9151/ns
39+
- nrf9131ek/nrf9131/ns
40+
tags:
41+
- ci_build
42+
- sysbuild
2443
applications.serial_lte_modem.native_tls:
2544
sysbuild: true
2645
build_only: true

applications/serial_lte_modem/src/lwm2m_carrier/slm_at_carrier.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string.h>
99
#include <time.h>
1010
#include <lwm2m_carrier.h>
11+
#include <zephyr/sys/util.h>
1112
#include <zephyr/logging/log.h>
1213
#include <modem/nrf_modem_lib.h>
1314
#include <modem/at_parser.h>
@@ -51,7 +52,7 @@ static void print_err(const lwm2m_carrier_event_t *evt)
5152
"Connection failure",
5253
};
5354

54-
__ASSERT(PART_OF_ARRAY(strerr[err->type]),
55+
__ASSERT(PART_OF_ARRAY(strerr, strerr[err->type]),
5556
"Unhandled liblwm2m_carrier error");
5657

5758
LOG_ERR("LWM2M_CARRIER_EVENT_ERROR: %s, reason %d", strerr[err->type], err->value);
@@ -87,7 +88,7 @@ static void print_deferred(const lwm2m_carrier_event_t *evt)
8788
"Waiting for SIM MSISDN",
8889
};
8990

90-
__ASSERT(PART_OF_ARRAY(strdef[def->reason]),
91+
__ASSERT(PART_OF_ARRAY(strdef, strdef[def->reason]),
9192
"Unhandled deferred reason");
9293

9394
LOG_INF("LWM2M_CARRIER_EVENT_DEFERRED: reason %s, timeout %d seconds",

applications/serial_lte_modem/src/slm_at_commands.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ enum sleep_modes {
8181
static struct {
8282
struct k_work_delayable work;
8383
uint32_t mode;
84-
} sleep;
84+
} sleep_control;
8585
#endif
8686

8787
bool verify_datamode_control(uint16_t time_limit, uint16_t *time_limit_min);
@@ -130,13 +130,13 @@ static int handle_at_slmver(enum at_parser_cmd_type cmd_type, struct at_parser *
130130

131131
static void go_sleep_wk(struct k_work *)
132132
{
133-
if (sleep.mode == SLEEP_MODE_IDLE) {
133+
if (sleep_control.mode == SLEEP_MODE_IDLE) {
134134
if (slm_at_host_power_off() == 0) {
135135
slm_enter_idle();
136136
} else {
137137
LOG_ERR("failed to power off UART");
138138
}
139-
} else if (sleep.mode == SLEEP_MODE_DEEP) {
139+
} else if (sleep_control.mode == SLEEP_MODE_DEEP) {
140140
slm_enter_sleep();
141141
}
142142
}
@@ -148,12 +148,13 @@ static int handle_at_sleep(enum at_parser_cmd_type cmd_type, struct at_parser *p
148148
int ret = -EINVAL;
149149

150150
if (cmd_type == AT_PARSER_CMD_TYPE_SET) {
151-
ret = at_parser_num_get(parser, 1, &sleep.mode);
151+
ret = at_parser_num_get(parser, 1, &sleep_control.mode);
152152
if (ret) {
153153
return -EINVAL;
154154
}
155-
if (sleep.mode == SLEEP_MODE_DEEP || sleep.mode == SLEEP_MODE_IDLE) {
156-
k_work_reschedule(&sleep.work, SLM_UART_RESPONSE_DELAY);
155+
if (sleep_control.mode == SLEEP_MODE_DEEP ||
156+
sleep_control.mode == SLEEP_MODE_IDLE) {
157+
k_work_reschedule(&sleep_control.work, SLM_UART_RESPONSE_DELAY);
157158
} else {
158159
ret = -EINVAL;
159160
}
@@ -376,7 +377,7 @@ int slm_at_init(void)
376377
int err;
377378

378379
#if POWER_PIN_IS_ENABLED
379-
k_work_init_delayable(&sleep.work, go_sleep_wk);
380+
k_work_init_delayable(&sleep_control.work, go_sleep_wk);
380381
#endif
381382

382383
err = slm_at_tcp_proxy_init();

doc/nrf/libraries/debug/memfault_ncs.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ To have these configuration files in the include path, add the following to the
5858
5959
.. memfault_config_files_end
6060
61+
Automatic sending of coredumps to Memfault
62+
==========================================
63+
64+
To post a stored coredump from a previous crash to Memfault upon network connection, set the :kconfig:option:`CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED` Kconfig option to ``y``.
65+
The option is only supported for nRF91 Series devices.
66+
67+
The library has built-in connection awareness and tries to post the coredump to a maximum of the number set in the :kconfig:option:`CONFIG_MEMFAULT_NCS_POST_COREDUMP_RETRIES_MAX` Kconfig option, at an interval of the time set in the :kconfig:option:`CONFIG_MEMFAULT_NCS_POST_COREDUMP_RETRY_INTERVAL_SECONDS` Kconfig option between each attempt.
68+
If unsuccessful within the number of attempts, the library gives up.
69+
If at any point the network is lost during the retry process, the library waits for the device to reconnect before restarting the retry process.
70+
71+
This feature is useful when you want to post the coredump as soon as possible after a crash and it is not desirable to wait for the next periodic upload set by :kconfig:option:`CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD_INTERVAL_SECS`.
72+
Alternatively, you can manually trigger the coredump upload by calling the :c:func:`memfault_zephyr_port_post_data` function.
73+
You can use the :c:func:`memfault_coredump_has_valid_coredump` function to check whether a coredump is available.
6174

6275
Configuration options in Memfault SDK
6376
=====================================
@@ -93,6 +106,7 @@ Configuration options in |NCS|
93106

94107
The Kconfig options for Memfault that are defined in |NCS| provide some additional features compared to the options that are already implemented in Memfault SDK:
95108

109+
* :kconfig:option:`CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED`
96110
* :kconfig:option:`CONFIG_MEMFAULT_NCS_PROJECT_KEY`
97111
* :kconfig:option:`CONFIG_MEMFAULT_NCS_PROVISION_CERTIFICATES`
98112
* :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP`

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ nRF Machine Learning (Edge Impulse)
253253
Serial LTE modem
254254
----------------
255255

256+
* Added an overlay :file:`overlay-memfault.conf` file to enable Memfault.
257+
For more information about Memfault features in |NCS|, see :ref:`mod_memfault`.
256258
* Updated the application to use the :ref:`lib_downloader` library instead of the deprecated :ref:`lib_download_client` library.
257259

258260
Thingy:53: Matter weather station
@@ -702,7 +704,9 @@ Edge Impulse integration
702704
Memfault integration
703705
--------------------
704706

705-
|no_changes_yet_note|
707+
* Added a new feature to automatically post coredumps to Memfault when network connectivity is available.
708+
To enable this feature, set the :kconfig:option:`CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED` Kconfig option to ``y``.
709+
Only supported for nRF91 Series devices.
706710

707711
AVSystem integration
708712
--------------------

modules/memfault-firmware-sdk/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ zephyr_library_sources_ifdef(
3131
CONFIG_MEMFAULT_NCS_BT_METRICS
3232
memfault_bt_metrics.c)
3333

34+
zephyr_library_sources_ifdef(
35+
CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED
36+
memfault_lte_coredump.c)
37+
3438
zephyr_library_sources_ifdef(
3539
CONFIG_MEMFAULT_NCS_ETB_CAPTURE
3640
memfault_etb_trace_capture.c)

modules/memfault-firmware-sdk/Kconfig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,43 @@ config MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION
191191
Implement the Memfault 'memfault_metrics_heartbeat_collect_data()' function
192192
for the selected metrics. Disable this to override the implementation.
193193

194+
config MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED
195+
bool "Post coredump on network connected"
196+
depends on PDN
197+
depends on LTE_LINK_CONTROL
198+
depends on SOC_SERIES_NRF91X
199+
select SMF
200+
select SMF_ANCESTOR_SUPPORT
201+
select SMF_INITIAL_TRANSITION
202+
help
203+
Post coredump to Memfault when the device is connected to LTE network.
204+
This option is only supported for nRF91 targets.
205+
206+
config MEMFAULT_NCS_POST_COREDUMP_AFTER_INITIAL_DELAY
207+
bool "Post coredump after initial delay"
208+
default y
209+
help
210+
Delay coredump posting to Memfault to avoid conflicts with the application's
211+
TLS connection setup that occurs typically LTE network is obtained.
212+
The delay duration is defined by CONFIG_MEMFAULT_NCS_POST_COREDUMP_RETRY_INTERVAL_SECONDS.
213+
214+
config MEMFAULT_NCS_POST_COREDUMP_RETRIES_MAX
215+
int "Max number of coredump post retries"
216+
default 3
217+
default 4 if MEMFAULT_NCS_POST_COREDUMP_AFTER_INITIAL_WAIT
218+
help
219+
Maximum number of retries to post a coredump to Memfault.
220+
221+
config MEMFAULT_NCS_POST_COREDUMP_RETRY_INTERVAL_SECONDS
222+
int "Retry interval in seconds"
223+
default 30
224+
help
225+
Interval in seconds between coredump post retries.
226+
227+
config MEMFAULT_NCS_POST_COREDUMP_THREAD_STACK_SIZE
228+
int "Post coredump thread size"
229+
default 512
230+
194231
config MEMFAULT_NCS_ETB_CAPTURE
195232
bool "Enable ETB trace capture"
196233
depends on ETB_TRACE

0 commit comments

Comments
 (0)