cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UARTEx_RxEventCallback Received Data Size Wrong?

nobbyv77
Associate II

Using an STM32L0x0, and with the DMA a HAL_UARTEx_ReceiveToIdle_DMA call to receive 6 bytes. DMA is configured for 8-bit data size on both the peripheral and memory size (MSIZE and PSIZE in DMA_CCR are both 0x00).

However, the RxEventCallback seems to be counting in half-words, despite the actual transfer seemingly working: i.e., I get 6 bytes in my destination buffer which has 1-byte elements, but Size = 3. This holds for any number of bytes I attempt to transfer.

What am I missing?

1 REPLY 1
Karl Yamashita
Lead II

Well when you call HAL_UARTEx_ReceiveToIdle_DMA it initializes UART_DMAReceiveCplt and UART_DMARxHalfCplt callbacks. So when you received half of the data that you are originally are expecting, you will get a half callback interrupt. When you get the second half of the data bytes you'll get the next complete callback.

If you want HAL_UARTEx_RxEventCallback to interrupt on the 6 bytes, then set HAL_UARTEx_RxEventCallback to receive 12 bytes. That way it'll interrupt on half callback.

If you set HAL_UARTEx_RxEventCallback for more than 12 bytes but only receive 6 bytes then the idle interrupt will still call HAL_UARTEx_RxEventCallback

If you find my answers useful, click the accept button so that way others can see the solution.