Skip to main content

Set up Zephyr RTOS

Zephyr RTOS supports a vast number of microcontrollers from many different vendors. There's a very good chance your preferred chip will work with Zephyr using Golioth as a module.

This section will guide you through installing the Zephyr tree (including the Golioth SDK) in a directory called golioth-zephyr-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 libmagic1
  2. 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 --version
    python3 --version
    dtc --version

    If 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.

  1. Create your workspace directory:

    mkdir ~/golioth-zephyr-workspace
  2. 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-zephyr-workspace/.venv
  3. Activate the virtual environment:

    source ~/golioth-zephyr-workspace/.venv/bin/activate

    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.

    note

    Anytime you need to use west or Zephyr, remember to re-activate the virtual environment.

  4. 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

Install Golioth Firmware SDK​

  1. With west installed, download Zephyr and the Golioth Firmware SDK:

    cd ~
    west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.23.0 --mf west-zephyr.yml ~/golioth-zephyr-workspace
    cd golioth-zephyr-workspace/modules/lib/golioth-firmware-sdk
    git submodule update --init --recursive
    west update
    info

    Depending on your internet and I/O speed, west update can take upwards of 5 or 10 minutes.

  2. Tell west to automatically configure CMake:

    west zephyr-export
  3. Install the remaining dependencies:

    west packages pip --install

Installing the Zephyr SDK Toolchain​

Download Zephyr SDK 0.17.4 from the SDK releases:

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

Install Device Specific Packages and Programming Tools​

Zephyr is a cross-vendor operating system and may require additional packages and tools based on your specific hardware.

Device Specific Examples:​

  • Espressif support in Zephyr requires binary blob installation:

    $ west blobs fetch hal_espressif

    Flashing Espressif boards needs esptool, which is installed by the west packages pip --install step above.

  • The NXP FRDM-RW612 WiFi build requires the NXP binary blobs:

    $ west blobs fetch hal_nxp
  • NXP evaluation kits usually offer on-board J-Link debugger support. To utilize this you will need to install Segger's J-Link Software and Documentation Pack.

    On the FRDM-RW612, west flash uses J-Link by default, which needs the on-board debug probe to run J-Link firmware (see Configuring a Debug Probe). If the probe runs NXP's CMSIS-DAP firmware instead, install LinkServer and flash with west flash -r linkserver.

Device-Specific information in Zephyr's Board Index

Review your vendor's board support in the Zephyr Board Index to find more information on specific set up steps for your prefered hardware.

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.

cd ~/golioth-zephyr-workspace/zephyr
west build -b your_board_name samples/basic/minimal -p
Show me how to list all Zephyr supported boards

If you don't know the name for your board, list all options using West:

west boards

Flash firmware to the device​

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

west flash