Skip to main content

Set up Nordic nRF Connect SDK (NCS)

Nordic Semiconductor devices require the nRF Connect SDK (NCS). This is a fork of the Zephyr project that Nordic Semiconductor maintains and includes some distinct features and IP. For instance, NCS includes the firmware for the cellular modem on the nRF9160, which is unavailable in the upstream Zephyr project.

This section will guide you through installing NCS and the Zephyr tree (including the Golioth SDK) in a directory called golioth-ncs-workspace.

Install Dependencies and West

Install Dependencies

  1. Install dependencies with apt:

    sudo apt update
    sudo apt install --no-install-recommends git cmake ninja-build gperf \
    ccache dfu-util device-tree-compiler wget python3-dev python3-pip \
    python3-setuptools python3-tk python3-venv python3-wheel xz-utils file \
    make gcc gcc-multilib g++-multilib libsdl2-dev
  2. West requires CMake version 3.20.0 or higher. Check the version that your package manager installed:

    $ cmake --version
    cmake version 3.16.3

    If you have an older version, Ubuntu 20.04 systems can add the Kitware repository which maintains the newest release:

    wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
    sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
    sudo apt update
    sudo apt install cmake
    cmake --version

    If the Kitware repository doesn't work for you (ie: your system is not running Ubuntu 20.04), you can build the stable version of CMake from source.

Install West

We recommend creating a python3 virtual environment to avoid running into tooling incompatibilities.

  1. Create your workspace directory:

    mkdir ~/golioth-ncs-workspace
  2. Use pip3 to install west (beginning with the wheel dependency):

    pip3 install wheel
    pip3 install west

Installing the Golioth Firmware SDK for NCS

  1. With west installed, grab the Golioth NCS SDK:

    cd ~
    west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.16.0 --mf west-ncs.yml ~/golioth-ncs-workspace
    cd golioth-ncs-workspace/modules/lib/golioth-firmware-sdk
    git submodule update --init --recursive
    west update
  2. Tell west to automatically configure CMake:

    west zephyr-export
  3. Lastly, install the remaining dependencies:

    pip3 install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txt

Installing the Zephyr SDK Toolchain

Nordic chips are ARM-based device, so we will use the ARM toolchains (gcc, gdb, etc) included in the Zephyr SDK

Download the latest SDK installer:

cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/zephyr-sdk-0.16.4_linux-x86_64.tar.xz

Unpack the archive and run the installer. The SDK will be placed in the ~/zephyr-sdk-0.16.4 directory:

tar -xvf zephyr-sdk-0.16.4_linux-x86_64.tar.xz
cd zephyr-sdk-0.16.4
./setup.sh

Answer y to both of the questions asked during the setup process.

Install udev rules, which allow you to flash most Zephyr boards as a regular user:

sudo cp ~/zephyr-sdk-0.16.4/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload

Zephyr uses nrfjprog to flash Nordic targets using a hardware programmer like the Segger J-Link, or the debugger that is built into the development kit (DK) boards. This tool is part of the nRF Command Line Tools which we will install along with the Segger tool.

  1. Go to Segger and download the latest J-Link Software and Documentation Pack

  2. Run the J-Link installer

    sudo dpkg -i JLink_Linux_V760f_x86_64.deb
  3. Go to the nRF Command Line Tools page. Scroll down, select your operating system, and download the installer package.

  4. Run the nRF Command Line Tools installer

    sudo dpkg -i nrf-command-line-tools_10.15.2_amd64.deb

Build Sample Firmware

Build firmware

Your system is all set up and ready to start building & flashing with Zephyr. Verify by building a minimal sample from the Zephyr tree. Here we are using the nRF9160 DK as an example:

cd ~/golioth-ncs-workspace/zephyr
west build -p auto -b nrf9160dk/nrf9160/ns samples/basic/minimal

Flash firmware to the device

Most boards supported by Zephyr can by flashed using a simple command:

west flash