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 20.04 LTS and later. If you are using a different Linux distribution see Install Linux Host Dependencies.

sudo apt update
sudo apt upgrade

Install dependencies

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

The current minimum required version for the main dependencies are:

Tool

Min. Version

CMake

3.20.5

Python

3.10

Devicetree compiler

1.4.6

  1. If using an Ubuntu version older than 22.04, it is necessary to add extra repositories to meet the minimum required versions for the main dependencies listed above. In that case, download, inspect and execute the Kitware archive script to add the Kitware APT repository to your sources list. A detailed explanation of kitware-archive.sh can be found here kitware third-party apt repository:

    wget https://apt.kitware.com/kitware-archive.sh
    sudo bash kitware-archive.sh
    
  2. Use apt to install the required 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 libmagic1
    
  3. Verify the versions of the main dependencies installed on your system by entering:

    cmake --version
    python3 --version
    dtc --version
    

    Check those against the versions in the table in the beginning of this section. Refer to the Install Linux Host Dependencies page for additional information on updating the dependencies manually.

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 in a Python virtual environment.

  1. Use apt to install Python venv package:

    sudo apt install python3-venv
    
  2. Create a new virtual environment:

    python3 -m venv ~/zephyrproject/.venv
    
  3. Activate the virtual environment:

    source ~/zephyrproject/.venv/bin/activate
    

    Once activated your shell will be prefixed with (.venv). The virtual environment can be deactivated at any time by running deactivate.

    Note

    Remember to activate the virtual environment every time you start working.

  4. Install west:

    pip install west
    
  5. Get the Zephyr source code:

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

    west zephyr-export
    
  7. The Zephyr west extension command, west packages can be used to install Python dependencies.

    west packages pip --install
    

Install the Zephyr SDK

The Zephyr Software Development Kit (SDK) contains toolchains for each of Zephyr’s supported architectures, which include a compiler, assembler, linker and other programs required to build Zephyr applications.

For Linux, it also contains additional host tools, such as custom QEMU and OpenOCD builds that are used to emulate, flash and debug Zephyr applications.

Install the Zephyr SDK using the west sdk install.

cd ~/zephyrproject/zephyr
west sdk install

Tip

Using the command options, you can specify the SDK installation destination and which architecture of toolchains to install. See west sdk install --help for details.

Note

If you want to install Zephyr SDK without using the west sdk command, please see Zephyr SDK installation.

Build the Blinky Sample

Note

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

If you are unsure what name west uses for your board, west boards can be used to obtain a list of all boards Zephyr supports.

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

cd ~/zephyrproject/zephyr
west build -p always -b <your-board-name> samples/basic/blinky

The -p always option forces a pristine build, and is recommended for new users. Users may also use the -p auto option, which will use heuristics to determine if a pristine build is required, such as when building another sample.

Note

A board may contain one or multiple SoCs, Also, each SoC may contain one or more CPU clusters. When building for such boards it is necessary to specify the SoC or CPU cluster for which the sample must be built. For example to build Blinky for the cpuapp core on the nRF5340DK the board must be provided as: nrf5340dk/nrf5340/cpuapp. See also Board terminology for more details.

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 and Shields.

Then flash the sample using west flash:

west flash

Note

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.

Note

When using Linux, you may need to configure udev rules the first time of using a debug probe. Please also see Setting udev rules.

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

../../_images/ReelBoard-Blinky.png

Phytec reel_board running blinky

Next Steps

Here are some next steps for exploring Zephyr:

Troubleshooting Installation

Here are some tips for fixing some issues related to the installation process.

Double Check the Zephyr SDK Variables When Updating

When updating Zephyr SDK, check whether the ZEPHYR_TOOLCHAIN_VARIANT or ZEPHYR_SDK_INSTALL_DIR environment variables are already set. See Updating the Zephyr SDK toolchain for more information.

For more information about these environment variables in Zephyr, see Important Environment Variables.

Asking for Help

You can ask for help on a mailing list or on Discord. Please send bug reports and feature requests to GitHub.

How to Ask

Important

Please search this documentation and the mailing list archives first. Your question may have an answer there.

Don’t just say “this isn’t working” or ask “is this working?”. Include as much detail as you can about:

  1. What you want to do

  2. What you tried (commands you typed, etc.)

  3. What happened (output of each command, etc.)

Use Copy/Paste

Please copy/paste text instead of taking a picture or a screenshot of it. Text includes source code, terminal commands, and their output.

Doing this makes it easier for people to help you, and also helps other users search the archives. Unnecessary screenshots exclude vision impaired developers; some are major Zephyr contributors. Accessibility has been recognized as a basic human right by the United Nations.

When copy/pasting more than 5 lines of computer text into Discord or Github, create a snippet using three backticks to delimit the snippet.