Skip to main content
Visitor II
August 15, 2022
Question

STM32 Hal Uart RX randomly Freezes using DMA

  • August 15, 2022
  • 2 replies
  • 1563 views

Hey guys we are using the HAL Uart at 9600 Baud between our Bluetooth Board and Motion Sensor. We are using the DMA in non circular Buffer mode and then we have an actual Circular Buffer the Data goes into after the DMA. We are noticing randomly the Uart Rx freezes but everything else including Uart tx keeps working. We are re-initializing the DMA After call back.

This is the initialization.

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, dmaModemRxBuf, DMA_RX_BUF_SIZE);

This is our Call Back.

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)

{

if(huart->Instance == USART2){

for(int i = 0; i < Size; i++){

modemCircBufPush(&modemRxBuffer,dmaModemRxBuf[i]);

}

//use circ push the data into ring buffer

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, dmaModemRxBuf, DMA_RX_BUF_SIZE);

// __HAL_DMA_DISABLE_IT(&hdma_usart2_rx,DMA_IT_HT);

}else if(huart->Instance == USART1){

//SendMessageToDevice(0x07, 0x07);

for(int i = 0; i < Size; i++){

circBufPush(&deviceRxBuffer,dmaDeviceRxBuf[i]);

}

HAL_UARTEx_ReceiveToIdle_DMA(&huart1, dmaDeviceRxBuf, DMA_RX_BUF_SIZE);

//__HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT);

}

}

We commented out the Half Transfer Interrupt Disable thinking that might be the issue but it did not help. The Data coming in is of varying length and the RX buffer is 120 bytes. Doing Live Expression we can see the buffer is not filling up but the DMA stops responding.

Was curious if there were any known issues with this method.

Our MCU is the STM32G030F6Px

    This topic has been closed for replies.

    2 replies

    Graduate II
    August 15, 2022

    Your circular buffer fill looks incredibly inefficient.

    Either the DMA or the USART indicating a fault or error?

    How are the error cases handled?

    Could you light off the next transfer to a different buffer?

    Graduate II
    August 15, 2022

    Different interrupt priorities of the respective UART and DMA channel can brake this.