[i=s] 本帖最后由 hdydy 于 2025-5-18 00:22 编辑 [/i]
搭建环境
参考https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=46251
编译
修改代码
examples/lighting-app/bouffalolab/bl602/mboard.h
板子上有RGB三个灯,分别对应引脚IO14,IO17,IO3,为了能够调试,IO14,IO17用作JTAG,所以使用IO3点灯

#define LED_PIN_PORT 3// PWM通道
#define LED_PIN 3
examples/lighting-app/bouffalolab/bl602/args.gni
中增加 chip_stack_lock_tracking = "none"
is_debug = true
设置debug编译

examples/lighting-app/bouffalolab/bl602/BUILD.gn
中增加两行代码

cflags_c += [ "-Wno-unused-variable" ]
cflags = [ "-Wno-unused-variable" ]
编译
./scripts/build/build_examples.py --target bouffalolab-bl602dk-light-wifi-littlefs-shell build
生成的文件 out/bouffalolab-bl602dk-light-wifi-littlefs-shell/chip-bl602-lighting-example.bin
烧录
有两种烧录方式,将bin文件复制到Windows中然后使用Windows烧录工具,或者,用usbipd将串口分享到WSL2中然后使用Linux烧录工具。下面详细介绍第二种方式
安装usbipd
https://github.com/dorssel/usbipd-win/releases
管理员运行PowerShell

usbipd list
usbipd bind -b <busid>
usbipd attach --wsl -b <busid>
在WSL2中查看串口 ls /dev/tty*
,一般是 /dev/ttyUSB*

烧录
./out/bouffalolab-bl602dk-light-wifi-littlefs-shell/chip-bl602-lighting-example.flash.py --port /dev/ttyUSB0
使用命令 usbipd detach -b <busid>
断开设备与WSL2的连接
Matter点灯
启动日志


串口发送 help
命令

其中有些命令没有实现,比如 wifi connect

初始状态,蓝灯(IO3)微亮,BOOT键可以开关灯
蓝牙配网
如果是重新配网,需要串口发送命令 device factoryreset
恢复出厂设置

WSL2中使用蓝牙有些问题,所以改用VMware虚拟机
安装chip-tool sudo snap install chip-tool
将蓝牙设备连接至虚拟机

启动蓝牙 sudo service bluetooth start
chip-tool配网
chip-tool pairing ble-wifi <node_id> <ssid> <password> <pin_code> <discriminator>
node_id
为用户自定义的设备id,例如0x12,后面控制的时候会用到
pin_code
,discriminator
在 examples/lighting-app/bouffalolab/bl602/BUILD.gn
中定义

chip-tool pairing ble-wifi 0x12 <ssid> <password> 20202021 3840
chip-tool命令输出日志最后如果没有error信息,则配网成功
配网过程中串口会输出WiFi信息

配网成功后,蓝灯更亮
onoff命令控制
chip-tool onoff on/off/toggle <node_id> <endpoint_id>
node_id
为前面设置的值,0x12
endpoint_id
在 examples/lighting-app/bouffalolab/common/AppTask.h
中定义

开灯 chip-tool onoff on 0x12 1
关灯 chip-tool onoff off 0x12 1
切换 chip-tool onoff toggle 0x12 1
