Getting Started with Zephyr
What is Zephyr OS?
Zephyr is a scalable, open-source real-time operating system (RTOS) designed for resource-constrained devices. It is developed under the Linux Foundation and supports multiple architectures including ARM, x86, RISC-V, and more.
Key Features
- Small footprint: Designed for devices with limited memory
- Multi-architecture support: ARM Cortex-M, RISC-V, x86, ARC, Xtensa, and more
- Security-focused: Built-in support for TrustZone, secure boot, and cryptographic libraries
- Connectivity: Native support for Bluetooth LE, Thread, Wi-Fi, LoRaWAN, and other protocols
- Real-time: Deterministic kernel with configurable scheduling algorithms
- Modular: Only include what you need in your build
- Active community: Backed by major companies (Intel, Nordic, NXP, STMicroelectronics, etc.)
Installation Procedure
Fedora / RHEL-based
The official Zephyr documentation only provides installation instructions for Ubuntu. Here are the equivalent dependencies for Fedora, RHEL, CentOS, Rocky Linux, and other DNF-based distributions:
sudo dnf install git cmake ninja-build gperf ccache dfu-util dtc wget \
python3-devel python3-tkinter xz file make gcc gcc-c++ \
glibc-devel.i686 libstdc++-devel.i686 SDL2-devel file-libs libusb1-devel libevdev-develInstall West (Zephyr meta-tool)
West is Zephyr’s command-line tool for managing repositories and building applications:
pip install westGet Zephyr Source Code
west init ~/zephyrproject
cd ~/zephyrproject
west updateInitialize West from a Custom Zephyr Repository
If you have a custom Zephyr fork or a project based on Zephyr with its own west.yml manifest, you can initialize West directly from that local repository:
# Clone your custom Zephyr repository
git clone https://github.com/your-org/your-custom-zephyr.git
cd your-custom-zephyr
# Initialize West using the local manifest
west init -l .
# Fetch all dependencies defined in west.yml
west updateThe -l (or --local) flag tells West that the manifest file is located in the current local directory rather than fetching it from a remote repository.
Install Zephyr SDK
Download and install the Zephyr SDK which includes toolchains for all supported architectures:
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64.tar.xz
tar xvf zephyr-sdk-0.16.8_linux-x86_64.tar.xz
cd zephyr-sdk-0.16.8
./setup.shSet Environment Variables
cd ~/zephyrproject/zephyr
source zephyr-env.shBuild and Run Locally (Native Simulator)
To build and run Zephyr applications on your local PC without hardware, use the native simulator:
west build -b native_sim samples/hello_worldOther native board variants:
native_sim/native/64: 64-bit native simulator
Run the application:
west build -t runFor more details, see the Native Simulator documentation.
Follow the official Zephyr Project installation guide to set up your development environment:
Board
ST Electronic Board
STM32CubeProgrammer is an all-in-one software tool for programming STM32 MCU memories (such as Flash and RAM). It provides an easy-to-use and efficient environment to read, write, and verify STM32 MCU memory through their debug interface (JTAG and SWD) or bootloader interface (accessible via UART, USB DFU, I2C, SPI, or CAN). It is available in both GUI (graphical user interface) and CLI (command-line interface) versions.
Download here: STM32CubeProgrammer
Installation on Linux:
unzip ./stm32cubeprg-lin-v2-21-0.zip
./SetupSTM32CubeProgrammer-2.21.0.linuxThen follow the UI instructions to complete the installation.
Configure udev rules to allow access to ST-Link debuggers without root privileges:
sudo cp ~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/Drivers/rules/*.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo usermod -aG dialout $USERLog out and log back in for the group change to take effect.
Build and flash your application to the board:
west build -b stm32h573i_dk samples/hello_world
west flashMonitor the UART output:
minicom -D /dev/ttyACM0Project Structure
A Zephyr application requires the following structure:
my_app/
├── CMakeLists.txt
├── prj.conf
├── boards/
│ └── <board_name>.overlay
└── src/
└── main.cCMakeLists.txt
The CMake build file integrates your application with the Zephyr build system:
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(my_app)
target_sources(app PRIVATE src/main.c)Kconfig (prj.conf)
Kconfig is Zephyr’s configuration system inherited from the Linux kernel. It allows you to enable/disable features, drivers, and kernel options at compile time. Options are defined in prj.conf:
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_GPIO=yCommon options:
CONFIG_SERIAL: Enable serial driverCONFIG_GPIO: Enable GPIO driverCONFIG_LOG: Enable logging subsystem
To see all available options, run west build -t menuconfig.
Devicetree Overlay
Devicetree describes the hardware configuration. Overlays (.overlay files) allow you to customize the board’s default devicetree without modifying Zephyr source files.
Create boards/<board_name>.overlay to:
- Enable/disable peripherals
- Change pin assignments
- Configure peripheral settings (baud rate, etc.)
Example enabling USART3:
&usart3 {
status = "okay";
current-speed = <115200>;
};The overlay is automatically applied when the filename matches your target board.
To check available peripherals in the devicetree after a build:
west build -b stm32h573i_dk samples/hello_world
cat build/zephyr/zephyr.dts | grep -A 10 "usart3"src/main.c
#include <zephyr/kernel.h>
int main(void)
{
printk("Hello World!\n");
return 0;
}