0

I'm realizing UART-DMA with STM_HAL library and I want to know if message size is counted by hardware (counting clock ticks till line is idle for example) or by some program method(something like strlen). So if Size in

HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) 

is counted by hardware, I can send data in pure HEX format, but if it is calculated by something like strline, I may recieve problems if data is 0x00 and have to send data in ASCII.

I've tried to make some research in generated code in Keil but failed (maybe I didn't try hard enough) so maybe somebody can help me.

lazba
  • 129
  • 9
  • 1
    It's going to be the number of frames received. What may vary is whether invalid frames (missing stop bit, wrong parity, etc) set the corresponding error flag and also store a byte, or set the error flag without storing any byte. Transferring a binary zero byte will work just fine if it has the correct stop bit(s) (and if parity is enabled, the correct parity). Sending a zero continuously with no stop bits over UART is interpreted by the receiver as the "BREAK" event. – Ben Voigt Feb 01 '22 at 16:55

1 Answers1

1

If you are using UART DMA, it is calculated by hardware.

If you check the call hierarchy of HAL_UARTEx_RxEventCallback using your ide, you can see how the Size variable is calculated.

The function is executed in the following flow.(Depending on the version of HAL Driver, it may be slightly different)

  1. UART Idle Interrupt occur
  2. Call HAL_UART_IRQHandler()
  3. If DMA mod is enabled, Call HAL_UARTEx_RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount))

Therefore, Size variable is calculated as (huart->RxXferSize - huart->RxXferCount)

  • huart->RxXferSize is a set value when initializing RX DMA.
  • huart->RxXferCount is (huart->hdmarx)->Instance->NDTR

NDTR is a value calculated by hardware as the size of the buffer remaining after DMA transfer data to memory!!

YJ Kim
  • 56
  • 3