nRF9160: 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 kit:

Hardware platforms

PCA

Board name

Build target

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

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

Overview

The Modem trace backend sample implements and selects a custom trace backend to receive traces from the nRF9160 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/nrf9160/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 Building and programming an application for other building and programming scenarios and Testing and debugging an application 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, PuTTY). See How to connect with PuTTY for the required settings.

  3. Power on or reset your nRF9160 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: