From eb2b27ddbcd41103d9194bb5fc48888e86e48288 Mon Sep 17 00:00:00 2001 From: helei Date: Sat, 22 Aug 2026 12:45:11 +0800 Subject: [PATCH] =?UTF-8?q?V1.5:=20485=E6=8E=92=E9=9A=9C=E5=8A=A0=E5=B8=A7?= =?UTF-8?q?=E6=8F=90=E4=BA=A4/=E7=BC=93=E5=86=B2=E4=B8=A2=E5=BC=83?= =?UTF-8?q?=E4=B8=A4=E6=9D=A1=E6=97=A5=E5=BF=97(=E5=AE=9A=E4=BD=8D9?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E5=8E=BB=E5=90=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- V1.5/STM32F103_App1/HardWare/UART/uart.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/V1.5/STM32F103_App1/HardWare/UART/uart.c b/V1.5/STM32F103_App1/HardWare/UART/uart.c index 735e50e..9f5f818 100644 --- a/V1.5/STM32F103_App1/HardWare/UART/uart.c +++ b/V1.5/STM32F103_App1/HardWare/UART/uart.c @@ -1,5 +1,6 @@ #include "uart.h" #include "network.h" +#include "log.h" #include "hlw8032.h" #include #include @@ -274,6 +275,12 @@ uint16_t USART2_GetRxIndex(void) { return uart2_cmd_index; } /* void USART2_FlushRxBuf(void) { + if (uart2_cmd_index > 0) { + char hex[3 * 24 + 1] = {0}; + uint16_t n = uart2_cmd_index < 24 ? uart2_cmd_index : 24; + for (uint16_t i = 0; i < n; i++) snprintf(hex + i * 3, 4, "%02X ", uart2_cmd_buf[i]); + log_warn("> UART2: 清缓冲丢弃 %d 字节: %s", (int)uart2_cmd_index, hex); + } uart2_rx_ready = 0; uart2_cmd_index = 0; /* 兜底:接收中断意外停摆时(ORE 后状态卡 BUSY_RX)拉起来。不 Abort,不动正常状态 */ @@ -366,6 +373,11 @@ void USART2_Tick(void) { if (uart2_cmd_index > 0 && (HAL_GetTick() - uart2_last_rx_tick) > UART2_CMD_TIMEOUT_MS) { + /* 排障:帧提交时打印内容(485 丢帧定位) */ + char hex[3 * 24 + 1] = {0}; + uint16_t n = uart2_cmd_index < 24 ? uart2_cmd_index : 24; + for (uint16_t i = 0; i < n; i++) snprintf(hex + i * 3, 4, "%02X ", uart2_cmd_buf[i]); + log_info("> UART2: 帧提交 %d 字节: %s", (int)uart2_cmd_index, hex); uart2_rx_ready = 1; } }