cancel
Showing results for 
Search instead for 
Did you mean: 

UART transmit DMA, receive interrupt

Hello dear friends,

I use F4 series MCUs. I am looking to send UART data via DMA and receive data in interrupt. How can I reach this goal? I am able to send data via DMA and receive data in interrupt, but the problem is in simultaneous use of DMA for data transmit and receive interrupt.

Sincerely yours

6 REPLIES 6
Simon.T
ST Employee

Hello,

It can be possible. Do you have some code to help you? ;)

Regards,

Simon

Tilen MAJERLE
ST Employee

What about transmitting AND receiving using DMA at the same time?

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

The matter is parsing input packets is more reliable in interrupt cases. In the case of DMA for receiving data, the interrupt will occur when a known number of bytes or half of that known number is received. But if one uses interrupt, one would not struggle with this limitation. The packet is supposed to be a long packet. Then using DMA for send will not block the program counter and receive interrupt will not lead to data loss.

There is way to overcome this problem. Have a look at the provided link before.

T J
Lead

Yes use the DMAs, Rx circular and Tx in Normal mode.

Full speed is no issue...

You can check the Rx DMA buffer pointer to see if a byte (or block) has arrived

set the Rx buffer to 1k or 4k as you need, I run a 16k Tx buffer, and move along it, when it get to 3/4 mark I move all unDMA'ed bytes back to the zero mark

Works very well...

Good Luck with that, its a huge set of code, I have sent it up here a couple of months ago...

 look for this Question:

STM32L476RG UART TX proccess via DMA without UART interrupt

Dear @Community member (Community Member)​ @Tilen MAJERLE (ST Employee)​ @Simon.T (ST Employee)​ 

Here is the MVP project that shows the issue. The project is built with STM32cubeMX 6.4 and STM32cubeF4 V1.26.2 and for stm32cubeIDE V1.8. Whenever a Uart DMA transfer is completed, a Uart transfer complete interrupt is generated which is not desired by me. If you review the code I have posted here, I have disabled the transfer complete interrupt in the beginning before the infinity loop (while(1)). How can I make it not generate a transfer complete interrupt? As far as I have searched in the STM32F407 series Reference manual RM0090, I have not found any clue that mentions when a DMA transfer makes an interrupt in hardware level.

After some investigating, I have found that in the function 

static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)

in the file "stm32f4xx_hal_uart.c" Line 2995

ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);

enable that notorious interrupt. Disabled that and altered the Uart soft status in the handle from busy to ready in the interrupt routine by 

if (huart2.gState != HAL_UART_STATE_READY)
	huart2.gState = HAL_UART_STATE_READY;

The if would be for later use to check if really the transfer complete was the source of interupt. 

I wonder if this scenario can be made through the stm32cubeMX