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
- Linux
- MacOS
- Windows
-
Install dependencies with
apt:sudo apt updatesudo 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 libmagic1 -
Zephyr supports Ubuntu 22.04 LTS and later and needs at least CMake 3.20.5, Python 3.10 and devicetree compiler 1.4.6. Check the installed versions:
cmake --versionpython3 --versiondtc --versionIf any of them is older, see Zephyr's dependency instructions.
Install West
We recommend creating a python3 virtual environment to avoid running into
tooling incompatibilities.
- Install within a virtualenv
- Install globally
-
Create your workspace directory:
mkdir ~/golioth-ncs-workspace -
Create a new virtual environment:
Even though we haven't pulled down Zephyr yet, we can create the virtual environment in the place where we will pull down Zephyr.
python3 -m venv ~/golioth-ncs-workspace/.venv -
Activate the virtual environment:
source ~/golioth-ncs-workspace/.venv/bin/activateWhenever the virtual environment is active, your shell's prompt will be prefixed with
(.venv).Deactivate the virtual environment when you're done by running
deactivate.noteAnytime you need to use west or Zephyr, remember to re-activate the virtual environment.
-
Now, use
pipto installwest(beginning with thewheeldependency):Because we're in a
python3virtualenv, we don't need to specifypip3and can just usepip(because virtual env knows the best version to use)pip install wheelpip install west
Recent distributions, such as Ubuntu 23.04 and later, and Homebrew's Python
refuse system-wide pip installs (PEP 668). Use the virtualenv tab there.
-
Create your workspace directory:
mkdir ~/golioth-ncs-workspace -
Use
pip3to installwest(beginning with thewheeldependency):pip3 install wheelpip3 install west
-
Start by installing dependencies with
brew:brew install cmake ninja gperf python3 python-tk ccache dtc libmagic wget
Install West
We recommend creating a python3 virtual environment to avoid running into
tooling incompatibilities.
- Install within a virtualenv
- Install globally
-
Create your workspace directory:
mkdir ~/golioth-ncs-workspace -
Create a new virtual environment:
Even though we haven't pulled down Zephyr yet, we can create the virtual environment in the place where we will pull down Zephyr.
python3 -m venv ~/golioth-ncs-workspace/.venv -
Activate the virtual environment:
source ~/golioth-ncs-workspace/.venv/bin/activateWhenever the virtual environment is active, your shell's prompt will be prefixed with
(.venv).Deactivate the virtual environment when you're done by running
deactivate.noteAnytime you need to use west or Zephyr, remember to re-activate the virtual environment.
-
Now, use
pipto installwest(beginning with thewheeldependency):Because we're in a
python3virtualenv, we don't need to specifypip3and can just usepip(because virtual env knows the best version to use)pip install wheelpip install west
Recent distributions, such as Ubuntu 23.04 and later, and Homebrew's Python
refuse system-wide pip installs (PEP 668). Use the virtualenv tab there.
-
Create your workspace directory:
mkdir ~/golioth-ncs-workspace -
Use
pip3to installwest(beginning with thewheeldependency):pip3 install wheelpip3 install west
Package Manager: Chocolatey
The chocolatey package manager needs to be installed
to fetch software packages required by Zephyr. These instructions must be run in
a cmd.exe command prompt. The required commands differ on PowerShell.
-
Open an Administrator
cmd.exewindow:- press the Windows key
- type
cmd.exe - right-click the result, and choose
Run as Administrator
-
Disable global confirmation to avoid having to confirm the installation of individual programs:
choco feature enable -n allowGlobalConfirmation -
Use
chocoto install the required dependencies:choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'choco install ninja gperf python git dtc-msys2 wget 7zip -
Close the window and open a new
cmd.exewindow as a regular user to continue
Install West
west is the Zephyr "meta tool" that will allow you to build firmware, install
packages, and flash firmware. There are various dependencies required, depending
upon your operating system (OS), because west is Python based.
- Install within a virtualenv
- Install globally
-
Create your workspace directory:
cd %HOMEPATH%mkdir golioth-ncs-workspace -
Create a new virtual environment:
cd %HOMEPATH%python -m venv golioth-ncs-workspace\.venv -
Activate the virtual environment:
## cmd.exegolioth-ncs-workspace\.venv\Scripts\activate.bat## PowerShellgolioth-ncs-workspace\.venv\Scripts\Activate.ps1Once activated your shell will be prefixed with
(.venv). The virtual environment can be deactivated at any time by runningdeactivate.noteRemember to activate the virtual environment whenever you need to use the
westcommand. -
Install west:
Now, use
pipto installwest.pip install west
-
Create your workspace directory:
cd %HOMEPATH%mkdir golioth-ncs-workspace -
Use
pipto installwest:pip install -U west
Install the Golioth Firmware SDK for NCS
- Linux
- MacOS
- Windows
-
With
westinstalled, grab the Golioth NCS SDK:cd ~west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.23.0 --mf west-ncs.yml ~/golioth-ncs-workspacecd golioth-ncs-workspace/modules/lib/golioth-firmware-sdkgit submodule update --init --recursivewest update -
Tell
westto automatically configure CMake:west zephyr-export -
Lastly, install the remaining dependencies:
- Install within a virtualenv
- Install globally
pip install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip install -r ~/golioth-ncs-workspace/nrf/scripts/requirements.txtpip install -r ~/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/nrf/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txt
-
With
westinstalled, grab the Golioth NCS SDK:cd ~west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.23.0 --mf west-ncs.yml ~/golioth-ncs-workspacecd golioth-ncs-workspace/modules/lib/golioth-firmware-sdkgit submodule update --init --recursivewest update -
Tell
westto automatically configure CMake:west zephyr-export -
Lastly, install the remaining dependencies:
- Install within a virtualenv
- Install globally
pip install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip install -r ~/golioth-ncs-workspace/nrf/scripts/requirements.txtpip install -r ~/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/nrf/scripts/requirements.txtpip3 install -r ~/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txt
-
With
westinstalled, grab the Golioth NCS SDK:cd %HOMEPATH%west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.23.0 --mf west-ncs.yml %HOMEPATH%/golioth-ncs-workspacecd golioth-ncs-workspace/modules/lib/golioth-firmware-sdkgit submodule update --init --recursivewest update -
Tell
westto automatically configure CMake:west zephyr-export -
Lastly, install the remaining dependencies:
- Install within a virtualenv
- Install globally
pip install -r %HOMEPATH%/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip install -r %HOMEPATH%/golioth-ncs-workspace/nrf/scripts/requirements.txtpip install -r %HOMEPATH%/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txtpip3 install -r %HOMEPATH%/golioth-ncs-workspace/zephyr/scripts/requirements.txtpip3 install -r %HOMEPATH%/golioth-ncs-workspace/nrf/scripts/requirements.txtpip3 install -r %HOMEPATH%/golioth-ncs-workspace/bootloader/mcuboot/scripts/requirements.txt
Install 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 Zephyr SDK 0.17.4 from the SDK releases:
- Linux
- MacOS
- Windows
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/zephyr-sdk-0.17.4_linux-x86_64.tar.xz
Unpack the archive and run the installer. The SDK will be placed in the ~/zephyr-sdk-0.17.4 directory:
tar -xvf zephyr-sdk-0.17.4_linux-x86_64.tar.xz
cd zephyr-sdk-0.17.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.17.4/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
On Apple Silicon Macs, replace macos-x86_64 with macos-aarch64 in the
commands below.
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/zephyr-sdk-0.17.4_macos-x86_64.tar.xz
Unpack the archive and run the installer. The SDK will be placed in the ~/zephyr-sdk-0.17.4 directory:
tar xvf zephyr-sdk-0.17.4_macos-x86_64.tar.xz
cd zephyr-sdk-0.17.4
./setup.sh
Unpack the archive and run the installer. The SDK will be placed in the %HOMEPATH%\zephyr-sdk-0.17.4 directory:
cd %HOMEPATH%
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/zephyr-sdk-0.17.4_windows-x86_64.7z
7z x zephyr-sdk-0.17.4_windows-x86_64.7z
cd zephyr-sdk-0.17.4
setup.cmd
Answer y to both of the questions asked during the setup process.
Install the SEGGER J-Link software and nRF Util
west flash programs Nordic targets with nRF Util (nrfutil device), using the
SEGGER J-Link debugger that is built into the development kit (DK) boards.
-
Go to SEGGER and download the J-Link Software and Documentation Pack. NCS v3.2.3 requires J-Link v9.18.
-
Install J-Link: on macOS and Windows, run the downloaded installer; on Debian and Ubuntu, install the downloaded package:
sudo dpkg -i JLink_Linux_<version>_x86_64.deb -
Download nRF Util, make it executable and move it to a directory that is in your
PATH:chmod +x nrfutil -
Install the nRF Util device command
nrfutil install device -
On Linux, install Nordic's udev rules which are required to access the USB ports of Nordic devices.
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:
- Linux
- MacOS
- Windows
cd ~/golioth-ncs-workspace/zephyr
west build -p auto -b nrf9160dk/nrf9160/ns samples/basic/minimal
cd ~/golioth-ncs-workspace/zephyr
west build -p auto -b nrf9160dk/nrf9160/ns samples/basic/minimal
cd %HOMEPATH%\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