STM32F4 UART HAL Driver

后端 未结 6 1131
北荒
北荒 2021-01-30 04:49

I\'m trying to figure out how to use this new HAL driver. I want to receive data using the HAL_UART_Receive_IT() which sets up the device to run an interrupt functi

6条回答
  •  清歌不尽
    2021-01-30 05:05

    Receiving data while the Data Register (DR) is full will result in an overrun error. The problem is that the function UART_Receive_IT(UART_HandleTypeDef*) will stop reading the DR register once it has received enough data. Any new data will cause the overrun error.

    What I did was to rather use a circular DMA receive structure. You can then use currentPosInBuffer - uart->hdmarx->Instance->NDTR to determine how much data was received that you haven't processed yet.

    It is a little bit more complicated because while the DMA does the circular buffering itself, you have to manually implement the loopback to the beginning if you go past the end of the buffer.

    I have also found a glitch where the controller says it has transferred the data (i.e. NDTR has decreased) but the data is not yet in the buffer. It may be some DMA/bus access contention issue, but it is annoying.

提交回复
热议问题