USART_SR_ORE
embedded
runtime_error
ai_generated
true
UART: overrun error (ORE flag set) on USART2
ID: embedded/uart-overrun-error-sr-ore
85%Fix Rate
88%Confidence
1Evidence
2023-11-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| STM32Cube FW_F4 V1.27.1 | active | — | — | — |
| STM32Cube FW_H7 V1.11.0 | active | — | — | — |
| Keil MDK-ARM 5.38 | active | — | — | — |
Root Cause
UART receive data register was not read before the next byte arrived, causing data loss due to overrun.
generic中文
UART 接收数据寄存器未能在下一个字节到达前被读取,导致数据因溢出而丢失。
Official Documentation
https://www.st.com/resource/en/reference_manual/dm00031020.pdfWorkarounds
-
85% success Enable DMA for UART reception: HAL_UART_Receive_DMA(&huart2, rx_buffer, BUFFER_SIZE); This offloads data transfer from CPU.
Enable DMA for UART reception: HAL_UART_Receive_DMA(&huart2, rx_buffer, BUFFER_SIZE); This offloads data transfer from CPU.
-
80% success Implement double-buffering with interrupt: use HAL_UARTEx_ReceiveToIdle_DMA to capture data without overrun.
Implement double-buffering with interrupt: use HAL_UARTEx_ReceiveToIdle_DMA to capture data without overrun.
-
70% success Increase interrupt priority of UART handler to ensure preemptive reading.
Increase interrupt priority of UART handler to ensure preemptive reading.
中文步骤
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.
Dead Ends
Common approaches that don't work:
-
Increase UART baud rate to match incoming data speed
90% fail
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% fail
Polling without interrupt may miss data entirely or still overrun if main loop is slow.