Skip to main content
Mike Hooper
Associate III
Jul 16, 2021 4:34 PM UTC
Solved

UART Framing Error immediately after initializing DMA transfer

I am using the UART4 in DMA mode. But as soon as I initialize the UART in RX mode, I get a framing error that calls the HAL_UART_ErrorCallback Error _Handler which halts the program. Below is my init code.

/* UART4 init function */
void UART4_Init(void)
{
	UartReady = false;
	huart4.Instance = UART4;
	huart4.Init.BaudRate = 115200;
	huart4.Init.WordLength = UART_WORDLENGTH_8B;
	huart4.Init.StopBits = UART_STOPBITS_1;
	huart4.Init.Parity = UART_PARITY_NONE;
	huart4.Init.Mode = UART_MODE_TX_RX;
	huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
	huart4.Init.OverSampling = UART_OVERSAMPLING_16;
	huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
	huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
	if (HAL_UART_Init(&huart4) != HAL_OK)
	{
		Error_Handler();
	}
 
	UartReady = false;
	GPIO_Set_RS485_TXEN(0);
	HAL_UART_Receive_DMA( &huart4, UART_RX_Buffer, cmdLen);
}

The error occurs at the last line (HAL_UART_Receive_DMA().

How do I prevent this error?

Guidance appreciated....

This topic has been closed for replies.
Mike Hooper
Mike HooperBest answer
Associate III
Jul 16, 2021 5:39 PM UTC

Thanks Pavel. It was a hardware problem. works fine now.

2 replies

Pavel A.
Jul 16, 2021 4:55 PM UTC

Does framing error occur if you receive without DMA?

If yes, does it persist after 1st byte?

What if you just ignore framing errors in few first bytes?

--pa

Mike Hooper
Mike HooperAuthorBest answer
Associate III
Jul 16, 2021 5:39 PM UTC

Thanks Pavel. It was a hardware problem. works fine now.