Developing Zephyr BSP and Application Using Nordic Cross Tools (based on nRF Connect SDK 2.5.1)

 

1. Overview

This note describes how to set up and use the Nordic cross-development environment for development and debugging of the Zephyr BSP and a user application running on the Emcraft Thingy-9151-Lite platform.

2. Setting Up Cross Development Host

2.1. Setting Up Hardware Links to Emcraft Thingy-9151-Lite Platform

The emulated hardware platform is used for for early software development, while the Emcraft Thingy-9151-Lite hardware kit is not available yet. The emulated platform is based on the existing nRF9161 and nRF5340 development kits.

This note describes how to set up the emulated hardware platform.

2.1.1. Setting Up Hardware of Emulated Platform

Step through the following procedure in order to set up the emulated platform hardware:

  • Connect a USB Type-C cable to the J6 connector on the nRF9161 DK to the Linux host to get access to the on-board programmer and serial console.

  • Connect a Micro-USB cable to the J2 connector on the nRF5340 DK, and to the Linux host to get access to the on-board programmer and the VCOM based serial consoles.

  • Connect a Micro-USB cable to the J3 connector on the nRF5340 DK, and to the Linux host to get access to the USB based serial consoles.

2.1.2. Setting Up Thingy-9151-Lite Platform

TBD

2.2. 2.1 Setting Up Software on Cross Development Host

2.2.1. Installing the nRF Connect SDK

Emcraft maintains the fork of the nRF Connect SDK on GitHub:

https://github.com/voxelbotics/sdk-nrf

Set up the nRF Connect SDK on a Linux PC as described in the Nordic documentation for the corresponding version. The instruction for v2.5.1 nRF Connect SDK can be found here:

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.1/nrf/installation/installing.html

Follow the Nordic instructions, but replace the west init... command in step 4 with the one below to use the Emcraft repositories:

west init -m https://github.com/voxelbotics/sdk-nrf --mr voxelbotics-v2.5.1-branch

2.2.2. Getting the Source Code of the Thingy-9151-Lite Application

The Thingy-9151-Lite Zephyr application is maintained in the separate GitHub repository:

https://github.com/voxelbotics/nrf-app

Just clone it in the same directory where west was initialized:

git clone git@github.com:voxelbotics/nrf-app -b main

The current branch and release tag are specified in the Release Notes document.

3. Developing Zephyr BSP and Application

3.1. Developing on nRF9151

3.1.1. Building Thingy-9151-Lite Application for nRF9151/nRF9161 from command line

Go to the application directory:

cd nrf-app/thingy9151lite_nrf9151_app/

The boards subdirectory contains the configurations of the supported boards. The Nordic nRF9161 DK board is already supported in Zephyr, so it is configured using the devicetree overlay:

Build the application for nRF9161 DK using the following command:

The resulting image is build/zephyr/merged.hex.

3.2. Developing on Application Core of nRF5340

3.2.1. Building Thingy-9151-Lite Application for nRF5340 (application core) from command line

Go to the application directory:

The boards subdirectory contains the configurations of the supported boards. The Nordic nRF5340 DK board is already supported in Zephyr, so it is configured using the devicetree overlay:

 

Build the application for nRF5340 DK using the following command:

The resulting image is build/zephyr/merged.hex.

3.3. Developing on Network Core of nRF5340

3.3.1. Building Thingy-9151-Lite Application for nRF5340 DK (network core)

Go to the application directory:

The boards subdirectory contains the configurations of the supported boards. The Nordic nRF5340 DK board is already supported in Zephyr, so it is configured using the devicetree overlay:

Build the application for nRF5340 DK using the following command:

The resulting image is build/zephyr/zephyr.hex.

4. Using VSCode to build and debug applications

4.1.1. Adding custom boards from the Thingy-9151-Lite into the VSCode

In order for nRF Connect plugin to recognize custom board configurations that come along with nrf-app, add it to the BOARD_ROOT setting of the plugin. For this start VSCode, navigate to File -> Preferences -> Settings -> Extensions -> nRF Connect -> Board Roots, then add the directory where nrf-app repository was cloned:<west_init>/nrf-app/.

 

configure_board_roots1_marked.png
Setting board roots

Sometimes changing BOARD_ROOT is not enough and nRF Connect plugin refuses to show boards from <west_init>/nrf-app/boards as valid configuration targets. To work around this, create fake board skeleton using nRF plugin in the same directory: activate nRF plugin, select 'Create a new board', supply some board name, accept suggested build board name, select any nRF device, specify full path to the <west_init>/nrf-app/ and finally enter something as company name. After this nRF Connect plugin creates skeleton for the new board in the target path. This board definition will never be used, it is only needed to force nRF Connect plugin to scan the <west_init>/nrf-app/boards for custom board definitions. This steps should only be needed once per workspace.

4.1.2. Importing the Thingy-9151-Lite Applications into the VSCode

To import the application(s), activate nRF Connect plugin, select ‘Open an existing application', navigate to wanted application (e.g. <west_init>/nrf-app/thingy9151lite_nrf9151_app), press 'Open'

 

nrfconnect_plugin_openapp.png
Button to start nRF Connect plugin and menu to open existing application highlighted

It is possible to open several applications into the same workspace.

4.1.3. Building the Thingy-9151-Lite Applications in the VSCode

Start VSCode with workspace where one or more Thingy-9151-Lite Applications are already imported, activate nRF Connect plugin.

If build configuration for the application does not exist yet (no build folder in the ‘Application’ window of nRF Connect plugin), create one by selecting ‘Add build configuration', selecting 'Custom board’ than target board name:

 

Application

Default board target name

SoC

Application

Default board target name

SoC

thingy9151lite_nrf9151_app

thingy9151lite_nrf9161_ns

nRF9161

thingy9151lite_nrf5340_cpuapp_app

thingy9151lite_nrf5340_cpuapp_ns

nRF5340 (application core)

thingy9151lite_nrf5340_cpunet_app

thingy9151lite_nrf5340_cpunet_ns

nRF5340 (network core)

Select build configuration, use ‘Build' in the 'Actions’ window of the nRF Connect plugin.

 

4.1.4. Debugging in VSCode

Follow Nordic instructions on debugging in VSCode.

 

 

In case manual installation was followed and west complains about missing Python dependencies when trying to install firmware on board, use the following tricks:

  • activate Python virtual environment by running <venv dir>\Scripts\activate.bat

  • activate Zephyr environment by running <west_init>\zephyr\zephyr-env.cmd

  • start VSCode

To avoid repeating this steps create cmd.exe script that will setup environment and launch VSCode and create desktop icon for it.