CSSE4011: Tute 1 - Getting Started with Zephyr RTOS
1.0 Zephyr RTOS: Overview
Zephyr Real-Time Operating System (RTOS) managed by the Linux foundation, is designed for connected and resource constrained embedded devices. Unlike many other real-time operating systems (like free-RTOS), Zephyr is more than just a kernel, it is a software eco-system. Zephyr integrates a broad range of functionality such as:
- Bluetooth
- LoRaWan
- USB / Serial Console / Shell(CLI)
- SPI/I2C/UART
- Flash Drivers
- Filesystems
and more... Depending on what particular feature your application might require, Zephyr allows you to build a program using only the necessary functionality (i.e BLE), this can optimize the overall footprint of binary. This is done using config file(s) that we will cover in the coming tutorials.
1.1 Zephyr Kernel Overview
The Zephyr kernel is similar to that of free-RTOS at a high level, in that it is primarily concerned with task-scheduling, inter-task communication and synchronization.
- Zephyr offers a pre-emptive scheduler, that is, the code context can change at anytime.
- Thread based, where 'threads' mean the same thing as a 'task' in free-RTOS.
- It is 'Soft' real-time provided by system ticks
1.2 Zephyr West Meta-Tool
Zephyr includes a command line tool named west. This tool provides a multiple repository management system, and Zephyr uses west to provide conveniences for building, flashing, debugging and cleaning applications. For example, to build a program you could use,
This will look at predefined build configuration settings and build an application as specified. The west meta-tool can be used to perform many other functions, see here for a detailed breakdown of it's features. In this course, you will be using west to build, flash and maintain your workspaces.1.3 Zephyr Documentation
The Zephyr documentation is well written and contains all the intricate details about Zephyr and it's features. Throughout this course and application development, you will need to refer back to these documentation to understand;
- The Build and Configuration Systems
- Device Tree (A way of describing hardware config to the OS)
- Application Development (App config options/Kernel config)
- API Usage
- Using an Interactive Kconfig interfaces (Optional)
Take some time to read through these documents to get an idea of how Zephyr is implemented. This will be useful later when you are required to implement advanced features using Zephyr.
2.0 Installing Zephyr RTOS
The following guide is made in reference to the Zephyr "Getting Started Guide" documentation, and is intended to be used on a Debian based linux distribution with the "apt" (package manager installed).
First update the system and any installed packages on your VM
Reboot (If this was a fresh OS install, typically kernel is upgraded) [Skip kitware for Debian: This is for Ubuntu] Update sources list by adding the Kitware APT repo (contains cmake etc...)cd ~
wget https://apt.kitware.com/kitware-archive.sh
sudo bash kitware-archive.sh
sudo rm bash kitware-archive.sh - Remove script
Install cmake, python3 and dtc (device tree compiler)
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
sudo apt remove cmake - Remove out of date default package
pip3 install cmake --upgrade - Install upto date CMAKE
Verify dependencies are installed before continuing
3.0 Get Zephyr and Install Python dependencies
Install West (Zephyr Meta-tool)
Setup Zephyr Foldercd /home/user
mkdir csse4011/
cd csse4011/
west init zephyrproject/ - Latest version of Zephyr (the development tree)
4.0 Installing the toolchains
This tutorial will focus on installing the Zephyr SDK. Download Link.
Download and extract the Zephyr SDK installer. It is recommended to download the minimal installation for you architecture (e.g. x86 for intel CPU based computers)
Install the SDK to /opt/ , see here for other potential installation locationschmod +x zephyr-sdk-<version_namber>linux-x86_64-setup.run
sudo ./zephyr-sdk--<version_namber>-linux-x86_64-setup.run -- -d /opt/zephyr-sdk-0.13.2
sudo cp /opt/zephyr-sdk--<version_namber>/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
5.0 Build a Sample Program (Blinky) for the a Board
Refer to tutorial that covers the board, you are using.
6.0 Setting Zephyr Base
Setting $ZEPHYR_BASE
allows you to invoke west from outside the source directory to build your applications. So we will add this environment to be set at login by bashrc
. If you are using a different shell fish
or zsh
, make sure you set this within those config files.
If you installed Zephyr elsewhere, adjust the following accordingly.
echo "# Add Zephyr Base Location to Path
export ZEPHYR_BASE=~/csse4011/zephyrproject/zephyr" >> ~/.bashrc
source ~/.bashrc