Skip to main content
Visitor II
May 3, 2023
Solved

STM32G0 USART3 and USART4 share an interrupt. How to deal with it?

  • May 3, 2023
  • 3 replies
  • 2648 views

void USART3_IRQHandler(void) is incorrect, since USARTs 3/4 share the interrupt, it doesn't compile. What replaces 'USART3' in the interrupt handler?

NVIC_ClearPendingIRQ(USART3_IRQn); is incorrect since USART3 3/4 share the interrupt. What replaces 'USART3_IRQn' so that the NVIC_ClearPendingIRQ will compile?

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

    The interrupt handler names are defined in the startup code, like in startup_stm32g070xx.s:

    .word USART1_IRQHandler /* USART1 */
    .word USART2_IRQHandler /* USART2 */
    .word USART3_4_IRQHandler /* USART3, USART4 */

    If you create code with UART 3/4 interrupts enabled, you find the code in stm32g0xx_hal_msp.c:

    HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART3_4_IRQn);

    Those defines are from CMSIS like stm32g070xx.h.

    The generated code is correct and does compile without errors.

    hth

    KnarfB

    3 replies

    Graduate II
    May 3, 2023

    You check and service both peripherals and the flags should clear.

    I​ think in one of the recent threads it establishes the combined symbol and number for the IRQ. Grep the library source or truncate the Handler name seen in startup.s

    Graduate II
    May 3, 2023

    YOUR thread here ​https://community.st.com/s/question/0D53W00002FEy7wSAD/i-there-a-usart3irqn-and-a-usart4irqn-on-stm32g070

    KnarfBAnswer
    Super User
    May 3, 2023

    The interrupt handler names are defined in the startup code, like in startup_stm32g070xx.s:

    .word USART1_IRQHandler /* USART1 */
    .word USART2_IRQHandler /* USART2 */
    .word USART3_4_IRQHandler /* USART3, USART4 */

    If you create code with UART 3/4 interrupts enabled, you find the code in stm32g0xx_hal_msp.c:

    HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART3_4_IRQn);

    Those defines are from CMSIS like stm32g070xx.h.

    The generated code is correct and does compile without errors.

    hth

    KnarfB

    DRobe.4Author
    Visitor II
    May 4, 2023

    Everyone, thanks for your help... compiles, so I presume that it will work.