Memfault

The Memfault module provides an integration of Memfault SDK into nRF Connect SDK and expands the functionality of the SDK with some options that are specific to nRF Connect SDK.

Overview

Memfault SDK is an SDK for embedded devices to make use of services that Memfault offers on their platform.

The SDK provides a functionality to collect debug information from devices in the form of coredumps, error traces, metrics, logs and more. Information that is collected from the device can be sent to Memfault’s cloud solution for further analysis. Communication with the Memfault Cloud is handled by APIs available in Memfault SDK, while the integration code of the SDK in nRF Connect SDK provides some additional functionality.

For official documentation for Memfault SDK and the Memfault platform in general, see Memfault Docs.

See the nRF9160: Memfault sample for an example of Memfault implementation in nRF Connect SDK.

Memfault in nRF Connect SDK currently supports the nRF9160-based build targets.

Using Memfault SDK

The SDK is part of the West manifest in nRF Connect SDK and is automatically downloaded when running west update. By default, it is downloaded to <nRF Connect SDK path>/modules/lib/memfault-firmware-sdk/.

To include Memfault in your build, enable the Kconfig option CONFIG_MEMFAULT. The APIs in Memfault SDK can then be linked into your application.

In addition, you must configure a Memfault project key using CONFIG_MEMFAULT_NCS_PROJECT_KEY. CONFIG_MEMFAULT_NCS_PROJECT_KEY is located in ../overlay-memfault.conf.

To get access to all the benefits, like up to 100 free devices connected, register at the Memfault registration page.

Configuration

In general, configuration of Memfault SDK in nRF Connect SDK is done using Kconfig options. Kconfig options are defined both in Memfault SDK and in the integration layer, which integrates the SDK into nRF Connect SDK. Kconfig options of the integration layer are located in modules/memfault/Kconfig. These Kconfig options are differentiated by two distinct prefixes:

  • CONFIG_MEMFAULT_ - Prefix for options defined in Memfault SDK

  • CONFIG_MEMFAULT_NCS_ - Prefix for options defined in nRF Connect SDK

Configuration files

If you just want to do a quick test with a sample, disable the CONFIG_MEMFAULT_USER_CONFIG_ENABLE option in the prj.conf to avoid adding the user configuration files. Otherwise, follow the instructions below.

Memfault SDK requires three files in the include path during the build process. Add a new folder into your project called config and add the following three files:

  • memfault_platform_config.h - Sets Memfault SDK configurations that are not covered by Kconfig options

  • memfault_metrics_heartbeat_config.def - Defines application-specific metrics

  • memfault_trace_reason_user_config.def - Defines application-specific trace reasons

For more information, you can see Memfault nRF Connect SDK integration guide. You can use the files in the nRF9160: Memfault sample as a reference. To have these configuration files in the include path, add the following in the CMakeLists.txt file:

zephyr_include_directories(config)

Configuration options in Memfault SDK

Following are some of the configuration options that Memfault SDK define:

You can find more details on each option using menuconfig, guiconfig, and in the Kconfig sources in modules/lib/memfault-firmware-sdk/ports/zephyr/Kconfig.

Note

The Memfault shell is enabled by default, using the UART interface. If AT Host library and the memfault module are enabled simultaneously, both will not behave as expected, as they both require the UART same interface. Therefore, it is recommended to only enable one of these at the same time. To disable the Memfault shell, you need to disable the two configurations, CONFIG_MEMFAULT_SHELL and CONFIG_MEMFAULT_NRF_SHELL.

Configuration options in nRF Connect SDK

The Kconfig options for Memfault that are defined in nRF Connect SDK provide some additional features compared to the options that are already implemented in Memfault SDK:

  • CONFIG_MEMFAULT_NCS_PROJECT_KEY

  • CONFIG_MEMFAULT_NCS_PROVISION_CERTIFICATES

  • CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP

  • CONFIG_MEMFAULT_NCS_LTE_METRICS

  • CONFIG_MEMFAULT_NCS_STACK_METRICS

The nRF Connect SDK integration of Memfault SDK provides default values for some metadata that are required to identify the firmware when it is sent to Memfault cloud. These defaults can be controlled by using the configuration options below:

  • CONFIG_MEMFAULT_NCS_DEVICE_ID

  • CONFIG_MEMFAULT_NCS_HW_VERSION

  • CONFIG_MEMFAULT_NCS_FW_TYPE

  • CONFIG_MEMFAULT_NCS_FW_VERSION_STATIC

  • CONFIG_MEMFAULT_NCS_FW_VERSION_PREFIX

API documentation

Header file: include/memfault_ncs.h
Source files: modules/memfault/
group memfault_ncs

Convenience functions for using Memfault firmware SDK with nRF Connect SDK.

Functions

int memfault_ncs_device_id_set(const char *device_id, size_t len)

Set the Memfault device ID.

Note

In order to use this API successfully, CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME must be enabled.

Parameters
  • device_id – Pointer to device ID buffer

  • len – Length of device ID. Can not exceed CONFIG_MEMFAULT_NCS_DEVICE_ID_MAX_LEN.

Returns

0 on success, otherwise a negative error code