Nordic IoT Axon NPU 手势识别 ,第 5 篇:Zephyr Linux 环境搭建

本文是 Nordic 新款获奖物联网开发套件 Nordic nRF54LM20-DK 系列教程的第五篇。

想要正常完成本次手势演示程序的环境配置,请先参考本系列第二篇、第三篇文章。本应用基于Nordic 边缘人工智能实验室方案,实现一款基于手势识别的遥控设备。

本次手势识别演示,我们采用 DigiKey 在售的 Bosch BMI270 惯性测量单元(IMU)Sparkfun 评估板

通过杜邦线点对点直连该评估板的 4 线 SPI 接口(同时引出 3.3V 电源与地线为传感器供电),将其连接至 Nordic nRF54LM20-DK 开发板的 P17 接口

以下为 Zephyr 实时操作系统设备树覆盖文件中的相关配置(仅展示 SPI 接口相关配置代码)

spi21_default: spi21_default {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 3, 3)>,
				<NRF_PSEL(SPIM_MISO, 3, 1)>,
				<NRF_PSEL(SPIM_MOSI, 3, 0)>;
		};
	};

	spi21_sleep: spi21_sleep {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 3, 3)>,
				<NRF_PSEL(SPIM_MISO, 3, 1)>,
				<NRF_PSEL(SPIM_MOSI, 3, 0)>;
			low-power-enable;
		};
	};
};

&gpio3 {
	status = "okay";
};

&spi21 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi21_default>;
	pinctrl-1 = <&spi21_sleep>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;

	bmi270: spi-dev-bmi270@0 {
		compatible = "bosch,bmi270";
		status = "okay";
		reg = <0>;
		spi-max-frequency = <DT_FREQ_M(8)>;
	};
};

硬件点对点接线对照表

本次使用的线材颜色仅为区分,无硬性规定:

  • 3.3V 电源 —— P17-1(橙色线)
  • GND 地线 —— P17-2(棕色线)
  • MOSI 主机输出从机输入 —— P17-9(灰色线)
  • MISO 主机输入从机输出 —— P17-10(绿色线)
  • SPI 片选 CS —— P17-13(黄色线)
  • SPI 时钟 CLK —— P17-14(紫色线)

程序编译步骤

在 Python 虚拟环境中按以下步骤编译演示工程(环境搭建详见第二、三篇)

(venv)  ~/DigiKey_Coffee_Cup/Nordic$ nrfutil sdk-manager toolchain launch --ncs-version v3.3.0-preview2 --shell

进入工具链终端后,执行编译命令:

(v3.3.0-preview2) ~/DigiKey_Coffee_Cup/Nordic$ west build -p always -b nrf54lm20dk/nrf54lm20b/cpuapp edge-ai/applications/gesture_recognition/

...

[376/376] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      490200 B     925552 B     52.96%
             RAM:       41428 B       511 KB      7.92%
        IDT_LIST:          0 GB        32 KB      0.00%

...

按照 Zephyr RTOS 常规流程烧录固件:

(v3.3.0-preview2) ~/DigiKey_Coffee_Cup/Nordic$west flash

...
...

-- runners.nrfutil: Connecting to probe
-- runners.nrfutil: Programming image
-- runners.nrfutil: Verifying image
-- runners.nrfutil: Reset
-- runners.nrfutil: Board(s) with serial number(s) 1051861371 flashed successfully.

打开 minicom 串口终端,若传感器检测正常,终端会打印如下启动信息:

*** Booting MCUboot v2.3.0-dev-3dfaa012cf34 ***
*** Using nRF Connect SDK v3.3.0-preview2-ede152ec210b ***
*** Using Zephyr OS v4.3.99-4b6df5ff11b1 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: none
I: Bootloader chainload address offset: 0x10000
I: Image version: v0.0.0
I: Jumping to the first image slot
*** Booting nRF Connect SDK v3.3.0-preview2-ede152ec210b ***
*** Using Zephyr OS v4.3.99-4b6df5ff11b1 ***
[00:00:00.050,671] <inf> fs_nvs: 8 Sectors of 4096 bytes
[00:00:00.050,678] <inf> fs_nvs: alloc wra: 0, fa0
[00:00:00.050,682] <inf> fs_nvs: data wra: 0, 30
[00:00:00.050,761] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
                                            ac 6c cb 12 2a 45 63 97  7c ba aa bd 8d 8f d0 9b |.l..*Ec. |.......
                                            c2 c9 23 ea                                      |..#.             
[00:00:00.052,910] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.052,925] <inf> bt_hci_core: HW Variant: nRF54Lx (0x0005)
[00:00:00.052,938] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 172.52076 Build 1665477138
[00:00:00.053,138] <inf> bt_hci_core: No ID address. App must call settings_load()
[00:00:00.053,153] <inf> ble_hid: Bluetooth initialized
[00:00:00.053,511] <inf> bt_hci_core: HCI transport: SDC
[00:00:00.053,611] <inf> bt_hci_core: Identity: F3:93:F9:A8:5C:40 (random)
[00:00:00.053,630] <inf> bt_hci_core: HCI: version 6.2 (0x10) revision 0x3073, manufacturer 0x0059
[00:00:00.053,648] <inf> bt_hci_core: LMP: version 6.2 (0x10) subver 0x3073
[00:00:00.055,972] <inf> ble_hid: Advertising successfully started
[00:00:00.056,019] <inf> main: nRF Edge AI Gestures Recognition Demo:
[00:00:00.056,029] <inf> main: nRF Edge AI Runtime Version: 2.2.0
[00:00:00.056,047] <inf> main: nRF Edge AI Lab Solution id: 36038
[00:00:22.525,021] <inf> main: Predicted class: DOUBLE THUMB, with probability 76 %
[00:00:53.594,756] <inf> main: Predicted class: DOUBLE THUMB, with probability 82 %

etc etc

[00:00:04.015,501] <inf> main: Predicted class: DOUBLE THUMB, with probability 88 %
[00:00:08.312,211] <inf> main: Predicted class: DOUBLE SHAKE, with probability 84 %
[00:00:09.303,819] <inf> main: Predicted class: ROTATION RIGHT, with probability 89 %
[00:00:09.634,333] <inf> main: Predicted class: ROTATION RIGHT, with probability 92 %
[00:00:16.245,012] <inf> main: Predicted class: DOUBLE THUMB, with probability 100 %
[00:00:17.567,062] <inf> main: Predicted class: DOUBLE SHAKE, with probability 99 %
[00:00:18.889,219] <inf> main: Predicted class: DOUBLE THUMB, with probability 92 %
[00:00:19.880,790] <inf> main: Predicted class: DOUBLE SHAKE, with probability 80 %
[00:00:21.864,775] <inf> main: Predicted class: DOUBLE SHAKE, with probability 91 %
[00:00:23.847,158] <inf> main: Predicted class: DOUBLE THUMB, with probability 91 %
[00:00:24.838,732] <inf> main: Predicted class: DOUBLE THUMB, with probability 98 %
[00:00:25.830,311] <inf> main: Predicted class: DOUBLE THUMB, with probability 80 %
[00:00:26.821,886] <inf> main: Predicted class: DOUBLE THUMB, with probability 98 %
[00:00:30.457,718] <inf> main: Predicted class: DOUBLE SHAKE, with probability 88 %
[00:00:37.068,271] <inf> main: Predicted class: DOUBLE SHAKE, with probability 99 %
[00:00:38.720,966] <inf> main: Predicted class: DOUBLE SHAKE, with probability 83 %

若在 minicom 终端出现如下报错信息:

[00:00:00.014,050] <err> main: Failed to initialize IMU sensor, error = 2

则说明硬件接线有误,需要重新检查并修正线路。

敬请关注后续文章,我们将对本套演示项目进行完整总结。至此,基于Nordic 前沿物联网平台、直接调用 Axon NPU 驱动实现的 Axon 神经网络处理器手势识别演示开发部分已完成。这款斩获2026 嵌入式世界博览会奖项的 Nordic nRF54LM20-DK 物联网开发套件,现已在DigiKey(DigiKey)上架销售。