cancel
Showing results for 
Search instead for 
Did you mean: 

Receive UART messages in DMA

Stefan.Andon
Associate II

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?

7 REPLIES 7
TDK
Guru

Init DMA before UART.

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

Thank you! I will try.

Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Stefan.Andon
Associate II

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 II

Hello,

Unfortunately it didn't solve the problem

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
Associate II

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.