cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure GPIO Interrupt with CubeMX

jarno
Associate III
Posted on July 03, 2014 at 08:02

Dear readers, how to configure a GPIO interrupt at port PG10 with CubeMX?

12 REPLIES 12
stm32cube-t
Senior III
Posted on July 21, 2014 at 17:16

Hello,

In the future please indicate the Microcontroller you selected for your project to facilitate support.

Click the GPIO pin on the chip view and select the signal GPIO_EXTI.

Go to the configuration tab, click the NVIC button and enable the interrupts for EXTI lines.

Best regards.

Posted on January 21, 2015 at 17:03

I am using an STM32F407 (on disco F4 boards).  It seems that when you select as suggested, the GPIO configuration for the pin in question stays at default event mode.  Doesn't it have to be changed to one of the Interrupt modes?  either Falling edge, rising edge or both?

tarzan2
Associate III
Posted on July 24, 2015 at 12:34

Actually it does NOT works with the latest version of cube MX (4.9). I'm using STM32F411 :

- I have configured input pins as EXTI 2, 3, 12 and 14 in the ''pinout'' tab

- The NVIC allow EXTI interrupts for lines 3 and [15:10], so due to a bug I not able to have interrupt on EXTI2. Since this line is connected to a hi-speed ADC DRDY signal, I will obviously NOT handle it in polling mode.

This is the third project in only one month that don't work because of a cubeMX bug. 

ST. time.wasted.
megahercas6
Senior
Posted on July 24, 2015 at 15:16

Same here, HAl and CubeMx is just paint to work with.

this is how i was able to make interrupt work. But funny part, no other interrupt is working, only this one, maybe luck ?

static void EXTI0_IRQHandler_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_0;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
}
void EXTI0_IRQHandler(void)
{
if((EXTI->PR&0x0001)==0x0001)
{
//todo
EXTI->PR = 0x0001;
}
}

But i don't know will it work for you
megahercas6
Senior
Posted on July 27, 2015 at 13:24

Ok, so i try to config PB12 interrupt, with no luck. Have no idea what is wrong. Original EXTI example in notfunctional all together.

here is SPL approach for F4:

void EXTI_Int(void)
{ 
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource12);
EXTI_InitStructure.EXTI_Line = EXTI_Line12;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x10;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line12) != RESET)
{
//ToDo
EXTI_ClearITPendingBit(EXTI_Line12);
}
}

Now this is what i am using right now, but it does not work.

void EXTI_Int(void)
{ 
uint32_t tmp = 0x00;
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_GPIOE_CLK_ENABLE();
//SPL approach registers that are not set here, but still nothing
//tmp = ((uint32_t)0x0F) << (0x04 * (0x0C & (uint8_t)0x03));
//SYSCFG->EXTICR[0x0C >> 0x02] &= ~tmp;
//SYSCFG->EXTICR[0x0C >> 0x02] |= (((uint32_t)0x04) << (0x04 * (0x0C & (uint8_t)0x03)));
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_12;
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
extern uint32_t program_counter;
void EXTI15_10_IRQHandler(void)
{
if((EXTI->PR&0x01000)==0x01000)
{
SPI_Config();
EXTI->PR = 0x01000;
}
}

megahercas6
Senior
Posted on July 28, 2015 at 11:15

So this is fun. Switching to STM32F7 , getting lot of problems, and not even single useful replay that solved my problem in multiple threads

So basically what STM did, is reduced community to people who only developing on they own.

LMI2
Lead
Posted on July 28, 2015 at 16:43

Have you Googled EXT1 or EXTI interrupts and so on. There are quite a lot of information and examples about EXT interrupts on ST ARM. I found some which looked useful for my own purposes, but I have not tested them yet.

megahercas6
Senior
Posted on July 28, 2015 at 18:00

i was googling alot. No examples wih HAL libraries.

This is what i don't like, with SPL i have tones of examples, and with HAL, only in CubeMx folder, but not all of them work, or doing what i need, like circular dma for spi

stm32cube-t
Senior III
Posted on July 30, 2015 at 16:29

Dear All,

This issue will be fixed in MX 4.

Please find attached C code for EXTI2 initialization on F4DISCOVERY (F407).

Best regards

________________

Attachments :

proj1.7z : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzQv&d=%2Fa%2F0X0000000bMq%2F_KSjHmaUivWMy2iY2WY7cYVBAmIfgtAoGl4Q2fPUyzI&asPdf=false