Skip to content

Commit

Permalink
modules: memfault: Add automatic sending of coredumps over LTE
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
simensrostad committed Jan 22, 2025
1 parent 1c36f9c commit 99efc15
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 9 deletions.
2 changes: 2 additions & 0 deletions applications/serial_lte_modem/doc/slm_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ The following configuration files are provided:
It can be customized to fit your configuration (UART, baud rate, and so on).
By default, it sets the baud rate of the PPP UART to 1 000 000.

* :file:`overlay-memfault.conf` - Configuration file that enables `Memfault`_.

* :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.
See :ref:`slm_as_zephyr_modem` for more information.

Expand Down
28 changes: 28 additions & 0 deletions applications/serial_lte_modem/overlay-memfault.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2025 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_MEMFAULT=y
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD=y
CONFIG_MODEM_KEY_MGMT=y
CONFIG_MEMFAULT_LOGGING_ENABLE=y
CONFIG_MEMFAULT_HTTP_ENABLE=y
CONFIG_MEMFAULT_NCS_LTE_METRICS=y
CONFIG_MEMFAULT_NCS_STACK_METRICS=y
CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP=y
CONFIG_MEMFAULT_NCS_DEVICE_ID_IMEI=y
CONFIG_MEMFAULT_LOGGING_RAM_SIZE=4096
CONFIG_MEMFAULT_HEAP_STATS=y
CONFIG_MEMFAULT_HTTP_DEDICATED_WORKQUEUE_STACK_SIZE=1560
CONFIG_MEMFAULT_COREDUMP_FULL_THREAD_STACKS=y
CONFIG_MEMFAULT_EVENT_STORAGE_SIZE=2048
CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED=y
CONFIG_PDN=y
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_LC_EDRX_MODULE=y
CONFIG_LTE_LC_PSM_MODULE=y

# Memfault depends on POSIX, disable unneeded POSIX features
CONFIG_POSIX_FILE_SYSTEM=n
3 changes: 2 additions & 1 deletion applications/serial_lte_modem/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# General config
CONFIG_LOG=y
CONFIG_ASSERT=y
CONFIG_ASSERT_VERBOSE=n
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_STACK_SENTINEL=y
CONFIG_PICOLIBC_IO_FLOAT=y
Expand Down Expand Up @@ -118,7 +120,6 @@ CONFIG_SLM_CUSTOMER_VERSION=""
CONFIG_SLM_EXTERNAL_XTAL=n

# debug options
#CONFIG_ASSERT=y
#CONFIG_LOG_BUFFER_SIZE=16384
#CONFIG_SLM_LOG_LEVEL_DBG=y
#CONFIG_LOG_PRINTK=n
Expand Down
15 changes: 8 additions & 7 deletions applications/serial_lte_modem/src/slm_at_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ enum sleep_modes {
static struct {
struct k_work_delayable work;
uint32_t mode;
} sleep;
} sleep_control;
#endif

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

static void go_sleep_wk(struct k_work *)
{
if (sleep.mode == SLEEP_MODE_IDLE) {
if (sleep_control.mode == SLEEP_MODE_IDLE) {
if (slm_at_host_power_off() == 0) {
slm_enter_idle();
} else {
LOG_ERR("failed to power off UART");
}
} else if (sleep.mode == SLEEP_MODE_DEEP) {
} else if (sleep_control.mode == SLEEP_MODE_DEEP) {
slm_enter_sleep();
}
}
Expand All @@ -148,12 +148,13 @@ static int handle_at_sleep(enum at_parser_cmd_type cmd_type, struct at_parser *p
int ret = -EINVAL;

if (cmd_type == AT_PARSER_CMD_TYPE_SET) {
ret = at_parser_num_get(parser, 1, &sleep.mode);
ret = at_parser_num_get(parser, 1, &sleep_control.mode);
if (ret) {
return -EINVAL;
}
if (sleep.mode == SLEEP_MODE_DEEP || sleep.mode == SLEEP_MODE_IDLE) {
k_work_reschedule(&sleep.work, SLM_UART_RESPONSE_DELAY);
if (sleep_control.mode == SLEEP_MODE_DEEP ||
sleep_control.mode == SLEEP_MODE_IDLE) {
k_work_reschedule(&sleep_control.work, SLM_UART_RESPONSE_DELAY);
} else {
ret = -EINVAL;
}
Expand Down Expand Up @@ -376,7 +377,7 @@ int slm_at_init(void)
int err;

#if POWER_PIN_IS_ENABLED
k_work_init_delayable(&sleep.work, go_sleep_wk);
k_work_init_delayable(&sleep_control.work, go_sleep_wk);
#endif

err = slm_at_tcp_proxy_init();
Expand Down
4 changes: 4 additions & 0 deletions modules/memfault-firmware-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ zephyr_library_sources_ifdef(
CONFIG_MEMFAULT_NCS_BT_METRICS
memfault_bt_metrics.c)

zephyr_library_sources_ifdef(
CONFIG_MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED
memfault_lte_coredump.c)

zephyr_library_sources_ifdef(
CONFIG_MEMFAULT_NCS_ETB_CAPTURE
memfault_etb_trace_capture.c)
Expand Down
26 changes: 26 additions & 0 deletions modules/memfault-firmware-sdk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ config MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION
Implement the Memfault 'memfault_metrics_heartbeat_collect_data()' function
for the selected metrics. Disable this to override the implementation.

config MEMFAULT_NCS_POST_COREDUMP_ON_NETWORK_CONNECTED
bool "Post coredump on network connected"
depends on PDN
depends on LTE_LINK_CONTROL
select SMF
select SMF_ANCESTOR_SUPPORT
select SMF_INITIAL_TRANSITION
help
Post coredump to Memfault when the device is connected to LTE network.

config MEMFAULT_NCS_POST_COREDUMP_RETRIES_MAX
int "Max number of coredump post retries"
default 3
help
Maximum number of retries to post a coredump to Memfault.

config MEMFAULT_NCS_POST_COREDUMP_RETRY_INTERVAL_SECONDS
int "Retry interval in seconds"
default 30
help
Interval in seconds between coredump post retries.

config MEMFAULT_NCS_POST_COREDUMP_THREAD_STACK_SIZE
int "Post coredump thread size"
default 512

config MEMFAULT_NCS_ETB_CAPTURE
bool "Enable ETB trace capture"
depends on ETB_TRACE
Expand Down
Loading

0 comments on commit 99efc15

Please sign in to comment.