From b493e1045469f5161acbfb74a6ed31dc8ab9c4e5 Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 13 Aug 2026 17:43:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(vd960DBN):=20UART2=20=E7=B2=98=E5=B8=A7/che?= =?UTF-8?q?cksum=20fail=20=E2=80=94=20=E9=AB=98=E9=A2=91=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=85=B3=E4=B8=AD=E6=96=AD=E4=B8=A2=E5=AD=97=E8=8A=82=20+=20fl?= =?UTF-8?q?ag=20=E4=B8=8D=E6=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现场: LUP 帧后 checksum fail 刷屏 (坏帧: 7F 03 39 EF... 多帧拼接)。 根因链条: 1. LUP Rx 打印 190B @256000 = 7.4ms 关中断 (PRINT 临界区) → UART2(19200) RX 溢出丢字节 → 帧解析错位 → 粘帧 2. g_pkg_uart_2.flag 清理缺失: uart_srv 0xC0 分支不 InitPkgUart, tcp_json_push_sensor not authed 提前 return 也不清 → 坏帧反复处理 → checksum fail 刷屏 修复: - LUP Rx 打印 #if 0 (高频打印关中断是丢字节根因, 调试时开) - json_sensor_callback not authed 打印 #if 0 (每帧刷屏) - uart_srv 所有分支消费后统一 InitPkgUart (0xC0 + 非0xC0无BLE) - 顺带修 report disabled 双反斜杠 --- .../BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c | 6 +++++- vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c | 7 ++++++- vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/usart_biz.c | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c index 3c999d2..599c04d 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c @@ -687,7 +687,10 @@ void lup_process_frame(const uint8_t *pkg, uint16_t len) if (len < 6) { FAULT_MARKER(MK_LUP_FRAME_OUT); return; } // Debug: print raw (2026-08-13: 缓冲一次性输出 — 逐字节 PRINT 关中断 ~350us/字节 - // 会屏蔽 UART2 ISR 丢帧, 且高频打印放大 printf 重入窗口) + // 会屏蔽 UART2 ISR 丢帧, 且高频打印放大 printf 重入窗口。 + // 再关闭: 190B 打印 @256000 = 7.4ms 关中断 → UART2(19200) 溢出丢字节 → 粘帧! + // 需要调试时打开 #if 1) +#if 0 { char _hex[224]; int _p = snprintf(_hex, sizeof(_hex), "LUP Rx:"); @@ -696,6 +699,7 @@ void lup_process_frame(const uint8_t *pkg, uint16_t len) } PRINT("%s\n", _hex); } +#endif // --- Checksum --- csr = lup_verify_checksum(pkg, len); diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index 381711c..e1fbfb3 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -883,8 +883,13 @@ static void json_sensor_callback(const uint8_t *pkg, uint16_t len) // Check: socket active, authed, report enabled if (g_json_socket_listen == 0xFF) { PRINT("JSON: sensor_cb skip: no socket\n"); return; } + /* 2026-08-13: not authed 每帧打印太吵 (Loop MCU 高频上报), 且占用主循环 + 关中断窗口 → UART2 丢字节。调试时打开 */ +#if 0 if (g_json_auth_state != JSON_STATE_AUTHED) { PRINT("JSON: sensor_cb skip: not authed\n"); return; } - if (!g_report_cfg.enable) { PRINT("JSON: sensor_cb skip: report disabled\\n"); return; } +#endif + if (g_json_auth_state != JSON_STATE_AUTHED) { return; } + if (!g_report_cfg.enable) { PRINT("JSON: sensor_cb skip: report disabled\n"); return; } LUP_SensorReport sr; memset(&sr, 0, sizeof(sr)); diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/usart_biz.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/usart_biz.c index aeed38e..20db4d6 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/usart_biz.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/usart_biz.c @@ -174,12 +174,19 @@ void uart_srv(void) g_pkg_uart_2.pkg[0] = 0x8F; g_flag_notify_temp = set_response_tran_to_notify(g_pkg_uart_2.pkg, g_pkg_uart_2.offset, &g_notify_buftemp); // 保留给 BLE } - // else: 回调已推送 TCP,直接清理 + /* 2026-08-13 修复: 0xC0 帧消费后必须清 flag — + 原缺失, auth 未通过时 tcp_json_push_sensor 提前 return + 也不清 → 坏帧/正常帧反复处理 (checksum fail 刷屏) */ + InitPkgUart(&g_pkg_uart_2); } else { if(g_flag_bt_state){ g_flag_notify_temp = set_response_tran_to_notify(g_pkg_uart_2.pkg, g_pkg_uart_2.offset, &g_notify_buftemp); InitPkgUart(&g_pkg_uart_2); + } + else { + /* 2026-08-13 修复: 非 0xC0 + 无 BLE 连接也清 flag (原缺失) */ + InitPkgUart(&g_pkg_uart_2); } }