Skip to main content
Senior
Question

USART DMA Receive Complete Callback Conflict?

I am using an STM32F072B-DISCO board as an interface between two serial data streams. I have USART4 operating at 1.5 MBit/s and USART1 operating at 115,200 Bits/s. I am using both in DMA mode to avoid blocking code. 

 

This is the initialisation:

 

And the callback for when serial data is received:

 

I am using port PC12 to indicate when a byte is received as shown below:

 

 

So the receive complete callback routine is definitely being executed (PC12 is connected to D2 on the logic analyser trace), but no data is being sent out on USART1 (D8). i have the normal selections set in STM32CubeMX for USART DMA operation per the below.

If I enable the code in the main While loop, then the Hello! messages are continuously sent out. My hunch is that USART DMA transmission isn’t possible within the receive complete callback routine, is this the case please? If so, else can I try please?

I also tried using HAL_UART_Transmit_IT() to send out the Hello! messages from within the callback routine, but with the same result -  no data is transmitted.

 

 

 

 

 

3 replies

gbm
Super User

The code above likely use USART4 but the peripheral configured is USART3. Anyway, HAL UART services are close to useless in real life since every Receive call disables the reception after completion.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
TDK

​@alw 

That code won’t even compile given the screenshots. huart4 is not initialized. Are you sure you’re looking at the right project?

My hunch is that USART DMA transmission isn’t possible within the receive complete callback routine, is this the case please?

That is not the case. You can send data within the rx complete callback. However, if tx data is already being sent, the call will fail. You should check for this.

 

​@gbm 

Anyway, HAL UART services are close to useless in real life since every Receive call disables the reception after completion.

HAL_UART_ReceiveToIdle_* with a circular buffer will continuously receive data. The reception is never disabled. Callbacks happen at idle, half- and full-transfer complete.

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

DMA callback conflicts can be tricky to debug. Check whether multiple UART receive handlers are sharing the same callback or DMA channel, and verify that the interrupt configuration is correct.