Colibri Zephyr

From Stm32World Wiki
Jump to navigation Jump to search


Colibri is intended to be used by systems integrators, makers, automation engineers, home automation enthusiasts and in general people how doesn't necessarily know how to write low-level programs or operate soldering iron. That means that "flashing an image" to the MCU is beyond what is expected by the potential customers.

Instead, we need an "operating system", where we can deploy user applications without low-level programming skills. With that comes two challenges;

1. How are those applications written?

2. How are they going to be executed on the Colibri MCUs?

TL;DR

  • A user application will deployed in a so called Web Assembly runtime. The number and size of user applications are dependent on available RAM in the MCU.
  • Each I/O module will contain its own Web Assembly driver that user applications will be able to interface with.
  • I/O driver is (initially?) limited to 16kB in size and will run inside its own Web Assembly runtime and given time slots to execute, via a tick(slot_number) function call at a (per I/O slot) settable interval. I/O modules may also emit events that applications can subscribe to. The exact API is documented for each Colibri I/O module.

It could happen that domain-specific languages are to be developed for this environment. Or perhaps, we will managed to get OpenPLC running on Web Assembly. It is a little bit too early to tell in which direction this will be going.

What is Zephyr?

From Zephyr's website;

   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.

Please read the entire introduction page.

Additionally to task scheduling, we also get cross-platform APIs for SPI and I2C peripherals, as well as access to many Zephyr libraries, such as Modbus/RTU, TCP/IP, MQTT and much more.

Supported Boards

Colibri Integration

Colibri carrier boards and Colibri MCU modules are being integrated with Zephyr.

Setting up Zephyr

Setting up Zephyr development is somewhat confusing. The official documentation is in my opinion somewhat misleading. At least it misled me for quite a while. I have found this to be the most straight forward, although you can probably set up with a single `zephyr/` for multiple projects, but since our target here is for only a single workspace, I am ok to occupy a lot of disk space for this.

   mkdir colibri-zephyr    # or whatever name you want
   cd colibri-zephyr
   
   sudo apt update
   sudo apt upgrade
   sudo apt install --no-install-recommends git cmake ninja-build gperf \
     ccache dfu-util device-tree-compiler wget python3-dev python3-venv python3-tk \
     xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 curl
   curl -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-29/wasi-sdk-29.0-$(uname -m | sed s/aarch64/arm64/)-linux.tar.gz | tar xz
   mv * wasi-sdk
   python3 -m venv .venv
   echo "export ZEPHYR_BASE=`pwd`/zephyr" >>.venv/bin/activate
   echo "export ZEPHYR_TOOLCHAIN_VARIANT=zephyr" >>.venv/bin/activate
   echo "export ZEPHYR_SDK_INSTALL_DIR=$HOME/zephyr-sdk-1.0.1" >>.venv/bin/activate
   source .venv/bin/activate
   pip install west
   west init -m https://github.com/currentmakers/colibri-runtime
   west update
   west zephyr-export
   west packages pip --install
   west sdk install -t arm-zephyr-eabi
   west config zephyr.toolchain-variant zephyr
   west config zephyr.sdk-install-dir $HOME/zephyr-sdk-1.0.1


Developing with Zephyr

To build Colibri Runtime, go to the directory created on the first step above (cd colibri-zephyr/).

After opening a new shell/terminal/konsole you will need to initialize the virtual Python environment.

   source .venv/bin/activate

And thereafter the build can be executed,

   west build -b colibri_mcu3 --shield colibri_carrier colibri-runtime

and the .elf and .bin output files are in build/zephyr and can be flashed as usual with

   st-flash --connect-under-reset write build/zephyr/zephyr.bin 0x8000000

It seems that Zephyr disables the SWD interface by default, hence the --connect-under-reset.

Colibri Runtime development

The Colibri Runtime (if you are only interested in USING the Colibri Runtime, go to that page) project is available on Github and after setting up Zephyr, checking out the WS2812B PWM driver and the Colibri device tree, with the paths set up correctly as described above, you should be able to build it.

Currently we have the following directory structure of the project, ignoring the build directory(ies).

   ├── app.overlay 
   ├── CMakeLists.txt
   ├── prj.conf
   ├── README.md
   └── src
       ├── fs
       │   ├── fs.h
       │   ├── littlefs.c
       │   └── nvs.c
       ├── leds
       │   ├── leds.c
       │   ├── leds.h
       │   └── neopixels.c
       ├── main.c
       └── slots
           ├── slotcount.c
           ├── slotctrl.c
           └── slotctrl.h