fix(vd960DBN): BLE→Loop OTA 失效修复 — 0x9F 帧透传回 BLE
DMA 改造(fed4335)后 UART2 RX 走 lup_feed_byte 只认 0x7F, Loop bootloader
回的 0x9F 响应帧(pre_ok/addr_ok/data ACK)全被吞; OTA 是停等协议
(0xA7 WITH_BACK 每块必回 ACK), 工具等不到 ACK 升级必然卡死。
- loop_uart_proto: 新增 lup_feed_byte_ota() 0x9F 帧状态机 (SUM 校验无 XOR,
复用 g_lup_parser), 枚举追加 OTA 专用状态
- usart_biz: uart2_dma_poll 按 g_flag_counter_ota.flag 切换 0x9F/0x7F 解析器,
模式切换 reset, OTA 溢出阈值放宽整缓冲, 补收帧 tick 归零;
uart_srv OTA 分支 0x9F 帧透传回 BLE + 清 flag
- 单测 tests/test_lup_ota_parser.c 8 断言全过 (bootloader 真实帧向量)
- 遗留: g_flag_counter_ota.flag 无退出机制, 升级后需断电重启
This commit is contained in:
@@ -28,6 +28,7 @@ void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
static uint8_t uart2_dma_buf[UART2_DMA_BUF_LEN] __attribute__((aligned(4)));
|
||||
static uint16_t uart2_dma_last = 0; /* 主循环消费位置 (DMA 写指针由硬件维护) */
|
||||
static uint32_t uart2_dma_drop = 0; /* 溢出丢弃计数 (主循环消费不及时) */
|
||||
static uint8_t uart2_dma_ota_mode = 0xFF; /* 上次 OTA 模式 (0xFF=未初始化, 首轮强制 reset) */
|
||||
|
||||
void uart2_dma_init(void)
|
||||
{
|
||||
@@ -67,19 +68,33 @@ void uart2_dma_poll(void)
|
||||
|
||||
if (n == 0) return;
|
||||
|
||||
/* 溢出保护: 未消费 > 半缓冲 (256B) → 消费太慢被 DMA 覆盖, 重置解析器丢帧计数 */
|
||||
if (n > (UART2_DMA_BUF_LEN / 2)) {
|
||||
uart2_dma_drop++;
|
||||
/* 溢出保护: 未消费 > 半缓冲 (256B) → 消费太慢被 DMA 覆盖, 重置解析器丢帧计数
|
||||
2026-08-19: OTA 模式下 0x9F ACK 帧仅 7B, 停等协议同一时刻 Loop 至多回 1 帧,
|
||||
放宽阈值到整缓冲 — 256B 阈值在 TX 阻塞窗口可能误杀 ACK */
|
||||
{
|
||||
uint16_t drop_thr = g_flag_counter_ota.flag ? UART2_DMA_BUF_LEN : (UART2_DMA_BUF_LEN / 2);
|
||||
if (n > drop_thr) {
|
||||
uart2_dma_drop++;
|
||||
lup_frame_reset();
|
||||
uart2_dma_last = cur;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* OTA 模式切换 (0x7F ↔ 0x9F) 时重置帧解析器, 防旧模式残留状态污染 */
|
||||
if (g_flag_counter_ota.flag != uart2_dma_ota_mode) {
|
||||
lup_frame_reset();
|
||||
uart2_dma_last = cur;
|
||||
return;
|
||||
uart2_dma_ota_mode = g_flag_counter_ota.flag;
|
||||
}
|
||||
|
||||
while (n--) {
|
||||
uint8_t b = uart2_dma_buf[uart2_dma_last];
|
||||
uart2_dma_last = (uint16_t)((uart2_dma_last + 1) & (UART2_DMA_BUF_LEN - 1));
|
||||
|
||||
if (lup_feed_byte(b)) {
|
||||
/* OTA 模式走 0x9F 帧解析 (bootloader 的 pre_ok/addr_ok/data ACK),
|
||||
非 OTA 保持 0x7F 协议解析 */
|
||||
int done = g_flag_counter_ota.flag ? lup_feed_byte_ota(b) : lup_feed_byte(b);
|
||||
if (done) {
|
||||
/* 帧接收完成 → 复制到 g_pkg_uart_2 (与中断版同逻辑, 主循环无竞争) */
|
||||
const uint8_t *frame = lup_frame_data();
|
||||
uint16_t frame_len = lup_frame_len();
|
||||
@@ -90,6 +105,9 @@ void uart2_dma_poll(void)
|
||||
g_pkg_uart_2.tick = 0;
|
||||
}
|
||||
lup_frame_reset();
|
||||
} else if (g_lup_parser.state != LUP_FRAME_STATE_IDLE) {
|
||||
/* 收帧中 → tick 归零 (对齐中断版行为, 防 TIM3 半帧兜底误判) */
|
||||
g_pkg_uart_2.tick = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +291,14 @@ void uart_srv(void)
|
||||
}
|
||||
}
|
||||
else{
|
||||
// OTA 模式 — 忽略 Loop MCU 数据
|
||||
/* OTA 模式 (2026-08-19): Loop bootloader 回的 0x9F 帧
|
||||
(back_9F_pre_ok / addr_ok / data ACK) 透传回 BLE 工具,
|
||||
否则停等协议 (0xA7 WITH_BACK) 永远等不到 ACK */
|
||||
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);
|
||||
}
|
||||
/* OTA 模式同样清 flag — 残留帧会在 OTA 结束后被误处理 */
|
||||
InitPkgUart(&g_pkg_uart_2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user