diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c index 0f0941b..3c999d2 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c @@ -686,12 +686,16 @@ void lup_process_frame(const uint8_t *pkg, uint16_t len) if (len < 6) { FAULT_MARKER(MK_LUP_FRAME_OUT); return; } - // Debug: print raw - PRINT("LUP Rx:"); - for (i = 0; i < len; i++) { - PRINT(" %02X", pkg[i]); + // Debug: print raw (2026-08-13: 缓冲一次性输出 — 逐字节 PRINT 关中断 ~350us/字节 + // 会屏蔽 UART2 ISR 丢帧, 且高频打印放大 printf 重入窗口) + { + char _hex[224]; + int _p = snprintf(_hex, sizeof(_hex), "LUP Rx:"); + for (i = 0; i < len && _p >= 0 && _p < (int)sizeof(_hex) - 5; i++) { + _p += snprintf(_hex + _p, sizeof(_hex) - (size_t)_p, " %02X", pkg[i]); + } + PRINT("%s\n", _hex); } - PRINT("\n"); // --- Checksum --- csr = lup_verify_checksum(pkg, len); diff --git a/vd960DBN/SRC/Debug/debug.h b/vd960DBN/SRC/Debug/debug.h index ebead36..ca8e7bd 100644 --- a/vd960DBN/SRC/Debug/debug.h +++ b/vd960DBN/SRC/Debug/debug.h @@ -46,7 +46,16 @@ void USART_Printf_Init(uint32_t baudrate); void SDI_Printf_Enable(void); #if(DEBUG) - #define PRINT(format, ...) printf(format, ##__VA_ARGS__) + /* 2026-08-13 printf 重入修复: BLE 协议栈回调(peripheral.c, BB 中断上下文) + 与主循环都有 PRINT, 交叉调用 printf → 输出乱码 + 堆/状态破坏 → HardFault。 + 临界区用保存/恢复 MSTATUS: 中断里调用也能正确恢复, 不会嵌套误开中断。 + 注意: 高频逐字节 PRINT (如 LUP Rx hex) 会长时间关中断, 应改缓冲一次性输出 */ + #define PRINT(format, ...) do { \ + uint32_t _print_ms = __get_MSTATUS(); \ + __disable_irq(); \ + printf(format, ##__VA_ARGS__); \ + __set_MSTATUS(_print_ms); \ + } while(0) #else #define PRINT(X...) #endif