USART_SR_ORE
embedded
runtime_error
ai_generated
true
UART:USART1 上发生溢出错误,数据丢失
UART: overrun error on USART1, data lost
ID: embedded/uart-overrun-error
80%修复率
85%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| STM32Cube_FW_F4 v1.27.0 | active | — | — | — |
| FreeRTOS v10.4.6 | active | — | — | — |
| GCC ARM Embedded 12.2.1 | active | — | — | — |
根因分析
UART 接收缓冲区溢出,因为 CPU 未能在下一个字节到达前读取数据,通常由于高中断延迟或 DMA 缓冲不足。
English
UART receive buffer overrun because the CPU failed to read data before the next byte arrived, typically due to high interrupt latency or insufficient DMA buffering.
官方文档
https://www.st.com/resource/en/reference_manual/dm00031020-stm32f405-415-407-417-427-437-429-439-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf解决方案
-
启用 UART DMA 进行接收并使用环形缓冲区:配置 DMA 为外设到内存传输,设置缓冲区大小为 256 字节,并使用半传输/全传输中断处理数据。
-
增加 UART FIFO 阈值(如果硬件支持):设置 USART_CR3_DMAT 启用 DMA,或配置接收超时(RTO)定期刷新缓冲区。
-
降低其他外设的中断优先级,确保 UART ISR 及时执行:使用 NVIC_SetPriority(USART1_IRQn, 0) 设置最高优先级。
无效尝试
常见但无效的做法:
-
Increase UART baud rate to reduce data arrival rate
95% 失败
Higher baud rate increases data rate, worsening the overrun condition.
-
Disable UART interrupts and poll manually
80% 失败
Polling increases CPU load and may miss data entirely, leading to more overruns.
-
Add a delay in the UART ISR
90% 失败
Delays in ISR increase interrupt latency, causing more overruns.