Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
F4_HAL/uart: Fix data loss when using DMA Rx with hardware flow control.
Data loss can occur when using DMA Rx + hardware flow control. Consider the following situation where a device is receiving UART data that consists of one byte that gives the size of the data followed by "size" bytes: - MCU requests to read one byte from UART by calling HAL_UART_Receive_IT() - The remote may or may not have already sent the byte, but it doesn't matter, this works correctly. - After the UART_Receive_IT() callback, the MCU requests to read "size" bytes by calling HAL_UART_Receive_DMA(). - If the remote has not sent the next byte yet, then all is well, but it could have sent the next byte already, which is waiting in the DR register. The RTS line will be high which prevents the remote from sending any more data, so no overrun will occur. But since __HAL_UART_CLEAR_OREFLAG() reads the DR register, this byte will be lost and the DMA read will read one extra byte from the incoming stream causing the algorithm to get out of sync. This adds a check to see if flow control is enabled and only calls __HAL_UART_CLEAR_OREFLAG() if flow control is disabled. This should prevent breaking users who aren't using flow control and may already depend on this behavior.
- Loading branch information