cancel
Showing results for 
Search instead for 
Did you mean: 

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

DRobe.4
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

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

View solution in original post

4 REPLIES 4

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KnarfB
Principal III

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.4
Senior

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