Skip to main content
Graduate
October 20, 2025
Question

F103C8 USART DMA Issue

  • October 20, 2025
  • 2 replies
  • 241 views

Hi,

I'm having the following issue with the F103C8 USART DMA.
After reset, sometimes the USART DMA Receive doesn't work. It doesn't happen every time, but it happens about once every 10 resets.

HAL_UARTEx_ReceiveToIdle_DMA(&huart1, (uint8_t *)RxDataUsart1, 128);
__HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT);

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, (uint8_t *)RxDataUsart2, 128);
__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
	if(huart == &huart1)
	{
		timer_UART1_Datalost = millis();
		uart_1_Ready	= SET;
		__HAL_UART_CLEAR_FEFLAG(&huart1);
		memcpy(copyRxDataUsart1, RxDataUsart1, 128);
		copyRxDataUsart1[127] = '\0';
		usart1Datareceived = 1;

		for (int i=Size; i < 128; i++)RxDataUsart1[i]=0;
	}
	__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
	HAL_UARTEx_ReceiveToIdle_DMA(&huart1, (uint8_t *)RxDataUsart1, 128);
	__HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT);

	if(huart == &huart2)
	{
		uart_2_Ready	= SET;
		__HAL_UART_CLEAR_FEFLAG(&huart2);
		memcpy(copyRxDataUsart2, RxDataUsart2, 128);
		copyRxDataUsart2[127] = '\0';
		usart2Datareceived = 1;
		for (int k=Size; k < 128; k++)RxDataUsart2[k]=0;
	}
	__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
	HAL_UARTEx_ReceiveToIdle_DMA(&huart2, (uint8_t *)RxDataUsart2, 128);
	__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);

}

 

    This topic has been closed for replies.

    2 replies

    Super User
    October 20, 2025

    @asttekin wrote:

    USART DMA Receive doesn't work


    What, exactly, does that mean?

    • It receives nothing ?
    • It receives something - but incomplete ?
    • It receives something - but corrupt ?
    • Other ?
    • A combination of the above ?

     

    Does it work reliably without DMA ?

     

    Please show a minimum but complete example which illustrates the issue.

     

    How to write your question to maximize your chances to find a solution

    asttekinAuthor
    Graduate
    October 20, 2025

    No action.
    No data reception.
    No data completion.

    Does it work reliably without DMA?
    I haven't tried it. 

    Super User
    October 20, 2025

    Hi,

    what speed you have on uart ?  many Mbit ?

    or: why DMA here ? 

    +

    The problem here is probably : what you do, if a spike sets the uart to an error condition?

    Without clearing the error, nothing happens - until you clear it.

    Seems this is the "problem" here.

    So include some useful error handling, or do it in INT mode, clearing an error, if it happens.

    Then you get reliable uart communication.