Getting started with Zephyr

Outline: 

  • What is zephyr rtos?
  • Why Zephyr?
  • Installation guide and basic troubleshooting
  • Flashing 

Hey there! 

This post is beginner friendly, and I hope it to be the first in a series of projects dealing with various different protocols using zephyr.

What is Zephyr RTOS?                                                                                                                                       RTOS=real time operating system. RTOS is different from standard OS in multiple ways. As the line between MCUs and microprocessors blur, the actions and conditions of the various GPIOs need to be prioritized and timed. Hence there is the need for RTOS, the OS is responsible for reacting timely and precisely to different triggers. The way the timing is followed, that is, how precisely the timing is followed defines whether the RTOS is soft, firm or hard. The hard RTOS is used when there is life and disaster involved,  Soft is when the timing is followed but not very strictly and as precisely. The firm RTOS lies in-between.

The Zephyr Project, is an open-source RTOS, by the Linux Foundation. It is an embedded OS that supports a pretty big list of boards with iot support on various architectures and has a library based approach. It is developed and maintained by developers of the member organisations of The Linux Foundation. 

Why Zephyr RTOS?                                                                                                                                            Zephyr RTOS has support available for various boards across multiple architectures, this makes the code, which has library based protocols, makes the code portable and testable on multiple platforms. 

Installing Zephyr

While zephyr is supported on both Linux and Windows, the following guide is for linux users, tested on Ubuntu. I have attached the link to the official installation page for windows and mac users.                                                                                                                             

  • Using CLI update and upgrade your system                                                                                                                                                                            
sudo apt update
sudo apt upgrade
  • Install necessary tools
sudo apt install --no-install-recommends git cmake ninja-build gperf \
  ccache dfu-util device-tree-compiler wget \
  python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
  make gcc gcc-multilib g++-multilib libsdl2-dev
  • Verify the cmake version using the following command
  • -> cmake –version                                                                          
  • Next we need to install west, now the official documentation does not specify the version while installing this later has been causing issue becuse the while building we require a higher version of west, hence the modified version of the command is            
pip3 install --user -U west==0.7.0
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc
  • Getting the zephyr project source code                
cd ~
west init zephyrproject
cd zephyrproject
west update
  • Exporting zephyr package
west zephyr-export

6) Installing python dependencies                                                           

pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt

7) Download SDK                                                                          

cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run
  • Running Installation binary                                                     
chmod +x zephyr-sdk-0.11.2-setup.run
./zephyr-sdk-0.11.2-setup.run -- -d ~/zephyr-sdk-0.11.2

Setting Environment Variables

export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-0.11.2
  • Moving the flashing tools to give the right hardware access
sudo cp ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload

11)  This step is specifically for nrf boards. Apart from the above step, you need jtag tools to flash nrf boards. Use the following link to download the command line tools according to your system configuration, on unzipping and installing the jtag tools, you will be ready to go for your nrf boards.                                                                                                      https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download#infotabs

Building and Flashing your first program

So now that you have tyour installation done, you are ready to go about buiilding, flashing and testing your code. So let’s start by picking a sample,  let’s go with the classic ‘hello world’.                                    

There are 2 ways to go about building the application: The first is by specifying the path, and building it from outside,                                                                       

west build -p auto -b <your-board-name> samples/hello_world  

The second way is to go into the directory and then simply build it 

west build <board_name> 

If you get an error that’s probably because we haven’t sourced the zephyr source file, the following command should do the magic:                             

source <zephyr-install-dir>/zephyr-env.sh                                                  

Now you are ready to flash it!!    

west flash

And now if you open minicom, or another serial monitor, you should see a hello world

Congratulations on building and flashing your first code through Zephyr!

Resources and References                                                                                                                            https://www.microcontrollertips.com/real-time-standard-how-to-choose-rtos/ https://www.microcontrollertips.com/zephyr-open-source-rtos-iot-faq/                                https://docs.zephyrproject.org/latest/

Official installation guide     https://docs.zephyrproject.org/latest/getting_started/index.html                                                                                                  

Leave a comment

Design a site like this with WordPress.com
Get started