Cellular: Modem trace backend

The Modem trace backend sample demonstrates how to add a user-defined modem trace backend to an application.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF9161 DK

PCA10153

nrf9161dk_nrf9161

nrf9161dk_nrf9161_ns

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

nrf9160dk_nrf9160_ns

nRF9151 DK

nrf9151dk_nrf9151

nrf9151dk_nrf9151_ns

When built for an _ns build target, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

External flash

To use the external flash memory on the nRF9160 DK v0.14.0 or later versions, the board controller firmware must be of version v2.0.1. This is the factory firmware version. If you need to program the board controller firmware again, complete the following steps:

  1. Download the nRF9160 DK board controller firmware from the nRF9160 DK downloads page.

  2. Make sure the PROG/DEBUG SW10 switch on the nRF9160 DK is set to nRF52.

  3. Program the board controller firmware (nrf9160_dk_board_controller_fw_2.0.1.hex) using the Programmer app in nRF Connect for Desktop.

Note

The board controller firmware version must be v2.0.1 or higher, which enables the pin routing to external flash.

See Board controller for more details.

Overview

The Modem trace backend sample implements and selects a custom trace backend to receive traces from the cellular modem. For demonstration purposes, the custom trace backend counts the number of bytes received and calculates the data rate of modem traces received. The CPU utilization is also measured. The byte count, data rate, and CPU load are periodically printed to terminal using a delayable work item and the system workqueue. The custom trace backend is implemented in modem_trace_backend/src/trace_print_stats.c. However, it is possible to add a custom modem trace backend as a library and use it in more than one application. See Adding custom trace backends for details.

Building and running

This sample can be found under samples/cellular/modem_trace_backend in the nRF Connect SDK folder structure.

When built as firmware image for the _ns build target, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Configuring and building an application for other building scenarios, Programming an application for programming steps, and Testing for general information about testing and debugging in the nRF Connect SDK.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

  3. Power on or reset your nRF91 Series DK.

  4. Observe that the sample starts and connects to the network.

  5. Observe that the sample displays the amount of received trace data bytes, throughput, and percentage of CPU load.

  6. Observe that the sample completes with a message on the terminal.

Sample Output

The sample shows the following output:

Custom trace backend initialized
*** Booting Zephyr OS build v3.0.99-ncs1  ***
Modem trace backend sample started
Connecting to network
LTE mode changed to 1
Traces received:   9.2kB, 18.4kB/s, CPU-load:  6.48%
Traces received:  14.4kB, 10.3kB/s, CPU-load:  3.65%
Traces received:  36.7kB, 44.3kB/s, CPU-load:  6.36%
Traces received:  51.6kB, 29.4kB/s, CPU-load:  5.72%
Traces received:  65.9kB, 28.3kB/s, CPU-load:  5.00%
Traces received:  67.5kB,  3.3kB/s, CPU-load:  2.34%
Traces received:  68.6kB,  2.1kB/s, CPU-load:  2.10%
Traces received:  70.0kB,  2.7kB/s, CPU-load:  2.12%
Traces received:  71.5kB,  3.0kB/s, CPU-load:  2.23%
Traces received:  74.2kB,  5.4kB/s, CPU-load:  2.60%
Traces received:  81.8kB, 15.1kB/s, CPU-load:  3.38%
Traces received:  82.2kB,  0.7kB/s, CPU-load:  1.64%
Traces received:  83.9kB,  3.4kB/s, CPU-load:  2.37%
LTE mode changed to 0
Custom trace backend deinitialized
Bye

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib library:

It uses the following Zephyr library:

In addition, it uses the following secure firmware component: