Skip to content

Latest commit

 

History

History
132 lines (97 loc) · 4.22 KB

File metadata and controls

132 lines (97 loc) · 4.22 KB

nRF5 SDK Segger Embedded Studio Memfault Example

This is an example project for Segger Embedded Studio and the nRF5 SDK, targeting the nRF52480-DK ("pca10056") dev board.

Building

Prerequisites

Make sure the SDK_ROOT macro is set up in Segger Embedded Studio:

Setup Steps

  1. Download and unpack the nRF5 SDK. This example was tested with v15.2.0, which can be downloaded here.

  2. In the nRF5 SDK, disable the nRF5 SDK app_error.h file by renaming it:

    mv components/libraries/util/app_error.h{,.overriden}
  3. Clone this repo somewhere:

    git clone --recursive \
       https://github.com/memfault/nrf5-segger-embedded-studio-example.git
  4. Open segger embedded studio and open the solution from <path_to_this_repo>/pca10056/blank/ses/cli_pca10056.emProject

  5. Build and flash to the nRF52480-DK

  6. Use the built-in RTT terminal to execute the Memfault Demo CLI commands

Details on Memfault integration

The overall strategy to integrating Memfault to a Segger Embedded Studio project is as follows:

1. Add the memfault source files

  1. 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
  2. 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" />

2. Add the necessary search paths to the Preprocessor configuration

../../../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

3. Modify the linker XML

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" />

4. Add the linker option for build id

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"

5. Add the necessary memfault port files

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).

6. Add the boot function to the application’s main() function:

#include "memfault/components.h"
...
int main(void) {
  memfault_platform_boot();
...