固件开发指南
更新时间:2024/11/06
快速开始
选择产品模板
根据开发产品选择合适产品模板。
查看设备功能定义,也可以点击服务查看具体的定义属性,方法,事件。
Spec 理解可以参考 Spec 知识。
模组入门
一. 硬件连接
模组资料下载:模组页面。
引脚 | 功能描述 | |
---|---|---|
VDD | 3.3V 供电 (VDD) | |
EN | 芯片使能端,正常工作外部需拉高 | |
IO6/U1RXD | 与 MCU 主控通讯串口 RX | |
IO7/U1TXD | 与 MCU 主控通讯串口 TX | |
IO9 | "BOOT:外部拉低,用于 Flash 启动模式;外部拉高,用于 Download,此时 LOG_TX 和 LOG_RX 上电默认功能为烧录 UART" | |
LOG_TX | LOG 串口下载 TX | |
LOG_RX | LOG 串口下载 RX |
二. 工具准备
- 安装 secureCRT 或者 Putty 等串口调试工具,使用串口工具模拟 MCU 和模组通讯。
- CP2102 串口转 USB 板,以下简称串口板。
- 安装 CP2102 串口驱动,插上串口板,在设备驱动里面可以看到 COM 口,如果设备驱动出现感叹号,需要重新安装串口驱动程序。
三. 调试 log 打印
硬件接线方法:
- 查看 COM 口编号:打开设备管理器,查看命令和 log(USB 开发板:名字为 USB-SERIAL CH340)分别是第几个 COM 口。
- 设置串口参数。波特率: 115200 数据位: 8 奇偶校验: None 停止位: 1,注意:RTS/CTS 不要选。
- 查看重启打印信息 log,点击模组 USB 版"CHIP-EN"复位按键会出现以下 log
miio_client [6:100]
[ INFO] [08:00:00.198 ] miio_instance: skip auto_recovery...
[ INFO] [08:00:00.203 ] miio_client_func: OT agent listen fd: 4
[ INFO] [08:00:00.209 ] miio_client_func: BT conn listen fd: 5
[ INFO] [08:00:00.217 ] miio_client_func: netlink listen fd: 6
[ INFO] [08:00:00.224 ] miio_client: pollfds[0]: 4
[ INFO] [08:00:00.230 ] miio_client: pollfds[1]: 5
[ INFO] [08:00:00.236 ] miio_client: pollfds[2]: 6
[ DEBUG] [08:00:00.242 ] miio_client: miio_common init
mible_mesh_common_bt [14:100]
NSH auto exit.
[net_config_debug]:wifi scan finished, 4 25c829b1922d3123_miwifi found.
[net_config_debug]:bingo ssid=25c829b1922d3123_miwifi, bssid=56:D2:F5:EA:4B:8D, pri=1, rssi=-22
[net_config_debug]:wlan0 link up
四. MCU 通信
- 硬件接线:模组的 IO6, IO7 和 GND 接到串口板,串口板接到 PC 的 USB 口
- Wi-Fi log 串口与命令串口输出
[ 0.000000] [ INFO] NuttX RTOS Initializtion Entry
[ 0.000000] [ INFO] esp32c3_rng_initialize: Initializing RNG
[ 0.010000] [ INFO] Starting init thread
[ 0.010000] [ INFO] nsh: main entry
[ 0.020000] [ INFO] Fault Log info File No 1 Length 4057 flags:0x01 state:1
[ 0.020000] [ INFO] coexist rom version 9387209
[ 0.030000] [ INFO] pp rom version: 9387209
[ 0.030000] [ INFO] net80211 rom version: 9387209
[ 0.040000] [ INFO] CPU0: Beginning Idle Loop zblue [5:100]
[ 0.180000] [ INFO] I (190) wifi:[ 0.180000] [ INFO] Set ps type: 0
[ 0.180000] [ INFO] ifup wlan0...OK
[ 0.190000] [ INFO] [08:00:00.190 ] miio_instance: skip auto_recovery...
[ 0.190000] [ INFO] [08:00:00.190 ] miio_client_func: OT agent listen fd: 4
[ 0.200000] [ INFO] [08:00:00.200 ] miio_client_func: BT conn listen fd: 5
[ 0.200000] [ INFO] [08:00:00.200 ] miio_client_func: netlink listen fd: 6
[ 0.210000] [ INFO] [08:00:00.210 ] miio_client: pollfds[0]: 4
[ 0.220000] [ INFO] [08:00:00.220 ] miio_client: pollfds[1]: 5
[ 0.220000] [ INFO] [08:00:00.220 ] miio_client: pollfds[2]: 6
[ 0.230000] [ DEBUG] [08:00:00.230 ] miio_client: miio_common init miio_client
- 获取产品的 model 与 pid
模组基础设置 Log(串口命令没有反应?):
[ DEBUG] [08:16:21.150 ] tou: recv=get_down
[ DEBUG] [08:16:21.160 ] tou: send=down_none
[ DEBUG] [08:16:21.810 ] tou: recv=set_log_level 0
[ EMERG] set log level is 0
[ DEBUG] [08:16:21.820 ] tou: send=ok
[ DEBUG] [08:16:22.610 ] tou: recv=model perdev.switch.004
[ DEBUG] [08:16:22.620 ] ot: event emit[id=1,txt=otn.config,ext_len=28]
[ DEBUG] [08:16:22.620 ] tou: send=ok
[ DEBUG] [08:16:23.390 ] tou: recv=ble_config set 18031 0001
[ INFO] [08:16:23.400 ] mcmd: ble_config_msg_send
[ DEBUG] [D][rpc_agent] mible_rpc_delegate_down 949: down: 1 64 {"id":955057968,"method":"local.status","params":"wifi_ap_mode"}
[ DEBUG] [08:16:23.410 ] tou: send=ok
[ DEBUG] [D][] arch_log_handler 989: msg_len=64, msg={"id":955057968,"method":"local.status","params":"wifi_ap_mode"}
[ DEBUG] [08:16:24.140 ] tou: recv=mcu_version 0001
[ ERROR] [08:16:24.150 ] mcmd: device not bound, don't report otc.info.
[ DEBUG] [08:16:24.150 ] tou: send=ok
MCU 发送 | 模组回复 | ||
---|---|---|---|
测试命令 | get_down | down_none | 有回复正确的字符及命令口连接正确 |
设置 log 打印 | set_log_level 0 | OK | 0:代表 log 打印等级为 debug |
设置 model | model perdev.switch.004 | OK | perdev.switch.004: 设备 model(产品/基本信息) |
设置 PID | ble_config set 18031 0001 | OK | 18031 :设备 PID(产品/基本信息) |
设置 mcu version | mcu_version 0001 | OK | 0001 为 MCU 版本 |
具体命令格式参考:串口通讯协议
重启设备,串口工具输出下面 log 信息:
[ 0.910000] [ EMERG] _| _| _|_|_| _|_|_| _|_|
[ 0.910000] [ EMERG] _|_| _|_| _| _| _| _|
[ 0.910000] [ EMERG] _| _| _| _| _| _| _|
[ 0.920000] [ EMERG] _| _| _| _| _| _|
[ 0.930000] [ EMERG] _| _| _|_|_| _|_|_| _|_|
[ 0.930000] [ EMERG] JENKINS BUILD NUMBER: N/A
[ 0.940000] [ EMERG] BUILD TIME: Sep 22 2023,16:42:31
[ 0.940000] [ EMERG] BUILT BY: N/A.
[ 0.940000] [ EMERG] MIIO APP VER: 1.0.8
[ 0.950000] [ EMERG] MIIO MCU VER: 0001
[ 0.950000] [ EMERG] MIIO DID: 698485xxx
[ 0.960000] [ EMERG] MIIO WIFI MAC: d4f0ea292e02
[ 0.960000] [ EMERG] MIIO MODEL: model perdev.switch.004
[ 0.970000] [ EMERG] ARCH TYPE: ESP32C3,0x00000000
[ 0.970000] [ EMERG] ARCH VER : 9.1.0-RC1-202309221640
[ 0.980000] [ EMERG] FLASH INFO: manufacturer(0x20), memory type(0x40), capacity(0x16)
[ 0.980000] [ EMERG] CHIP WORK MODE: 0x01
[ 0.990000] [ EMERG] CHIP MODEL: xiaomi.dev.lx4
[ 0.990000] [ EMERG] CHIP VER: 1.0.8
[ 1.000000] [ EMERG] CHIP PKG TIME: Sep 22 2023,16:42:31
说明:
- MIIO App VER: 1.0.8 代表模组固件版本是 1.0.8
- MIIO MODEL: model perdev.switch.004 代表产品的 model
- MIIO DID: 698485xxx 是 DID(Device ID),由小米平台发放
设备配网
使用具有个人开发者权限的账号登录米家 App,并通过添加设备连接该模组,将该模组连上云端。(发现不了设备?)
设备控制
进入插件控制
命令 log
TX: get_down
RX: down set_properties 2 1 false
TX: result 2 1 0
// properties_changed 更新云端状态
TX: properties_changed 2 1 false
RX: ok
模组 log
// 插件控制开关
ots: {"from":"4","id":39950136,"method":"set_properties","params":[{"did":"698485xxx","piid":1,"siid":2,"value":true}]}.
ot: set_properties[id=39950136] is a ext methodmiio_ot: ext rpc recvd
miio_instance: miio_ext_rpc_hook_default called
tou: recv=get_down
mcmd: ext rpc[id=39950136]
mcmd: set_properties found
tou: send=down set_properties 2 1 true
miio_monitor: work time = 1566s, memory left = 42624
tou: recv=result 2 1 0
mcmd: state=1, timeout=3723, ts=1566145, now=1566196
ot: ot_down_rpc_delegate_ack_handle(), 510, malloc_len: 145, pload_len: 73
ot: ot_down_rpc_delegate_finish(), 423, id: 39950136, timestamp: 0, tick: 0, pload_len: 73
ots: ots_down_rpc_delegate_ack(), 243, ack: {"id":39950136,"result":[{"did":"698485xxx","siid":2,"piid":1,"code":0}],"exe_time":363}, len: 88
ots: rpc_cnt = 100[100], rpcack_cnt = 31[31], costtime = 18373[544,542]
// properties_changed 更新云端状态
tou: recv=properties_changed 2 1 false
tou: send=ok
miio_monitor: work time = 1896s, memory left = 42880
mcmd: 1 properties flushed
ots: ots_up_rpc_delegate_out_cb(), 348, {"id":967312993,"method":"properties_changed","params"[{"did":"698485xxx","siid":2,"piid":1,"value":false}]}
ots: recvd 39Bytes
ots: req or ack recvd.ots: {"id":967312993,"result":"ok"}.
小爱同学控制
语料:“打开开关”
命令串口
命令 log
TX: get_down
RX: down set_properties 2 1 true
TX: result 2 1 0
// properties_changed 更新云端状态
TX: properties_changed 2 1 true
RX: ok
MCU 程序开发
参考 Wi-Fi 通用模组开发。
参考 Wi-Fi 模组串口指令。
常见问题
参考 Wi-Fi 模组常见问题
上一篇:
下一篇: