4️⃣Zephyr RTOS

https://www.zephyrproject.org/

Introduction

The Zephyr OS is based on a small-footprint kernel designed for use on resource-constrained and embedded systems: from simple embedded environmental sensors and LED wearables to sophisticated embedded controllers, smart watches, and IoT wireless applications.

The Zephyr kernel supports multiple architectures, including:

  • ARCv2 (EM and HS) and ARCv3 (HS6X)

  • ARMv6-M, ARMv7-M, and ARMv8-M (Cortex-M)

  • ARMv7-A and ARMv8-A (Cortex-A, 32- and 64-bit)

  • ARMv7-R, ARMv8-R (Cortex-R, 32- and 64-bit)

  • Intel x86 (32- and 64-bit)

  • MIPS (MIPS32 Release 1 specification)

  • NIOS II Gen 2

  • RISC-V (32- and 64-bit)

  • SPARC V8

  • Tensilica Xtensa

The full list of supported boards based on these architectures can be found here.

Licensing

Zephyr is permissively licensed using the Apache 2.0 license (as found in the LICENSE file in the project’s GitHub repo). There are some imported or reused components of the Zephyr project that use other licensing, as described in Licensing of Zephyr Project components.

Distinguishing Features

Zephyr offers a large and ever growing number of features including:

Extensive suite of Kernel services

Zephyr offers a number of familiar services for development:

  • Multi-threading Services for cooperative, priority-based, non-preemptive, and preemptive threads with optional round robin time-slicing. Includes POSIX pthreads compatible API support.

  • Interrupt Services for compile-time registration of interrupt handlers.

  • Memory Allocation Services for dynamic allocation and freeing of fixed-size or variable-size memory blocks.

  • Inter-thread Synchronization Services for binary semaphores, counting semaphores, and mutex semaphores.

  • Inter-thread Data Passing Services for basic message queues, enhanced message queues, and byte streams.

  • Power Management Services such as overarching, application or policy-defined, System Power Management and fine-grained, driver-defined, Device Power Management.

Multiple Scheduling Algorithms

Zephyr provides a comprehensive set of thread scheduling choices:

  • Cooperative and Preemptive Scheduling

  • Earliest Deadline First (EDF)

  • Meta IRQ scheduling implementing “interrupt bottom half” or “tasklet” behavior

  • Timeslicing: Enables time slicing between preemptible threads of equal priority

  • Multiple queuing strategies:

    • Simple linked-list ready queue

    • Red/black tree ready queue

    • Traditional multi-queue ready queue

Highly configurable / Modular for flexibility

Allows an application to incorporate only the capabilities it needs as it needs them, and to specify their quantity and size.

Cross Architecture

Supports a wide variety of supported boards with different CPU architectures and developer tools. Contributions have added support for an increasing number of SoCs, platforms, and drivers.

Memory Protection

Implements configurable architecture-specific stack-overflow protection, kernel object and device driver permission tracking, and thread isolation with thread-level memory protection on x86, ARC, and ARM architectures, userspace, and memory domains.

For platforms without MMU/MPU and memory constrained devices, supports combining application-specific code with a custom kernel to create a monolithic image that gets loaded and executed on a system’s hardware. Both the application code and kernel code execute in a single shared address space.

Compile-time resource definition

Allows system resources to be defined at compile-time, which reduces code size and increases performance for resource-limited systems.

Optimized Device Driver Model

Provides a consistent device model for configuring the drivers that are part of the platform/system and a consistent model for initializing all the drivers configured into the system and allows the reuse of drivers across platforms that have common devices/IP blocks.

Devicetree Support

Use of devicetree to describe hardware. Information from devicetree is used to create the application image.

Native Networking Stack supporting multiple protocols

Networking support is fully featured and optimized, including LwM2M and BSD sockets compatible support. OpenThread support (on Nordic chipsets) is also provided - a mesh network designed to securely and reliably connect hundreds of products around the home.

Bluetooth Low Energy 5.0 support

Bluetooth 5.0 compliant (ESR10) and Bluetooth Low Energy Controller support (LE Link Layer). Includes Bluetooth Mesh and a Bluetooth qualification-ready Bluetooth controller.

  • Generic Access Profile (GAP) with all possible LE roles

  • Generic Attribute Profile (GATT)

  • Pairing support, including the Secure Connections feature from Bluetooth 4.2

  • Clean HCI driver abstraction

  • Raw HCI interface to run Zephyr as a Controller instead of a full Host stack

  • Verified with multiple popular controllers

  • Highly configurable

Mesh Support:

  • Relay, Friend Node, Low-Power Node (LPN) and GATT Proxy features

  • Both Provisioning bearers supported (PB-ADV & PB-GATT)

  • Highly configurable, fitting in devices with at least 16k RAM

Native Linux, macOS, and Windows Development

A command-line CMake build environment runs on popular developer OS systems. A native port (native_sim) lets you build and run Zephyr as a native application on Linux, aiding development and testing.

Virtual File System Interface with ext2, FatFs, and LittleFS Support

ext2, LittleFS and FatFS support; FCB (Flash Circular Buffer) for memory constrained applications.

Powerful multi-backend logging Framework

Support for log filtering, object dumping, panic mode, multiple backends (memory, networking, filesystem, console, …) and integration with the shell subsystem.

User friendly and full-featured Shell interface

A multi-instance shell subsystem with user-friendly features such as autocompletion, wildcards, coloring, metakeys (arrows, backspace, ctrl+u, etc.) and history. Support for static commands and dynamic sub-commands.

Settings on non-volatile storage

The settings subsystem gives modules a way to store persistent per-device configuration and runtime state. Settings items are stored as key-value pair strings.

Non-volatile storage (NVS)

NVS allows storage of binary blobs, strings, integers, longs, and any combination of these.

Native port

Native sim allows running Zephyr as a Linux application with support for various subsystems and networking.

Setting up on Ubuntu version 20.04 LTS and later.

$ sudo apt update
$ sudo apt upgrade

Install dependencies

Tool

Min. Version

3.20.5

3.8

1.4.6

Installation

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

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

Verify the versions of the main dependencies installed on your system by entering

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

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.

Install west:

pip3 install west

Get the Zephyr source code:

west init ~/zephyrproject
cd ~/zephyrproject
west update

Export a Zephyr CMake package. This allows CMake to automatically load boilerplate code required for building Zephyr applications.

west zephyr-export

Zephyr’s scripts/requirements.txt file declares additional Python dependencies. Install them with pip

pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt

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.

It also contains additional host tools, such as custom QEMU and OpenOCD builds that are used to emulate, flash and debug Zephyr applications. You can change 0.16.4 to another version in the instructions below if needed; the Zephyr SDK Releases page contains all available SDK releases.

Download and verify the Zephyr SDK bundle

cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/zephyr-sdk-0.16.4_linux-x86_64.tar.xz
wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/sha256.sum | shasum --check --ignore-missing

If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace x86_64 with aarch64 in order to download the 64-bit ARM Linux SDK.

Extract the Zephyr SDK bundle archive:

tar xvf zephyr-sdk-0.16.4_linux-x86_64.tar.xz

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

  • $HOME

  • $HOME/.local

  • $HOME/.local/opt

  • $HOME/bin

  • /opt

  • /usr/local

The Zephyr SDK bundle archive contains the zephyr-sdk-0.16.4 directory and, when extracted under $HOME, the resulting installation path will be $HOME/zephyr-sdk-0.16.4.

Run the Zephyr SDK bundle setup script:

cd zephyr-sdk-0.16.4
./setup.sh

You only need to run the setup script once after extracting the Zephyr SDK bundle. You must rerun the setup script if you relocate the Zephyr SDK bundle directory after the initial setup.

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

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

Last updated