Zephyr OS en la Raspberry Pico 2 (Linux) Parte 1

Para aquellos interesados en aprender acerca del Sistema Operativo Zephyr (Manejador de Partición [no mostrado pero también parte de la entrada a la herramienta CMake]), Devicetree, KConfig, CMake, Ninja, GCC) (Fase de Configuración + Fase de Construcción).

aquí hay una alternativa económica disponible de DigiKey tal como el bien conocido Raspberry Pico 2 o el Raspberry Pico 2 W, que se puede utilizar en otras plataformas como el bien conocido ESP32-WROOM-32E-N4 Espressif Systems Xtensa dual-core 32-bit LX6 microprocessor.

Aquí están los pasos para instalar en Linux para desarollar en Zephyr OS en la Raspberry Pico 2. Primeramente se crea un ambiente virtual de python,

$ python3 -m venv venv
$ source venv/bin/activate

entonces se procede a instalar west dentro del ambiente virtual de python,

$ (venv) pip3 install west

se inicializa Zephyr con west como sigue,

$ (venv) west init zephyrproject
$ (venv) cd zephyrproject/
$ (venv) west update

se procede a instalar el siguiente componente de abstracción del hardware,

$ (venv) west blobs fetch hal_infineon

entonces se procede al clásico zephyr-export,

$ (venv) west zephyr-export
$ (venv) west packages pip --install
$ (venv) cd zephyr/

luego se instala el Zephyr OS Software Development Kit (SDK),

$ (venv) west sdk install

una vez este completada la instalación del sistema operativo Zephyr OS.

Se puede en este momento, construir la clásica aplicación main.c que se encuetra aquí,

zephyrproject/zephyr/samples/basic/blinky/src

en el sistema operativo Zephyr OS application en la Raspberry Pico 2 utiliza west para construirla como se mustra a continuación (asumiendo que el directorio build esta presente),

$ (venv) cd build
$ (venv) west build -p always -b rpi_pico2/rp2350a/m33 -S cdc-acm-console ../samples/basic/blinky -DCONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

-- west build: making build dir /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/samples/basic/blinky
-- CMake version: 3.25.1
-- Found Python3: /home/digikey/Projects/Workspace/zephyr-picow/venv/bin/python3 (found suitable version "3.11.2", minimum required is "3.10") found components: Interpreter 
-- Cache files will be written to: /home/digikey/.cache/zephyr
-- Zephyr version: 4.2.99 (/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr)
-- Found west (found suitable version "1.5.0", minimum required is "0.14.0")
-- Board: rpi_pico2, qualifiers: rp2350a/m33
-- Snippet(s): cdc-acm-console
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.17.4 (/home/digikey/zephyr-sdk-0.17.4)
-- Found toolchain: zephyr 0.17.4 (/home/digikey/zephyr-sdk-0.17.4)
-- Found Dtc: /home/digikey/zephyr-sdk-0.17.4/sysroots/aarch64-pokysdk-linux/usr/bin/dtc (found suitable version "1.7.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/boards/raspberrypi/rpi_pico2/rpi_pico2_rp2350a_m33.dts
-- Found devicetree overlay: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/snippets/cdc-acm-console/cdc-acm-console.overlay
-- Generated zephyr.dts: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/zephyr.dts
-- Generated pickled edt: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/edt.pickle
-- Generated devicetree_generated.h: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/include/generated/zephyr/devicetree_generated.h

Parsing /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/Kconfig
Loaded configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/boards/raspberrypi/rpi_pico2/rpi_pico2_rp2350a_m33_defconfig'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/samples/basic/blinky/prj.conf'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/snippets/cdc-acm-console/cdc-acm-console.conf'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/misc/generated/extra_kconfig_options.conf'
Configuration saved to '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/.config'
Kconfig header saved to '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/digikey/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/digikey/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Using ccache: /usr/bin/ccache
-- Found gen_kobject_list: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/scripts/build/gen_kobject_list.py
-- Configuring done
-- Generating done
-- Build files have been written to: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build
-- west build: building application
[1/168] Preparing syscall dependency handling

[3/168] Generating include/generated/zephyr/version.h
-- Zephyr version: 4.2.99 (/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr), build: v4.2.0-5176-ge5838ffc2176
[168/168] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       42088 B         4 MB      1.00%
             RAM:       14120 B       520 KB      2.65%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/zephyr.elf for board: rpi_pico2
Converted to uf2, output size: 84480, start address: 0x10000000
Wrote 84480 bytes to zephyr.uf2

Una vez la construcción del código se haya completado, entonces procede a oprimir el botón del
Raspberry Pico 2 una vez reconectado el cable USB,

$ (venv) west flash --runner uf2 

-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner uf2
-- runners.uf2: Copying UF2 file to '/media/digikey/RP2350'

otra alternativa es utilizando picotool,

$ (venv) picotool load build/zephyr/zephyr.uf2
Family ID 'absolute' can be downloaded in absolute space:
  00000000->02000000
Loading into Flash:   [==============================]  100%

Se procede a desconectar el cable USB de la Raspberry Pico 2 una vez reconectado, entonces el LED comienza a parpadear,

para accesar la salida, se procede a utilizar minicom como sigue,

$ minicom -D /dev/ttyACM0

Welcome to minicom 2.8

OPTIONS: I18n 
Port /dev/ttyACM0, 12:41:43

Press CTRL-A Z for help on special keys

LED state: ON
LED state: OFF
LED state: ON
LED state: OFF
LED state: ON                                                         
....


el programa main.c se modifica como el default delay de la rapidez con que parpadea el LED,

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

a otro valor como 1 segundo (1000 ms) como se muestra anteriormente. Entonces se repite el proceso de construir el código como se muestra anteriormente para ver si esta funcionando.

Otro ejemplo es el de sincronización de los “threads” el sistema operativo Zephyr, y se contruye el código como se muestra a continuación,

(venv) $ west build -p always -b rpi_pico2/rp2350a/m33 -S cdc-acm-console ../samples/synchronization/ -DCONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y
-- west build: making build dir /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/samples/synchronization
-- CMake version: 3.25.1
-- Found Python3: /home/digikey/Projects/Workspace/zephyr-picow/venv/bin/python3 (found suitable version "3.11.2", minimum required is "3.10") found components: Interpreter 
-- Cache files will be written to: /home/digikey/.cache/zephyr
-- Zephyr version: 4.2.99 (/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr)
-- Found west (found suitable version "1.5.0", minimum required is "0.14.0")
-- Board: rpi_pico2, qualifiers: rp2350a/m33
-- Snippet(s): cdc-acm-console
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.17.4 (/home/digikey/zephyr-sdk-0.17.4)
-- Found toolchain: zephyr 0.17.4 (/home/digikey/zephyr-sdk-0.17.4)
-- Found Dtc: /home/digikey/zephyr-sdk-0.17.4/sysroots/aarch64-pokysdk-linux/usr/bin/dtc (found suitable version "1.7.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/boards/raspberrypi/rpi_pico2/rpi_pico2_rp2350a_m33.dts
-- Found devicetree overlay: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/snippets/cdc-acm-console/cdc-acm-console.overlay
-- Generated zephyr.dts: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/zephyr.dts
-- Generated pickled edt: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/edt.pickle
-- Generated devicetree_generated.h: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/include/generated/zephyr/devicetree_generated.h

Parsing /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/Kconfig
Loaded configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/boards/raspberrypi/rpi_pico2/rpi_pico2_rp2350a_m33_defconfig'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/samples/synchronization/prj.conf'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/snippets/cdc-acm-console/cdc-acm-console.conf'
Merged configuration '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/misc/generated/extra_kconfig_options.conf'
Configuration saved to '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/.config'
Kconfig header saved to '/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/digikey/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/digikey/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Using ccache: /usr/bin/ccache
-- Found gen_kobject_list: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/scripts/build/gen_kobject_list.py
-- Configuring done
-- Generating done
-- Build files have been written to: /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build
-- west build: building application
[1/169] Preparing syscall dependency handling

[3/169] Generating include/generated/zephyr/version.h
-- Zephyr version: 4.2.99 (/home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr), build: v4.2.0-5176-ge5838ffc2176
[169/169] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       42832 B         4 MB      1.02%
             RAM:       16712 B       520 KB      3.14%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from /home/digikey/Projects/Workspace/zephyr-picow/zephyrproject/zephyr/build/build/zephyr/zephyr.elf for board: rpi_pico2
Converted to uf2, output size: 86016, start address: 0x10000000
Wrote 86016 bytes to zephyr.uf2

 $ west flash --runner uf2 
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner uf2
-- runners.uf2: Copying UF2 file to '/media/digikey/RP2350'

en el terminal minicom se puede ver la salida,

$ minicom -D /dev/ttyACM0

Welcome to minicom 2.8

OPTIONS: I18n 
Port /dev/ttyACM0, 12:41:43

Press CTRL-A Z for help on special keys
Welcome to minicom 2.8

thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!
thread_b: Hello World from cpu 0 on rpi_pico2!
thread_a: Hello World from cpu 0 on rpi_pico2!

La sincronización entre ambos “threads” usa semáforos, y “sleep mode”, para tomar turnos para imprimir un mensaje vía USB en determinados intervalos. La Raspberry Pico 2 tiene dos “cores”. Una arquitectura dual, ya que permite al usario escoger, entre un par “cores”, uno del standard de la industria Arm Cortex-M33, y el “core” bien conocido open-hardware Hazard3 RISC-V.

Esto es una buena alternativa para aprender el sistema operativo Zephyr OS (Devicetree, KConfig, CMake, Ninja, GCC). En las próximas semanas sale el Arduino Uno que incluye un Qualcomm® Dragonwing™ QRB2210 que es un quad-core Arm® Cortex®-A53 corriendo el sistema operativo Debian Linux y también el TMicroelectronics® STM32U585 que es un Arm® Cortex®-M33 corriendo un Arduino Core en Zephyr OS.

Este artículo esta disponible en idioma ingles aquí.

This article is available in english language here.