PPI trace

The PPI trace sample shows how to trace hardware events on GPIO pins. It uses the PPI trace module.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

nrf9160dk_nrf9160

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

The sample also requires a logic analyzer.

Overview

The sample initializes trace pins to observe the following hardware events:

The sample sets up a Counter to generate an NRF_RTC_EVENT_COMPARE_0 event every 50 ms. Initially, RTC runs on RC low frequency (lower precision) as clock source. When the crystal is ready, it switches seamlessly to crystal (precise) as clock source. When the low-frequency crystal is ready, an NRF_CLOCK_EVENT_LFCLKSTARTED event is generated.

The sample uses Zephyr’s Link Layer instead of the SoftDevice Link Layer. This is because the SoftDevice Link Layer is blocked during the initialization until the low-frequency crystal is started and the clock is stable. For this reason, the SoftDevice Link Layer cannot be used to show the NRF_CLOCK_EVENT_LFCLKSTARTED event on pin.

Configuration

See Configuring your application for information about how to permanently or temporarily change the configuration.

FEM support

You can add support for the nRF21540 front-end module to this sample by using one of the following options, depending on your hardware:

  • Build the sample for one board that contains the nRF21540 FEM, such as nrf21540dk_nrf52840.

  • Manually create a devicetree overlay file that describes how FEM is connected to the nRF5 SoC in your device. See Set devicetree overlays for different ways of adding the overlay file.

  • Provide nRF21540 FEM capabilities by using a shield, for example the nRF21540 EK shield that is available in the nRF Connect SDK. In this case, build the project for a board connected to the shield you are using with an appropriate variable included in the build command, for example SHIELD=nrf21540_ek. This variable instructs the build system to append the appropriate devicetree overlay file.

    To build the sample in the nRF Connect for VS Code IDE for an nRF52840 DK with the nRF21540 EK attached, add the shield variable in the build configuration’s Extra CMake arguments and rebuild the build configuration. For example: -DSHIELD=nrf21540_ek.

    See nRF Connect for VS Code extension pack documentation for more information.

    See Programming nRF21540 EK for information about how to program when you are using a board with a network core, for example nRF5340 DK.

Each of these options adds the description of the nRF21540 FEM to the devicetree. See Working with RF front-end modules for more information about FEM in the nRF Connect SDK.

To add support for other front-end modules, add the respective devicetree file entries to the board devicetree file or the devicetree overlay file.

Building and running

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

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 a logic analyzer to the pins that are used for tracing. Check the sample configuration for information about which pins are used.

  2. Observe that:

    • The pin that is tracing the RTC Tick event is toggling with a frequency of approximately 32 kHz.

    • The pin that is tracing the RTC Compare event is toggling approximately every 50 ms.

    • The pin that is tracing the LFCLK Started event is set at some point.

  3. Measure the typical time between two consecutive toggles of the pin that is tracing the RTC Compare event, before and after the LFCLK Started event is generated.

    Observe that the precision increases when the low-frequency crystal is started.

  4. Observe periodical radio activity during Bluetooth advertising.

Dependencies

This sample uses the following nRF Connect SDK subsystems:

In addition, it uses the following Zephyr libraries: