简体   繁体   中英

Receive UART messages in DMA

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?

Try changing the order of the initialization procedures.

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

The DMA needs to be initialised prior to using the UART.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM