diff --git a/AGENTS.md b/AGENTS.md index 55b2fd2..ca8e8a4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,7 +5,7 @@ 本仓库是 **mothercup(母乳杯)** 产品的完整代码仓库,包含三大部分: 1. **设备固件** — 基于国民技术(Nations)**N32WB031 BLE SoC**(Cortex-M0,64MHz HSI,**板载硅片实测 256KB Flash**(0x01000000~0x0103FFFF,开发日志 §37),RAM 48KB+16KB): - - **`mcm-ddc-ble/`** — 唯一活跃的应用固件工程(APP,链接在 APP1 bank `0x01008000`/112KB)。以 SDK rdtss 例程为蓝本,集成 FreeRTOS、UART CLI、BLE 自定义 GATT 服务(CLI 透传 / 设备信息查询 / BLE OTA 双 bank 直写升级)、bootsetting 与 APP_DATA 参数区结构化读写命令。当前版本 **V1.00.22**(`mcm-ddc-ble/inc/app_version.h`)。历史上曾有 `mcm-ddc-04/` 主工程,**已删除**,其功能已全部并入本工程。 + - **`mcm-ddc-ble/`** — 唯一活跃的应用固件工程(APP,链接在 APP1 bank `0x01008000`/112KB)。以 SDK rdtss 例程为蓝本,集成 FreeRTOS、UART CLI、BLE 自定义 GATT 服务(CLI 透传 / 设备信息查询 / BLE OTA 双 bank 直写升级)、bootsetting 与 APP_DATA 参数区结构化读写命令。当前版本 **V1.00.23**(`mcm-ddc-ble/inc/app_version.h`)。历史上曾有 `mcm-ddc-04/` 主工程,**已删除**,其功能已全部并入本工程。 - **`Boot/`** — 自写精简 bootloader(链接在 `0x01000000`/16KB):校验 bootsetting 记录自身完整性(magic + 结构体 CRC32)后按 active bank 的 `start_address` 直接跳转;**不校验镜像 CRC(CRC 校验在 OTA 升级过程中完成)**;记录无效或地址越界回退 APP1。 2. **手机 App `SmartAssiter/`** — uni-app **Vue3 + TypeScript** 工程(HBuilderX 项目管理,无 package.json),通过 BLE 连接设备:查看运行参数(温度/电压/转速等)、CLI 终端、OTA 升级页(当前停用,见下)。另有登录/注册/用户信息等云端业务页面。 3. **PC 工具 `tools/`** — 整片烧录包制作/烧录脚本 + bleak 蓝牙测试客户端。 diff --git a/Boot/MDK-ARM/build.log b/Boot/MDK-ARM/build.log index 4c324cd..1d68b51 100644 --- a/Boot/MDK-ARM/build.log +++ b/Boot/MDK-ARM/build.log @@ -9,4 +9,4 @@ Program Size: Code=1320 RO-data=680 RW-data=0 ZI-data=2104 FromELF: creating hex file... After Build - User command #1: fromelf --bin --output=.\bin\caiic_boot.bin .\Objects\caiic_boot.axf ".\Objects\caiic_boot.axf" - 0 Error(s), 0 Warning(s). -Build Time Elapsed: 00:00:00 +Build Time Elapsed: 00:00:01 diff --git a/docs/开发日志.md b/docs/开发日志.md index 9acd789..b57524c 100644 --- a/docs/开发日志.md +++ b/docs/开发日志.md @@ -1159,3 +1159,15 @@ APP2 链接的镜像发向 APP1 区。设备端 END 校验(向量表 Reset PC 实测:修复后 UART OTA(APP2→APP1,V1.00.22)全程 PASS 并自动复核通过; 顺带修复了误刷进 APP1 区的内容。固件无改动(仅版本号 V1.00.21→V1.00.22)。 + +## 46. V1.00.23 + OTA 工具进度细化(2026-09-04,工具侧) + +- 固件版本号 V1.00.22→V1.00.23(0x00010017,无代码改动),供用户做 + BLE/UART OTA 全流程验证:两通道均 PASS(用户自测 BLE:APP1→APP2; + 本机复测 BLE:APP2→APP1,自动复核版本/bank 正确)。 +- `ble_ota_update.py` 进度显示细化:tty 下帧级进度条原地刷新(24 格 + bar + 百分比 + 字节数 + 速率 + 最近一帧 ACK 往返 rtt,~10fps 节流); + 非 tty(重定向/管道)自动退化为每 5% 一行,避免日志被 `\r` 刷乱。 + 重传/再同步提示前补换行不与进度条混行;END 总结新增 + `N resent, N resynced` 统计(链路质量一目了然:BLE 实测 0 次, + 接触不良的串口线 4~6 次)。BEGIN/END 阶段切换增加明示打印。 diff --git a/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble-app2.bin b/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble-app2.bin index a170ea2..eebc4b3 100644 Binary files a/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble-app2.bin and b/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble-app2.bin differ diff --git a/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble.bin b/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble.bin index da23815..b5077fa 100644 Binary files a/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble.bin and b/mcm-ddc-ble/MDK-ARM/bin/mcm-ddc-ble.bin differ diff --git a/mcm-ddc-ble/inc/app_version.h b/mcm-ddc-ble/inc/app_version.h index 2c4705e..8488cba 100644 --- a/mcm-ddc-ble/inc/app_version.h +++ b/mcm-ddc-ble/inc/app_version.h @@ -9,12 +9,12 @@ #define __APP_VERSION_H__ #ifndef APP_FW_VERSION -#define APP_FW_VERSION "V1.00.22" +#define APP_FW_VERSION "V1.00.23" #endif /* Numeric form used by the BLE info query / OTA records: 0x00MMmmpp */ #ifndef APP_FW_VERSION_NUM -#define APP_FW_VERSION_NUM 0x00010016u +#define APP_FW_VERSION_NUM 0x00010017u #endif #endif /* __APP_VERSION_H__ */ diff --git a/tools/ble_ota_update.py b/tools/ble_ota_update.py index 7bf6b86..b74da42 100644 --- a/tools/ble_ota_update.py +++ b/tools/ble_ota_update.py @@ -304,6 +304,9 @@ def decode_tlv(data): async def ota_session(xfer, chunk, blob, version, target): """Lockstep OTA: BEGIN -> DATA* -> END, every frame acked by OTA_RSP.""" + tty = sys.stdout.isatty() + state = {"resent": 0, "resynced": 0} + async def call(ftype, payload, ack_off=None): stage = {TYPE_OTA_BEGIN: "BEGIN", TYPE_OTA_DATA: "DATA", TYPE_OTA_END: "END", TYPE_OTA_ABORT: "ABORT"}.get(ftype, "?") @@ -315,7 +318,8 @@ async def ota_session(xfer, chunk, blob, version, target): rsp = await xfer(encode_frame(ftype, payload)) except asyncio.TimeoutError: if attempt < XFER_TRIES: - print(" %s: ack timeout, resending (attempt %d/%d)" + state["resent"] += 1 + print("\n %s: ack timeout, resending (attempt %d/%d)" % (stage, attempt + 1, XFER_TRIES)) continue raise asyncio.TimeoutError("%s: no OTA_RSP after %d tries" @@ -327,36 +331,68 @@ async def ota_session(xfer, chunk, blob, version, target): if echo != ftype: raise RuntimeError("%s: RSP echo 0x%02X != 0x%02X" % (stage, echo, ftype)) if ftype == TYPE_OTA_BEGIN and status == ST_BAD_STATE: + state["resynced"] += 1 print(" BEGIN: session already open on device, resynced") return ST_OK, offset if ftype == TYPE_OTA_DATA and status == ST_BAD_STATE \ and ack_off is not None and offset == ack_off: - print(" DATA: chunk already stored (ack was lost), resynced") + state["resynced"] += 1 + print("\n DATA: chunk already stored (ack was lost), resynced") return ST_OK, offset return status, offset + def progress(sent, total, t0, rtt_ms): + """Fine-grained progress: live-updating bar on a tty (throttled to + ~10 fps), one line per 5%% step when output is redirected.""" + now = asyncio.get_event_loop().time() + dt = now - t0 + pct = 100.0 * sent / total + rate = sent / 1024.0 / max(dt, 0.001) + if tty: + if sent != total and now - progress.last_draw < 0.1: + return + progress.last_draw = now + filled = int(pct / 100 * 24) + bar = "#" * filled + "-" * (24 - filled) + print(" [%s] %5.1f%% %d/%d B %.1f kB/s rtt %.0f ms " + % (bar, pct, sent, total, rate, rtt_ms), + end="\r" if sent != total else "\n", flush=True) + else: + step = int(pct // 5) + if sent == total or step != progress.last_step: + progress.last_step = step + print(" %d / %d bytes (%.0f%%, %.1f kB/s, rtt %.0f ms)" + % (sent, total, pct, rate, rtt_ms)) + + progress.last_draw = 0.0 + progress.last_step = -1 + + print("OTA_BEGIN: open session (%d bytes, crc32=0x%08X) ..." + % (len(blob), crc32(blob))) + t_begin = asyncio.get_event_loop().time() status, _ = await call(TYPE_OTA_BEGIN, struct.pack("