cancel
Showing results for 
Search instead for 
Did you mean: 

UART DMA TX occasional errors

Werner Dähn
Associate II

Once a while my Error_Callback() of the UART DMA RX/TX is triggered and I can't make sense out of it.

In the HAL_UART_ErrorCallback the values are

HAL_UART_GetState(huart) == 32 //  HAL_UART_STATE_BUSY_RX
HAL_UART_GetError(huart) == 16 // HAL_UART_ERROR_DMA 
huart->hdmarx->ErrorCode == 0 // NONE 
huart->hdmatx->ErrorCode == 2 // HAL_DMA_ERROR_FE means fifo error

Okay, so it is a FIFO error. I am not using FIFO. Any ideas?

        hdma_usart2_tx.Instance = DMA1_Stream6;
        hdma_usart2_tx.Init.Channel = DMA_CHANNEL_4;
        hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
        hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
        hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
        hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
        hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
        hdma_usart2_tx.Init.Mode = DMA_NORMAL;
        hdma_usart2_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
        hdma_usart2_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
        hdma_usart2_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
        hdma_usart2_tx.Init.MemBurst = DMA_MBURST_INC4;
        hdma_usart2_tx.Init.PeriphBurst = DMA_PBURST_INC4;
        if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
        {
          _Error_Handler(__FILE__, __LINE__);
        }
 
        __HAL_LINKDMA(huart, hdmatx, hdma_usart2_tx);

 Also I make sure that I do not call a transmit as long as the HAL_UART_TxCpltCallback() was not called and all transmits are in the main loop, not within an interrupt or callback.

4 REPLIES 4

This is a recurring question for years.

For explanation, see AN4031, chapter 4.3 Software sequence to enable DMA.

Simply ignore the error - if FIFO is not enabled, it's benign. The real solution is not to enable the FIFO error interrupt when DMA is in Direct mode; but that's probably on Cube's authors.

I don't Cube/CubeMX.

JW

Werner Dähn
Associate II

Okay. Is there any side effect when using DMA on four UARTs (2 RX+TX, 1 TX and 1 RX)? I have the feeling that I experience packet loss when these errors happen. At least I cannot get some parts working, currently trying to figure out if the problem is my code or the interaction with the remote device.

I expect DMA for UARTs, especially if the use 38400 and 115200 baud is essentially side effect free. Correct or wrong?

Race conditions

Reentrant behaviour

Failures in exit paths, and response to error conditions

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Werner Dähn
Associate II

:face_screaming_in_fear:

I hate micro controllers. ;)