Getting Started Guide

Follow this guide to:

  • Set up a command-line Zephyr development environment on Ubuntu, macOS, or Windows (instructions for other Linux distributions are discussed in Install Linux Host Dependencies)

  • Get the source code

  • Build, flash, and run a sample application

Select and Update OS

Click the operating system you are using.

This guide covers Ubuntu version 18.04 LTS and later.

sudo apt update
sudo apt upgrade

On macOS Mojave or later, select System Preferences > Software Update. Click Update Now if necessary.

On other versions, see this Apple support topic.

Select Start > Settings > Update & Security > Windows Update. Click Check for updates and install any that are available.

Install dependencies

Next, you’ll install some host dependencies using your package manager.

  1. Use apt to install dependencies:

    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
    
  2. Verify the version of cmake installed on your system using:

    cmake --version
    

    If it’s not version 3.13.1 or higher, follow these steps to add the Kitware third-party apt repository to get an updated version of cmake.

    1. Add the Kitware signing key:

      wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
      
    2. Add the Kitware apt repository for your OS release. For Ubuntu 18.04 LTS:

      sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
      
    3. Then install the updated cmake with apt:

      sudo apt update
      sudo apt install cmake
      
  1. Install Homebrew:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. Use brew to install dependencies:

    brew install cmake ninja gperf python3 ccache qemu dtc
    

Note

Due to issues finding executables, the Zephyr Project doesn’t currently support application flashing using the Windows Subsystem for Linux (WSL) (WSL).

Therefore, we don’t recommend using WSL when getting started.

These instructions must be run in a cmd.exe command prompt. The required commands differ on PowerShell.

These instructions rely on Chocolatey. If Chocolatey isn’t an option, you can install dependencies from their respective websites and ensure the command line tools are on your PATH environment variable.

  1. Install chocolatey

  2. Open an Administrator cmd.exe window: press the Windows key, type “cmd.exe”, right-click the result, and choose “Run as Administrator”.

  3. Disable global confirmation to avoid having to confirm installation of individual programs:

    choco feature enable -n allowGlobalConfirmation
    
  4. Use choco to install dependencies:

    choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
    choco install ninja gperf python git
    
  5. Open a new cmd.exe window as a regular user to continue.

Get Zephyr and install Python dependencies

Next, clone Zephyr and its modules into a new west workspace named zephyrproject. You’ll also install Zephyr’s additional Python dependencies.

  1. Install west, and make sure ~/.local/bin is on your PATH environment variable:

    pip3 install --user -U west
    echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
    source ~/.bashrc
    
  2. Get the Zephyr source code:

    west init ~/zephyrproject
    cd ~/zephyrproject
    west update
    
  3. Export a Zephyr CMake package. This allows CMake to automatically load boilerplate code required for building Zephyr applications.

    west zephyr-export
    
  4. Zephyr’s scripts/requirements.txt file declares additional Python dependencies. Install them with pip3.

    pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
    
  1. Install west:

    pip3 install west
    
  2. Get the Zephyr source code:

    west init ~/zephyrproject
    cd ~/zephyrproject
    west update
    
  3. Export a Zephyr CMake package. This allows CMake to automatically load boilerplate code required for building Zephyr applications.

    west zephyr-export
    
  4. Zephyr’s scripts/requirements.txt file declares additional Python dependencies. Install them with pip3.

    pip3 install -r ~/zephyrproject/zephyr/scripts/requirements.txt
    
  1. Install west:

    pip3 install west
    
  2. Get the Zephyr source code:

    cd %HOMEPATH%
    west init zephyrproject
    cd zephyrproject
    west update
    
  3. Export a Zephyr CMake package. This allows CMake to automatically load boilerplate code required for building Zephyr applications.

    west zephyr-export
    
  4. Zephyr’s scripts/requirements.txt file declares additional Python dependencies. Install them with pip3.

    pip3 install -r %HOMEPATH%\zephyrproject\zephyr\scripts\requirements.txt
    

Install a Toolchain

A toolchain provides a compiler, assembler, linker, and other programs required to build Zephyr applications.

The Zephyr Software Development Kit (SDK) contains toolchains for each of Zephyr’s supported architectures. It also includes additional host tools, such as custom QEMU binaries and a host compiler.

  1. Download the latest SDK installer:

    cd ~
    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.4/zephyr-sdk-0.11.4-setup.run
    
  2. Run the installer, installing the SDK in ~/zephyr-sdk-0.11.4:

    chmod +x zephyr-sdk-0.11.4-setup.run
    ./zephyr-sdk-0.11.4-setup.run -- -d ~/zephyr-sdk-0.11.4
    

    Note

    It is recommended to install the Zephyr SDK at one of the following locations:

    • $HOME/zephyr-sdk[-x.y.z]

    • $HOME/.local/zephyr-sdk[-x.y.z]

    • $HOME/.local/opt/zephyr-sdk[-x.y.z]

    • $HOME/bin/zephyr-sdk[-x.y.z]

    • /opt/zephyr-sdk[-x.y.z]

    • /usr/zephyr-sdk[-x.y.z]

    • /usr/local/zephyr-sdk[-x.y.z]

    where [-x.y.z] is optional text, and can be any text, for example -0.11.4.

    If installing the Zephyr SDK outside any of those locations, please read: Install the Zephyr Software Development Kit (SDK)

    You cannot move the SDK directory after you have installed it.

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

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

Follow the instructions in Set Up a Toolchain. Note that the Zephyr SDK is not available on macOS.

Do not forget to set the required environment variables (ZEPHYR_TOOLCHAIN_VARIANT and toolchain specific ones).

Follow the instructions in Set Up a Toolchain. Note that the Zephyr SDK is not available on Windows.

Do not forget to set the required environment variables (ZEPHYR_TOOLCHAIN_VARIANT and toolchain specific ones).

Build the Blinky Sample

Note

Blinky is compatible with most, but not all, Supported Boards. If your board does not meet Blinky’s Requirements, then Hello World is a good alternative.

Build the Blinky with west build, changing <your-board-name> appropriately for your board:

cd ~/zephyrproject/zephyr
west build -p auto -b <your-board-name> samples/basic/blinky
cd ~/zephyrproject/zephyr
west build -p auto -b <your-board-name> samples/basic/blinky
cd %HOMEPATH%\zephyrproject\zephyr
west build -p auto -b <your-board-name> samples\basic\blinky

The -p auto option automatically cleans byproducts from a previous build if necessary, which is useful if you try building another sample.

Flash the Sample

Connect your board, usually via USB, and turn it on if there’s a power switch. If in doubt about what to do, check your board’s page in Supported Boards.

Then flash the sample using west flash:

west flash

You may need to install additional host tools required by your board. The west flash command will print an error if any required dependencies are missing.

If you’re using blinky, the LED will start to blink as shown in this figure:

../_images/ReelBoard-Blinky.gif

Phytec reel_board running blinky

Next Steps

Here are some next steps for exploring Zephyr: