# UART: overrun error (ORE flag set) on USART2

- **ID:** `embedded/uart-overrun-error-sr-ore`
- **Domain:** embedded
- **Category:** runtime_error
- **Error Code:** `USART_SR_ORE`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

UART receive data register was not read before the next byte arrived, causing data loss due to overrun.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| STM32Cube FW_F4 V1.27.1 | active | — | — |
| STM32Cube FW_H7 V1.11.0 | active | — | — |
| Keil MDK-ARM 5.38 | active | — | — |

## Workarounds

1. **Enable DMA for UART reception: HAL_UART_Receive_DMA(&huart2, rx_buffer, BUFFER_SIZE); This offloads data transfer from CPU.** (85% success)
   ```
   Enable DMA for UART reception: HAL_UART_Receive_DMA(&huart2, rx_buffer, BUFFER_SIZE); This offloads data transfer from CPU.
   ```
2. **Implement double-buffering with interrupt: use HAL_UARTEx_ReceiveToIdle_DMA to capture data without overrun.** (80% success)
   ```
   Implement double-buffering with interrupt: use HAL_UARTEx_ReceiveToIdle_DMA to capture data without overrun.
   ```
3. **Increase interrupt priority of UART handler to ensure preemptive reading.** (70% success)
   ```
   Increase interrupt priority of UART handler to ensure preemptive reading.
   ```

## Dead Ends

- **Increase UART baud rate to match incoming data speed** — Overrun occurs because the CPU cannot read data fast enough; higher baud rate makes the problem worse, not better. (90% fail)
- **Disable UART interrupt and poll in main loop** — Polling without interrupt may miss data entirely or still overrun if main loop is slow. (70% fail)
