From 4bdf8a7993f121017771cb26e5e5b916d6fb183b Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 13 Aug 2026 16:15:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(vd960DBN):=20IWDG=20=E6=97=A0=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=90=AF=E7=94=A8+=E5=96=82=E7=8B=97=20=E2=80=94=20?= =?UTF-8?q?=E5=8D=A1=E6=AD=BB=E5=85=9C=E5=BA=95=20(=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E9=97=AD=E7=8E=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现场: printf 重入修复后乱码消失, 但 LUP 帧处理卡死(连 JSON: sensor_cb enter 都没打印), 且 iot_enable=0 模式 IWDG 未初始化 (iot_mqtt_poll 才喂狗, tcp_json 分支不喂) → 卡死永久冻结无兜底。 修复: - main 无条件 iot_watchdog_init() (IWDG 4s 超时) - 主循环 while 开头无条件 iot_watchdog_kick() (原只在 iot_mqtt_poll) - json_sensor_callback / iot_evt_sensor_cb 加 FAULT_MARKER(MK_EVT_CB_IN/OUT) 效果: 卡死 → 4s IWDG 复位 → 上电 FAULT_DIAG 打印 marker 定位卡死点 --- .../BLE/OnlyUpdateApp_Peripheral/APP/include/iot_mqtt_srv.h | 1 + vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c | 2 ++ vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/peripheral_main.c | 3 +++ vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/iot_mqtt_srv.h b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/iot_mqtt_srv.h index 27fc883..62aa77e 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/iot_mqtt_srv.h +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/iot_mqtt_srv.h @@ -52,6 +52,7 @@ void iot_mqtt_poll(void); // 主循环轮询 (状态机 + 心跳 + void iot_mqtt_handle_sock_int(uint8_t socketid, uint8_t intstat); // Socket 中断处理 void iot_mqtt_publish_sensor(void); // 推送传感器数据到 MQTT void iot_evt_handle_ack(uint32_t msg_id, int code); // event_report 平台应答入口 (V1.04) +void iot_watchdog_init(void); // 初始化硬件 IWDG (无条件, 主循环卡死兜底) void iot_watchdog_kick(void); // 喂硬件 IWDG (主循环调用) #endif /* __IOT_MQTT_SRV_H__ */ diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c index 1ca60d5..061646e 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c @@ -177,10 +177,12 @@ static void iot_sensor_ingest(const LUP_SensorReport *sr) { /* lup 传感回调: uart_srv 消费路径的帧从这里喂入 (lup_process_frame 已过校验) */ static void iot_evt_sensor_cb(const uint8_t *pkg, uint16_t len) { LUP_SensorReport sr; + FAULT_MARKER(MK_EVT_CB_IN); memset(&sr, 0, sizeof(sr)); if (lup_parse_sensor_report(pkg, len, &sr) == 0) { iot_sensor_ingest(&sr); } + FAULT_MARKER(MK_EVT_CB_OUT); } /* 序列化并发布队列头 n 条事件 (首发与重发共用: 同 id/ts 同内容) */ diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/peripheral_main.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/peripheral_main.c index 2d78f9e..25bcd2a 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/peripheral_main.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/peripheral_main.c @@ -302,6 +302,7 @@ void Main_Circulation(void) while(1) { FAULT_MARKER(MK_LOOP_TOP); + iot_watchdog_kick(); /* 无条件喂狗 (2026-08-13): 原只在 iot_mqtt_poll, tcp_json 分支不喂 */ TMOS_SystemProcess(); if(g_net_state.flag < 2) @@ -380,6 +381,8 @@ int main(void) 每次上电必打, 区分看门狗死锁 vs 掉电 vs 外部复位 */ PRINT("RST_REASON: 0x%08lx\n", (unsigned long)OFFLOG_RCC_RSTSCKR); fault_diag_init(); /* 打印上次复位现场 (HardFault mcause/mepc + 执行轨迹 marker) */ + iot_watchdog_init(); /* 无条件 IWDG (2026-08-13): iot_enable=0 时 iot_mqtt_init 不调, + 卡死无兜底 → 永久冻结。IWDG 4s 超时 + 主循环喂狗 */ PRINT("%s\n", VER_LIB); PRINT("SystemCoreClock:%d\n", SystemCoreClock); /* ===== 实验: 禁用全部 Flash/SPI 操作 (2026-08-12) ===== diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index 1774eaa..ee17cdb 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -19,6 +19,7 @@ #include "simple_json.h" #include "storage.h" #include "offlog.h" +#include "fault_diag.h" #include #include #include @@ -872,6 +873,7 @@ static int format_loop_param_json(char *buf, uint16_t buf_size, const LUP_ParamG static void json_sensor_callback(const uint8_t *pkg, uint16_t len) { + FAULT_MARKER(MK_EVT_CB_IN); PRINT("JSON: sensor_cb enter socket=%d auth=%d report=%d\n", g_json_socket_listen, g_json_auth_state, g_report_cfg.enable);