Skip to main content
bnguy.1
Associate III
June 21, 2020
Solved

How to enable GPIO inputs for INTERRUPT MODE ?

  • June 21, 2020
  • 3 replies
  • 5112 views

The H745 Datasheet says General-purpose input/outputs : Up to 168 I/O ports with interrupt capability

Yet, every pin I select as GPIO (ex. PORTC.13 (PIN E3)), only lists INPUT or OUPUT options, but no Interrupt mode.

If I bypass the Stm32CubeIde 1.3.1's auto-code-generation, and forcefully initialize a GPIO to interrupt.. reading the PIN works, but the interrupt does not:

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_13;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
/* Enable and set EXTI lines 15 to 10 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
 
/* Configure the EXTI line for IT*/
HAL_EXTI_D1_EventInputConfig(EXTI_LINE13 , EXTI_MODE_IT, ENABLE);

How can I make any GPIO issue a interrupt?

This topic has been closed for replies.
Best answer by bnguy.1

Thanks, I hadn't noticed that GPIO_EXTI option! However, even selecting that, and setting it to Interrupt mode, it generates the same code as the snippet I had tried/posted.

I finally got it to work by adding this to stm32h7xx_it.c:

void EXTI15_10_IRQHandler(void)
{
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}

 The other GOTCHA, is that setting PE0 as GPIO_EXT will automatically remove that mode from PX0! I didn't realize but it seems all ports (A-I) share the 13 interrupts, i.e. for a given bit you can only have ONE interrupt for this bit across ALL ports! ex. PC0 interrupt means no PE0 interrupt available.

3 replies

TDK
June 21, 2020

When you click on a pin, there is a "GPIO_EXTIx" option. Select that. Set its context to the M7 or M4 core and enable the interrupt in NVIC. You'll get code similar to this (just an example):

static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOD_CLK_ENABLE();
 
 /*Configure GPIO pin : PD4 */
 GPIO_InitStruct.Pin = GPIO_PIN_4;
 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
 /* EXTI interrupt init*/
 HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(EXTI4_IRQn);
 
}

BTW, all pins can be configured to generate an interrupt, but not at the same time. You're limited to 1 per pin number.

"If you feel a post has answered your question, please click ""Accept as Solution""."
bnguy.1
bnguy.1AuthorBest answer
Associate III
June 21, 2020

Thanks, I hadn't noticed that GPIO_EXTI option! However, even selecting that, and setting it to Interrupt mode, it generates the same code as the snippet I had tried/posted.

I finally got it to work by adding this to stm32h7xx_it.c:

void EXTI15_10_IRQHandler(void)
{
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}

 The other GOTCHA, is that setting PE0 as GPIO_EXT will automatically remove that mode from PX0! I didn't realize but it seems all ports (A-I) share the 13 interrupts, i.e. for a given bit you can only have ONE interrupt for this bit across ALL ports! ex. PC0 interrupt means no PE0 interrupt available.

waclawek.jan
Super User
June 21, 2020

Or, read the EXTI and SYSCFG chapters in RM and set it up yourself.

JW