fix(vd960DBN): IWDG 无条件启用+喂狗 — 卡死兜底 (卡死定位闭环)

现场: 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 定位卡死点
This commit is contained in:
wangfq
2026-08-13 16:15:26 +08:00
parent ee3ade6f00
commit 4bdf8a7993
4 changed files with 8 additions and 0 deletions
@@ -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__ */
@@ -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 同内容) */
@@ -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) =====
@@ -19,6 +19,7 @@
#include "simple_json.h"
#include "storage.h"
#include "offlog.h"
#include "fault_diag.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -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);