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 |
Board target |
---|---|---|---|
PCA10153 |
|
||
PCA10090 |
|
||
PCA10171 |
|
When built for a board target with the */ns
variant, 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:
Download the nRF9160 DK board controller firmware from the nRF9160 DK downloads page.
Make sure the PROG/DEBUG SW10 switch on the nRF9160 DK is set to nRF52.
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 on the nRF9160 DK for more details.
Overview
The Modem trace backend sample implements and selects a custom trace backend to receive traces from the nRF91 Series 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 a board target with the */ns
variant, 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, follow the instructions in Configuring and building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
Testing
After programming the sample to your development kit, complete the following steps to test it:
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.
Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Power on or reset your nRF91 Series DK.
Observe that the sample starts and connects to the network.
Observe that the sample displays the amount of received trace data bytes, throughput, and percentage of CPU load.
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: