cancel
Showing results for 
Search instead for 
Did you mean: 

On STM32L475 using UART4 with DMA ring buffer after calling function HAL_UARTEx_ReceiveToIdle_DMA UART generates frame error.

MZina.1
Associate

Sometimes DMA is setup prior to frame error interrupt, sometimes after frame error it is not clear to me why. Problem is when frame error is detected after dma is set up then "HAL_UART_IRQHandler" function executes "UART_DMAAbortOnError".

I can not detect if DMA is aborted or not because "HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)" in both cases returns 0 because in HAL_UART_IRQHandler this bit is reset before user HAL_UART_ErrorCallback function is called and error code is HAL_UART_ERROR_FE.

Why is frame error generated anyway?

This is snippet from HAL_UART_IRQHandler where DMA is aborted, and huart->ErrorCode is allways HAL_UART_ERROR_FE.

if ((HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) ||
          ((errorcode & (HAL_UART_ERROR_RTO | HAL_UART_ERROR_ORE)) != 0U))
      {
        /* Blocking error : transfer is aborted
           Set the UART state ready to be able to start again the process,
           Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
        UART_EndRxTransfer(huart);
 
        /* Disable the UART DMA Rx request if enabled */
        if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
        {
          CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
 
          /* Abort the UART DMA Rx channel */
          if (huart->hdmarx != NULL)
          {
            /* Set the UART DMA Abort callback :
               will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */
            huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError;
 
            /* Abort DMA RX */
            if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
            {
              /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */
              huart->hdmarx->XferAbortCallback(huart->hdmarx);
            }
          }else
          {
            /* Call user error callback */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
            /*Call registered error callback*/
            huart->ErrorCallback(huart);
#else
            /*Call legacy weak error callback*/
            HAL_UART_ErrorCallback(huart);
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */

1 REPLY 1
MZina.1
Associate

I got it, RX pin was low. This is why frame error is generated.