cancel
Showing results for 
Search instead for 
Did you mean: 

what happen if I call more than once HAL_UART_Receive_DMA API before Rxcpltcallback of first call?

Mr.L0seR
Associate II

I am using STM32F407VG. I am transmitting data from PC to STM32 using uart. I wrote the code to receive 100 bytes. Firstly I call the HAL_UART_Receive_DMA more than once and then I sent the data from PC to STM32.I observed it receives only 100 bytes,means only one time DMA is receiving the data. except in first call, In remaining calls it is HAL_UART_STATE_BUSY_RX state. So what happen when already Rx process is ongoing(HAL_UART_STATE_BUSY_RX)?

5 REPLIES 5
TDK
Guru

It returns HAL_BUSY without doing anything else.

HAL code is included in your project. It's easily inspected.

If you feel a post has answered your question, please click "Accept as Solution".
Piranha
Chief II

Theoretically it will return "busy" error, but in real life sooner or later it will fail in some way because __HAL_LOCK() is not thread-safe. That is what you get when the code is made by brainless code-monkeys...

Only if you call it within multiple interrupts or threads. If it’s only called in the main loop or only within a single interrupt, there is no issue.
If you feel a post has answered your question, please click "Accept as Solution".

Indeed, but it will be pretty ugly code to implement it in a way that HAL_UART_Receive_DMA() is called only from one of those contexts.

Anyway this approach is architecturally dumb and sub-optimal as a whole. Normally receive is implemented in such a way that it is started only once and then, when the callback informs that there is some new data received, main code gets the new data from the driver.

So there is no use of those remaining Receive calls in HAL_BUSY state.