Skip to content

Thread Co-processor

Overview

The Thread Co-processor sample demonstrates how to implement OpenThread’s Co-processor designs inside the Zephyr environment. The sample uses the Radio co-processor (RCP) architecture.

The sample is based on Zephyr’s OpenThread Co-Processor sample. However, it customizes Zephyr’s sample to fulfill the nRF Connect SDK requirements (for example, by increasing the stack size dedicated for the user application), and also extends it with features such as:

  • Increased Mbed TLS heap size.
  • Lowered main stack size to increase user application space.
  • No obsolete configuration options.
  • Vendor hooks for co-processor architecture allowing users to extend handled properties by their own, customized functionalities.
  • Thread 1.2 features.

Sniffing packets from a Thread network

You can use nRF Sniffer for 802.15.4 to capture and analyze packets exchanged on a Thread network.

Requirements

Before you start, check that you have the required hardware and software:

Building the sample

Before you start building, remember to set up the environment first.

Use the following steps to build the Thread Co-processor sample on the command line.

  1. Open a terminal window.

  2. Go to my-workspace/ncs-playground directory created in the Setting up the environment section.

    cd my-workspace/ncs-playground
    
  3. Build the sample using the west command, specifying the board (following the -b option) as connectkit_nrf52840:

    west build -p always -b connectkit_nrf52840 samples/openthread/coprocessor
    
    west build -p always -b connectkit_nrf52840 samples/openthread/coprocessor -- -DOVERLAY_CONFIG=overlay-vendor_hook.conf
    

    Tip

    The -p always option forces a pristine build, and is recommended for new users. Users may also use the -p auto option, which will use heuristics to determine if a pristine build is required, such as when building another sample.

  4. After running the west build command, the build files can be found in build/zephyr.

Flashing the firmware

The sample is designed to work with the UF2 Bootloader, so that you can easily flash the sample using the UF2 Bootloader. The firmware can be found in build/zephyr with the name zephyr.uf2.

To flash the firmware, complete the following steps:

  1. Push and hold the USER button and plug your board into the USB port of your computer. Release the USER button after your board is connected. The RGB LED turns green.

  2. It will mount as a Mass Storage Device called UF2BOOT.

  3. Drag and drop zephyr.uf2 onto the UF2BOOT volume. The RGB LED blinks red fast during flashing.

  4. Reset the board and the sample will start running.

Testing

After flashing the firmware to your board, complete the following steps to test it:

  1. Connect nRF52840 Connect Kit to your computer using the USB-C Cable.
  2. Get the board’s serial port name (for example, /dev/cu.usbmodem14201).
  3. Build the OpenThread POSIX applications by performing the following steps:

    1. Enter the openthread directory:

      cd modules/lib/openthread
      
    2. Install the OpenThread dependencies:

      ./script/bootstrap
      
    3. Build the ot-daemon and ot-ctl applications with support for Thread v1.2:

      ./script/cmake-build posix -DOT_THREAD_VERSION=1.2 -DOT_DAEMON=ON
      

    You can find the generated applications in ./build/posix/src/posix/.

  4. Open up a terminal window, and start ot-daemon with the --verbose flag so you can see log output and confirm that it is running:

    sudo ./build/posix/src/posix/ot-daemon 'spinel+hdlc+uart:///dev/cu.usbmodem14201?uart-baudrate=115200' --verbose
    

    When successful, ot-daemon in verbose mode generates output similar to the following:

    2
    3
    4
    5
    Feb 10 16:51:15  ./build/posix/src/posix/ot-daemon[56466] <Info>: Running OPENTHREAD/632b63089; POSIX; Feb 10 2023 16:31:19
    Feb 10 16:51:15  ./build/posix/src/posix/ot-daemon[56466] <Info>: Thread version: 3
    Feb 10 16:51:15  ./build/posix/src/posix/ot-daemon[56466] <Info>: Thread interface: utun4
    Feb 10 16:51:15  ./build/posix/src/posix/ot-daemon[56466] <Info>: RCP version: OPENTHREAD/632b63089; Zephyr; Feb 10 2023 16:50:38
    
  5. Open up a second terminal window and use ot-ctl to communicate with the RCP node, specifying the Thread interface utun4 shown in ot-daemon log output:

    sudo ./build/posix/src/posix/ot-ctl -I utun4
    
  6. From this point, you can follow the Testing instructions in the CLI sample by removing the ot prefix for each command. For example:

    > state
    state
    disabled
    Done
    > channel
    channel
    11
    Done
    > panid 0xabcd
    panid 0xabcd
    Done
    ...