2026-01-29 7:42 AM
hello
Description:
I'm currently working with the STM32U585 and encountered an issue related to USART3
Most of the time the code works fine, but it occasionally gets trapped in HAL_UART_IRQHandler
I am using the DMA Receiver Timeout (RTO) and DMA TX, may code is:
void uart_tx_complete_cb(UART_HandleTypeDef *huart)
{
if (...)
HAL_UART_Transmit_DMA(huart, buf, len);
}
void uart_rx_error_cb(UART_HandleTypeDef *huart)
{
HAL_UART_AbortReceive(huart);
if (huart->ErrorCode & HAL_UART_ERROR_RTO)
{
...
}
HAL_UART_Receive_DMA(huart, rx_buf, rx_buf_len);
}
HAL_UART_RegisterCallback(&huart3, HAL_UART_ERROR_CB_ID, uart_rx_error_cb);
HAL_UART_ReceiverTimeout_Config(&huart3, 100);
HAL_UART_EnableReceiverTimeout(&huart3);
HAL_UART_Receive_DMA(&TD_UART_HANDLE, rx_buf, rx_buf_len);
HAL_UART_RegisterCallback(&huart3, HAL_UART_TX_COMPLETE_CB_ID, uart_tx_complete_cb);
When the issue occurs, I found that the TC (Transmission Complete) flag is not being cleared:
and HAL_UART_IRQHandler return at /* End if some error occurs */
Solved! Go to Solution.
2026-02-09 12:25 AM
thank you all
I move HAL_UART_Transmit_DMA() out of uart_tx_complete_cb()
and use HAL_UARTEx_ReceiveToIdle_DMA() instead of HAL_UART_EnableReceiverTimeout()
to circumvent this issue, it seems to be working well
2026-01-29 7:59 AM
Hello @lll
Did you investigate why it is not clearing the TC flag inside HAL_UART_IRQHandler?
2026-01-29 4:14 PM
You restart the transfer on every tx complete, so TC flag will continue to get set. What makes you think it is stuck? Stepping through should let you see the logic where it gets cleared. TC flag doesn’t necessarily even need to be cleared.
If it “works most of the time”, problem is likely not with the logic inside the handler.
2026-01-29 7:56 PM
TC and TCIE are both set, and HAL_UART_IRQHandler returned before:
/* UART in mode Transmitter (transmission end) -----------------------------*/
UART_EndTransmit_IT
After problem occurs, any suspension will stop at HAL_UART_IRQHandler, I set a breakpoint in uart_tx_complete_cb, and never go in it
2026-02-03 1:53 AM
Hello @lll
Could you please share a minimal example to reproduce the issue ?
2026-02-03 2:03 AM
I think you can look up yourself which operations clear the TC flag.
However, consider your callback routine takes too long,and flag is already set again when it exists.
In this case, you need to move processing code out of the interrupt context.
2026-02-09 12:25 AM