Skip to main content
Stefan.Andon
Associate
January 15, 2022
Question

Receive UART messages in DMA

  • January 15, 2022
  • 7 replies
  • 1402 views

I am trying to receive messages in DMA mode, on a STM32L432KCU. The pins PA2 and PA3 are configured as DMA pins. The baudrate is 115200 and the global interrupt for USART2 is turned on. In the main function, I have the initialization of the peripherals:

MX_GPIO_Init();
MX_USART2_UART_Init();
MX_DMA_Init();

, which is followed by the functions that turn on the idle receive mode of the DMA and disable the half transfer interrupt:

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, UART2_rxBuffer, 12);
__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);

Here I have the callback:

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
 if(huart->Instance == USART2){
 memcpy(mainbuff, UART2_rxBuffer, Size);
 HAL_UARTEx_ReceiveToIdle_DMA(&huart2, UART2_rxBuffer, 12);
 __HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);
 }
 } 

It checks if the message is received from the second uart, then copies it into the main buffer, that stores all the data. The receive is enabled again and the half transfer interrupt is disabled. Unfortunately, when I am trying to debug, the breakpoint inside the callback never gets hit. I've also tried to display the message. It didn't work. What could cause this problem?

This topic has been closed for replies.

7 replies

TDK
January 15, 2022

Init DMA before UART.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Stefan.Andon
Associate
January 16, 2022

Thank you! I will try.

ST Technical Moderator
January 19, 2022

Hello @Stefan.Andon​ ,

Did you tried @TDK's proposal ​? Does it work ?

If yes, please mark his reply as Best answer (click on "Select as Best"). This will help other users find that answer faster.

Thanks

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Stefan.Andon
Associate
January 20, 2022

Hi, @Imen DAHMEN​ ,

Unfortunately, I was not able to test @ TDK's solution, as I don't have the hardware with me at the moment. I will respond as soon as I try.

Stefan.Andon
Associate
January 28, 2022

Hello,

Unfortunately it didn't solve the problem

waclawek.jan
Super User
January 28, 2022

Polled UART Rx works?

DMA works?

Some interrupt-related hints here.

Read out and check/post UART and DMA registers content, after having some data arrived at the Rx pin.

JW

ssipa.1
Visitor II
January 28, 2022

The pins PA2 and PA3 are configured as DMA pins" -- This makes no sense. DMA transfers do not occur at the SoC pins. The DMA transfers are between the main memory and the RX & TX data registers of the UART's host interface.