针对那些有兴趣了解Zephyr OS(分区管理器[未显示但也是CMake工具的输入])、设备树、KConfig、CMake、Ninja、GCC)的朋友(配置阶段 + 构建阶段)
DigiKey提供了一种经济实惠的替代方案,例如知名的树莓派Pico 2或树莓派Pico 2 W,可以用来替代其他平台,如广为人知的ESP32-WROOM-32E-N4(乐鑫系统Xtensa双核32位LX6微处理器)。
以下是在Linux系统中安装并开发树莓派Pico 2上Zephyr OS的步骤。首先创建一个Python虚拟环境,
$ python3 -m venv venv
$ source venv/bin/activate
然后安装west,
$ (venv) pip3 install west
接着按如下方式使用west初始化Zephyr,
$ (venv) west init zephyrproject
$ (venv) cd zephyrproject/
$ (venv) west update
还需要安装以下英飞凌硬件抽象层软件项,
$ (venv) west blobs fetch hal_infineon
然后执行经典的zephyr-export,
$ (venv) west zephyr-export
$ (venv) west packages pip --install
$ (venv) cd zephyr/
继续安装Zephyr OS软件开发套件(SDK),
$ (venv) west sdk install
至此,Zephyr OS开发环境安装完成。为了构建位于此处的经典LED闪烁应用程序main.c,
zephyrproject/zephyr/samples/basic/blinky/src
在树莓派Pico 2的Zephyr OS应用中,使用west按如下方式构建(假设构建目录已存在),
$ (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
此时构建完成,然后按住树莓派Pico 2上的启动按钮并重新连接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'
另一种方法是使用picotool,
$ (venv) picotool load build/zephyr/zephyr.uf2
Family ID 'absolute' can be downloaded in absolute space:
00000000->02000000
Loading into Flash: [==============================] 100%
此时,一旦重新连接后,从树莓派Pico 2上断开USB线,板载LED应开始闪烁,
[wrap=“justify”]
如果使用minicom,用户可以访问打印输出,
$ 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
....
可以修改main.c程序,例如LED闪烁频率的默认延迟,
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
改为其他值,并重复之前展示的构建和烧录过程,以检查其是否正常工作。
另一个例子是经典的Zephyr CPU同步示例,
(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'
在minicom窗口中可以看到输出,
$ 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!
该同步演示有两个线程,它们使用信号量和休眠功能,以受控的速率通过USB轮流打印消息。
树莓派Pico 2具有双核、双架构能力,其RP2350允许用户在一对行业标准的Arm Cortex-M33核心和一对开源硬件Hazard3 RISC-V核心之间进行选择。
对于那些等不及再等两周才发布的Arduino Uno(它包含一颗运行Debian Linux操作系统的Qualcomm® Dragonwing™ QRB2210四核Arm® Cortex®-A53,以及一颗在Zephyr OS上运行Arduino Core的TMicroelectronics® STM32U585 Arm® Cortex®-M33)的人来说,这是一个开始学习Zephyr OS(设备树、KConfig、CMake、Ninja、GCC)的不错替代方案。
本文的西班牙语版本可在此处获取。
Este artículo se encuentra disponible el lenguaje español aqui.

