Set up Zephyr for nRF9160
Zephyr Setup Overview
Golioth is implemented on IoT devices using Device SDKs. These are based on different embedded Real Time Operating Systems (RTOS). Currently Golioth targets the Zephyr Project and builds upon the APIs & tools of Zephyr. As such, prior experience with Zephyr will be helpful when working with Golioth's Zephyr Device SDK. Refer to Zephyr's detailed documentation when running into issues.
The nRF9160 Feather and all Nordic Semiconductor devices utilizing Zephyr require the nRF Connect SDK (NCS). Nordic Semiconductor maintains a fork of the Zephyr project that includes some distinct features and IP, including the firmware for the cellular modem on the nRF9160. We will install the nRF Connect SDK in a directory in your home location separate from other Zephyr projects shown for Golioth (in a directory called golioth-ncs-workspace
)
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.
Choose your OS from the tabs below
- Linux
- MacOS
- Windows
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-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev
We recommend creating a python3
virtual environment to avoid running into
tooling incompatibilities.
- Install within a virtualenv
- Install globally
Create a new version 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-zephyr-workspace/.venv
Activate the virtual environment:
source ~/golioth-zephyr-workspace/.venv/bin/activate
# OR, if you're using the fish shell, run
source ~/golioth-zephyr-workspace/.venv/bin/activate.fish
Whenever 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
.
Anytime you need to use west or Zephyr, remember to re-activate the virtual environment.
Now, use pip
to install west
(beginning with the wheel
dependency):
Because we're in a python3
virtualenv
, we don't need to specify pip3
and can just use pip
(because virtual env knows the best version to use)
pip install wheel
pip install west
Use pip3
to install west
(beginning with the wheel
dependency):
pip3 install wheel
pip3 install west
Start by installing dependencies with brew
:
brew install cmake ninja gperf python3 ccache qemu dtc
We recommend creating a python3
virtual environment to avoid running into
tooling incompatibilities.
- Install within a virtualenv
- Install globally
Create a new version 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-zephyr-workspace/.venv
Activate the virtual environment:
source ~/golioth-zephyr-workspace/.venv/bin/activate
# OR, if you're using the fish shell, run
source ~/golioth-zephyr-workspace/.venv/bin/activate.fish
Whenever 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
.
Anytime you need to use west or Zephyr, remember to re-activate the virtual environment.
Now, use pip
to install west
(beginning with the wheel
dependency):
Because we're in a python3
virtualenv
, we don't need to specify pip3
and can just use pip
(because virtual env knows the best version to use)
pip install wheel
pip install west
Use pip3
to install west
(beginning with the wheel
dependency):
pip3 install wheel
pip3 install west
The nRF Connect For Desktop installer includes a Toolchain Manager section that handles many of the same functions described in the Ubuntu tab. This can be used in conjunction with the VS Code extension for nRF Connect SDK (NCS). This is the recommended path for Windows users with the nRF9160.
Using the VS Code extension in conjuction with the nRF Connect for Desktop tools may move you outside many of the other recommended methods of compiling your firmware, described on this docs page and elsewhere on Golioth. If you're having problems with your Windows install, please contact us on our Community Discord
Installing the NRF Connect SDK
These directions are mirroring the Zephyr and Python dependency install instructions. Some directions may be slightly modified to fit your nRF91 / Golioth install.
With west
installed, grab the Golioth NCS SDK:
cd ~
west init -m https://github.com/golioth/golioth-zephyr-sdk.git --mf west-ncs.yml ~/golioth-ncs-workspace
cd golioth-ncs-workspace
west update
Tell west
to 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.txt
pip3 install -r ~/golioth-ncs-workspace/zephyr/scripts/requirements.txt
Installing the Zephyr SDK Toolchain
The nRF9160 is an ARM based device, so we will use the ARM toolchains (gcc, gdb, etc) included in the Zephyr SDK
Download the latest SDK installer:
- Linux
- MacOS
- Windows
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz
Unpack the archive and run the installer. The SDK will be placed in the ~/zephyr-sdk-0.15.2
directory:
tar -xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz
cd zephyr-sdk-0.15.2
./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.15.2/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_macos-x86_64.tar.gz
Unpack the archive and run the installer. The SDK will be placed in the ~/zephyr-sdk-0.15.2
directory:
tar -xvf zephyr-sdk-0.15.2_macos-x86_64.tar.gz
cd zephyr-sdk-0.15.2
./setup.sh
Unpack the archive and run the installer. The SDK will be placed in the %HOMEPATH%\zephyr-sdk-0.15.2
directory:
cd %HOMEPATH%
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_windows-x86_64.zip
unzip zephyr-sdk-0.15.2_windows-x86_64.zip
cd zephyr-sdk-0.15.2
setup.cmd
Answer y
to both of the questions asked during the setup process.
Build firmware for the nRF9160
Your system is all set up and ready to start building & flashing with Zephyr. Verify by building a minimal sample for the nRF9160 DK:
cd ~/golioth-ncs-workspace/zephyr
west build -p auto -b nrf9160dk_nrf9160_ns samples/basic/minimal
Flash firmware to the device
If you are using a J-Link hardware programmer and already have the software for that tool set up on your system, flashing firmware is as simple as running:
west flash
The nRF9160 DK acts as a J-Link hardware programmer. west
will automatically work with J-Link as long as the supporting software is installed on your system. The next section will walk through installing that software.