USART_SR_ORE
embedded
runtime_error
ai_generated
true
UART:USART2 上溢出错误(ORE 标志已设置)
UART: overrun error (ORE flag set) on USART2
ID: embedded/uart-overrun-error-sr-ore
85%修复率
88%置信度
1证据数
2023-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| STM32Cube FW_F4 V1.27.1 | active | — | — | — |
| STM32Cube FW_H7 V1.11.0 | active | — | — | — |
| Keil MDK-ARM 5.38 | active | — | — | — |
根因分析
UART 接收数据寄存器未能在下一个字节到达前被读取,导致数据因溢出而丢失。
English
UART receive data register was not read before the next byte arrived, causing data loss due to overrun.
官方文档
https://www.st.com/resource/en/reference_manual/dm00031020.pdf解决方案
-
Enable DMA for UART reception: HAL_UART_Receive_DMA(&huart2, rx_buffer, BUFFER_SIZE); This offloads data transfer from CPU.
-
Implement double-buffering with interrupt: use HAL_UARTEx_ReceiveToIdle_DMA to capture data without overrun.
-
Increase interrupt priority of UART handler to ensure preemptive reading.
无效尝试
常见但无效的做法:
-
Increase UART baud rate to match incoming data speed
90% 失败
Overrun occurs because the CPU cannot read data fast enough; higher baud rate makes the problem worse, not better.
-
Disable UART interrupt and poll in main loop
70% 失败
Polling without interrupt may miss data entirely or still overrun if main loop is slow.