cancel
Showing results for 
Search instead for 
Did you mean: 

Two UART DMA transmissions in a row.

Steven Bébin
Associate III

Hello,

I am currently working on a project which requires the use of the transmission / reception of a UART by DMA. I would like to make two transmissions in a row like the following.

void send_all_registers()
{
	HAL_UART_Transmit_DMA(&huart2, (unsigned char*)"Start of the transmission of registers\r\n", 40);	
	HAL_UART_Transmit_DMA(&huart2, (unsigned char*)"End of the transmission of registers\r\n", 38);
}

When I am under the debugger, we observe the first successful transmission, but the second transmission fails because the gState UART is BUSY. However, I have the following code for set the flag ready.

void USART2_IRQHandler(void)
{
	HAL_UART_IRQHandler(&huart2);
}

The problem is that the USART2_IRQHandler() function is not called between the two transmissions. I do not understand why. Do you know why ?

Edit : When I call the HAL_UART_IRQHandler(&huart2) function between the two transmissions, the function refuses to put the flag ready because the transmission is not "finished". But yet it is not !?

Thanks,

Steven

4 REPLIES 4
RMcCa
Senior II

I don​'t use hal, but it looks like it's working properly. The uart is busy because it hasn't finished transmitting the last message. You need to poll for the dma ntdr = 0 and uart tx buffer empty before restarting the process to send another string. I don't think this is the correct way to use dma as the processor needs to sit & wait for the transfer to complete.

Danish1
Lead II

To clarify what RMcCa said, we use DMA (or interrupts) in order to let the cpu get on with other things while the (very slow, in computer terms) USART transmission takes place.

The HAL library seems unhelpful in that it doesn't queue up the second transfer while the first one is running. But from a programmer's point of view that's a fairly complicated thing to do. If you don't mind waiting while the USART transmissions take place, try HAL_USART_Transmit()

Hope this helps,

Danish

Steven Bébin
Associate III

Thanks a lot for your answers.

It was not an obligation to transmit in DMA. So it works perfectly as you told me with HAL_USART_Transmit().

Miles1
Associate III

I had the same issue, and found the fix was to enable HAL_UART_IRQHandler()

See this thread for more details:

https://community.st.com/s/question/0D50X00009XkgtY/dma-uart-with-hal-remain-busy-bug