cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEMX didn't create correct EXTI code for GPIO pin.

Richard Li
Associate II

I use STM32CUBEMX 5.5.0 create code for Nucleo-G474RE, when I set PIN PC2 to GPIO_EXTI2, after create code, the code didn't create correct code, only create two lines for EXTI15_10_IRQn​, how EXTI15_10_IRQn can handle PC2?

5 REPLIES 5
berendi
Principal

EXTI15_10_IRQn can't handle PC2/EXTI2, but EXTI2_IRQHandler() can.

Clear the pending flag in EXTI->PR1, and do whatever you want to do in the handler.

void EXTI2_IRQHandler() {
  EXTI_PR1 = EXTI_PR1_PIF2;
  /* user code goes here */
}

Of course as CubeMX failed to generate code for the interrupt handler, you cannot assume it has managed to generate correct code for the rest (you should never trust generated code, CubeMX fails at it more often than not), so the first thing you should do is to verify with a debugger whether the interrupt handler above is actually called. If not, verify the following registers

  • GPIO MODER register is set to input
  • GPIO IDR is reflecting the actual state of the pin
  • SYSCFG->EXTICR maps PC2 to EXTI2
  • At least one edge is selected for EXTI2 in EXTI->RTSR1 or FTSR1
  • Interrupt mask for EXTI2 is set in EXTI->IMR1
  • EXTI2_IRQn interrupt is enabled in NVIC
  • interrupts are enabled in general
Richard Li
Associate II

​Hello Berendi,

Thank you very much for this information!

I use one STM32Cube example code change as you noticed, it is work, but still something wrong, the EXTI-PR1 can't clear for some reason.

The NVIC in ST document is very badly, I check ARM CM4 program manual , looks I need set more NVIC register, I did set NVIC->ICER[0], the EXTI->PR1 still keep.

Regards,

Richard

The flag in NVIC should be cleared by hardware when EXTI->PR1 is cleared in the interrupt handler.

Verify that the bits for EXTI2 in SYSCFG->EXTICR are set for PC2, and check the signal on the pin for noise.

Richard Li
Associate II

​Hello Berendi,

I set GPIO with PU, (I use falling interrupt) it is better.

But there are two question I can't fig out:

  1. The NVIC->ISER[0] have to set to 0x100 for GPIOC2, do you know where I can find the STM32G474 NVIC registers map?
  2. Even I change code for EXTI2_IRQHandler() only, no EXTI15_10_IRQ anymore, the compiler keep use EXTI15_10_IRQHandler() under SysTick_Handler

Attached my test file.

Richard Li
Associate II