This is an example project for Segger Embedded Studio and the nRF5 SDK, targeting the nRF52480-DK ("pca10056") dev board.
Make sure the SDK_ROOT
macro is set up in Segger Embedded Studio:
-
Download and unpack the nRF5 SDK. This example was tested with v15.2.0, which can be downloaded here.
-
In the nRF5 SDK, disable the nRF5 SDK
app_error.h
file by renaming it:mv components/libraries/util/app_error.h{,.overriden}
-
Clone this repo somewhere:
git clone --recursive \ https://github.com/memfault/nrf5-segger-embedded-studio-example.git
-
Open segger embedded studio and open the solution from
<path_to_this_repo>/pca10056/blank/ses/cli_pca10056.emProject
-
Build and flash to the nRF52480-DK
-
Use the built-in RTT terminal to execute the Memfault Demo CLI commands
The overall strategy to integrating Memfault to a Segger Embedded Studio project is as follows:
-
Add the memfault sdk as a git submodule (only if the project is already using git, otherwise just clone the Memfault SDK instead):
❯ git submodule add https://github.com/memfault/memfault-firmware-sdk.git third_party/memfault-firmware-sdk
-
Add the source files; for example, as a virtual folder with the following exclusions (example below is the content in the
.emProject
file itself; can be added from within Segger Embedded Studio or by manually editing the file in a text editor):<folder Name="third_party/memfault-firmware-sdk" exclude="cmake;components/http;examples;scripts;tests;atmel;cypress;dialog;emlib;esp8266_sdk;esp_idf;freertos;lwip;mbedtls;mynewt;nxp;particle;qp;s32sdk;stm32cube;templates;zephyr;nrf5_coredump_storage.c" filter="*.c" path="../../../third_party/memfault-firmware-sdk" recurse="Yes" />
../../../third_party/memfault-firmware-sdk/examples/nrf5/apps/memfault_demo_app/third_party/memfault/sdk_overrides
../../../third_party/memfault-firmware-sdk/components/include
../../../memfault_port
../../../third_party/memfault-firmware-sdk/ports/include
This is usually the flash_placement.xml
file. It needs to include the
following section for the Build ID:
<ProgramSection alignment="4" load="Yes" name=".text" />
<!-- placing it right after the .text section -->
<ProgramSection alignment="4" keep="Yes" load="Yes" name=".note.gnu.build-id" inputsections="*(.note.gnu.build-id)" address_symbol="__start_gnu_build_id_start" end_symbol="__stop_gnu_build_id_stop" />
Under project Options -> Code -> Linker -> Additional Linker Options, add
--build-id
on its own line. Example here for the .emProject
file:
<solution Name="MyProject" target="8" version="2">
<project Name="MyProject">
<configuration
...
linker_additional_options="--build-id"
In this example, they're added in thememfault_port
folder as a virtual folder,
which can be added through the UI, or by directly modifying the .emProject
XML:
<folder
Name="memfault_port"
exclude=""
filter="*.c"
path="../../../memfault_port"
recurse="Yes" />
Note that the
memfault_port/memfault_platform_log_config.h
and
memfault_port/memfault_platform_config.h
files contained required settings for successfully building the project,
be sure to copy them as-in into the target project (or review the settings
and make sure the necessary ones are included).
#include "memfault/components.h"
...
int main(void) {
memfault_platform_boot();
...