cancel
Showing results for 
Search instead for 
Did you mean: 

HAL UART DMA functions

sde c.1
Senior II

Hi,

I need a DMA setup for 4 separate UARTs in an STM32G473 controller. The idea is to always be able to receive data through rxDMA, and only invoke txDMA when sending data. The data that I receive changes in size, is between 20 and 300 bytes, starts with a start character, and stops with 2 CRC bytes. Considering this, I think the best way to go is using `HAL_UARTEx_ReceiveToIdle_DMA` and `HAL_UARTEx_RxEventCallback` as IDLE callback. Correct me if I'm wrong.

I wonder if I always need to execute `HAL_UARTEx_ReceiveToIdle_DMA` after I process the data? Or do I use `HAL_UARTEx_ReceiveToIdle_IT`?

I also noticed that `HAL_UARTEx_RxEventCallback` stops working after I receive a `HAL_UART_TxCpltCallback`. Are these interrupts linked to each other?
Do I need to use `HAL_UARTEx_ReceiveToIdle_IT` or `HAL_UARTEx_ReceiveToIdle_DMA` at the end of HAL_UART_TxCpltCallback to enable reception again?

I think it's odd that receiver callback interrupts are disabled after Tx complete callbacks. I'm afraid I'm losing receiving data this way. How do I make sure I do not lose any data on the serial ports?

Thanks!

 

 

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){ uint32_t head; uint8_t n; // process data ....for(n=0;n<port_end_of_list;n++) if(huart->Instance == uartbuffer[n].type) { HAL_UARTEx_ReceiveToIdle_DMA(.... } }

 




 

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){ uint8_t n; for(n=0;n<port_end_of_list;n++) { if(huart->Instance == uartbuffer[n].type) { HAL_UARTEx_ReceiveToIdle_DMA .... } } }

 

 

1 REPLY 1
Karl Yamashita
Principal

See this project https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki

 

I was told that if a devices starts to smoke, put the smoke back in. I guess I never got all the smoke because the device never worked afterwards.
Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.