2025-10-20 8:15 AM - last edited on 2025-10-20 8:22 AM by mƎALLEm
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);
}
2025-10-20 8:23 AM
@asttekin wrote:USART DMA Receive doesn't work
What, exactly, does that mean?
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
2025-10-20 8:37 AM
No action.
No data reception.
No data completion.
Does it work reliably without DMA?
I haven't tried it.
2025-10-20 1:52 PM
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.