Post

ENG | Zephyr RTOS Setup and Blinky Examples

Setting up Zephyr RTOS development environment and flashing simple LED examples to Nordic and Raspberry Pi Pico development boards.

ENG | Zephyr RTOS Setup and Blinky Examples

This article describes my first steps with Zephyr and it’s building pipeline.

Installation

Installation process is well documented in Getting started, but time consuming and requires at least 16GB of disk space. Likely more due to prerequisites and Python modules. It downloads lot of data from github and then creates hundreds thousands files, so if I recall, installation can take over one hour on weak hardware, such as Lenovo T480s notebook from 2017/18.

Only mistake I made was that when installation mentions activate you really need to run proper command for PowerShell, which is not activate.bat. Just in case you see errors such as FATAL ERROR: Running pip install outside of a virtual environment when installing west packages or ModuleNotFoundError: No module named 'elftools' when building application.

Building package for nRF52840 Dongle

There is a documentation for nRF52840 Dongle which takes some parts from Nordic Semiconductor documentation or for Seeed Studio XIAO nRF52840 (Sense)

nrfutil command has to be downloaded from Nordic Semiconductor

Useful commands are

1
2
3
4
cd C:\dev-zephyr\zephyrproject
west build --pristine -b nrf52840dongle/nrf52840  .\zephyr\samples\basic\blinky
C:\apps\nrfutil.exe pkg generate --hw-version 52 --sd-req=0x00 --application build\zephyr\zephyr.hex --application-version 1 blinky.zip
c:\apps\nrfutil.exe dfu usb-serial -pkg .\blinky.zip -p COM7

or

1
2
west build --pristine -b xiao_ble/nrf52840 .\zephyr\samples\basic\blinky
cp .\build\zephyr\zephyr.uf2 d:

In both cases, device must be in boot mode. For dongle it is entered by briefly holding RESET (not SW1!) button while being plugged in. For XIAO it needs to double click RST button.

For XIAO it ends by

1
2
3
4
5
6
7
8
[154/154] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       36632 B       788 KB      4.54%
             RAM:       14720 B       256 KB      5.62%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from C:/dev-zephyr/zephyrproject/build/zephyr/zephyr.elf for board: xiao_ble
Converted to uf2, output size: 73728, start address: 0x27000
Wrote 73728 bytes to zephyr.uf2

NOTE: Pristine build is needed when switching target hardware.

Building blinky for Raspberry Pi Pico

At the time of writing, Raspberry Pi Pico 2 W is likely not supported and only ARM Cortex-M33 cores are supported on Pico 2. I haven’t tried version with WiFi, which requires installing wifi module by west blobs fetch hal_infineon.

Documentation is here:

Boards basically differ by rpi_pico, rpi_pico2/rp2350a/m33, xiao_rp2040.

Boot mode for Picos is entered by holding BOOTSEL button while being plugged in.

Tips

After playing with Zephyr, you may need to reupload MicroPython

Conclusion

Installation of Zephyr is rather straightforward and very well documented, but it requires many steps and it’s a bit time consuming and resource heavy.

So far, documentation seems very good.

Debugging embedded applications requires a different approach than desktop development. Without hardware debug probes, you’re mainly limited to printing text to the serial console to understand what’s happening. This is common across embedded platforms. The need to manually enter boot mode for flashing (holding reset buttons) does slow down the development cycle compared to some other platforms where you can flash directly over USB.

I assume this can be a problem - not caused by Zephyr per-se, but it’s much easier to debug applications on PC.

From what I read, C++ support and especially use of STL is somewhat limited.

This post is licensed under CC BY 4.0 by the author.