Skip to main content
Explorer
March 7, 2025
Solved

UART3 and UART4 interrupts together

  • March 7, 2025
  • 1 reply
  • 381 views


Hi,

I am using UART3 and UART4 interrupts together in STM32G070RBT6TR processor and facing issues.
I have inserted my service routines as below.

/* USER CODE BEGIN USART3_4_IRQn 0 */
if((USART4->ISR & USART_ISR_TC_Msk) == USART_ISR_TC_Msk){

}

if((USART3->ISR & USART_ISR_TC_Msk) == USART_ISR_TC_Msk){

}
/* USER CODE END USART3_4_IRQn 0 */


It is possible that, both interrupts can occur any time. It may happen that, one interrupt (USART4) occur while other (USART3) is being served.
At the end of service routine both interrupts are getting cleared (with below functions created by CubeMX) and may miss the one which occur later.
HAL_UART_IRQHandler(&huart3);
HAL_UART_IRQHandler(&huart4);
Can you provide me some pointer how to handle this situation?
Thanks in advance.

BR
Narendra

    This topic has been closed for replies.
    Best answer by TDK

    You can either use the HAL callbacks as intended, or you can handle the flags yourself. Doing a mix is not possible, as you may miss flags as outlined in your post.

    The HAL callbacks will denote which flag was observed so that you can handle them there. The TC flag will cause the RX or TX complete callback to be called. I would recommend handling the TC flag in those callbacks.

    1 reply

    TDKAnswer
    Super User
    March 7, 2025

    You can either use the HAL callbacks as intended, or you can handle the flags yourself. Doing a mix is not possible, as you may miss flags as outlined in your post.

    The HAL callbacks will denote which flag was observed so that you can handle them there. The TC flag will cause the RX or TX complete callback to be called. I would recommend handling the TC flag in those callbacks.