cancel
Showing results for 
Search instead for 
Did you mean: 

Resources for enabling interrupts and configuring GPIOs?

BSunw.1
Associate III

I am trying to enable some GPIO as external interrupts and have run the GPIO example where the user button is set as an interrupt. Is there any resources that show what GPIO can be used as external interrupts? For example, I would like to set one of the Arduino GPIO as an external interrupt pin if possible.

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

Every digital GPIO can be configured as external interrupt (EXTI) source. UM2534 User manual "Discovery kits with STM32MP157 MPUs" pin assignments or you might use STM32CubeMX for interactive pin planning.

View solution in original post

4 REPLIES 4
KnarfB
Principal III

Every digital GPIO can be configured as external interrupt (EXTI) source. UM2534 User manual "Discovery kits with STM32MP157 MPUs" pin assignments or you might use STM32CubeMX for interactive pin planning.

BSunw.1
Associate III

@KnarfB​ Thanks for the quick reply! I was trying to use the .ioc file to configure the GPIO pins that I wanted but the pin list was very limited. I included screen shots of the GPIOs that were listed. Then I looked at the GPIO example for the M4 projects and was planning on using the GPIO initialization function from that. The issue is where the example uses the USER_BUTTON_PIN for the interrupt configuration, I want to use different pins. Looking at the auto generated files in my project, I do not see pin definitions for Arduino pins or anything and cannot find anywhere online that states configuration details (like pin and port numbers) for those GPIO so that I could add them manually.

So if anyone knows of a simple way that I am overlooking to configure custom GPIOs please let me know!

static void EXTI14_IRQHandler_Config(void)
{
  GPIO_InitTypeDef   GPIO_InitStruct;
  EXTI_ConfigTypeDef EXTI_ConfigStructure;
 
 
  /* Enable GPIOA clock */
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  /* Configure PA.14 pin as input floating */
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Pin = USER_BUTTON_PIN;
  PERIPH_LOCK(GPIOA);
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  PERIPH_UNLOCK(GPIOA);
 
  /* Set configuration except Interrupt and Event mask of Exti line 14*/
  EXTI_ConfigStructure.Line = EXTI_LINE_14;
  EXTI_ConfigStructure.Trigger = EXTI_TRIGGER_FALLING;
  EXTI_ConfigStructure.GPIOSel = EXTI_GPIOA;
  EXTI_ConfigStructure.Mode = EXTI_MODE_C2_INTERRUPT;
  PERIPH_LOCK(EXTI);
  HAL_EXTI_SetConfigLine(&hexti, &EXTI_ConfigStructure);
  PERIPH_UNLOCK(EXTI);
 
  /* Register callback to treat Exti interrupts in user Exti14FallingCb function */
  HAL_EXTI_RegisterCallback(&hexti, HAL_EXTI_FALLING_CB_ID, Exti14FallingCb);
 
  /* Enable and set line 14 Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(EXTI14_IRQn, (DEFAULT_IRQ_PRIO + 2U), 0);
  HAL_NVIC_EnableIRQ(EXTI14_IRQn);
}

0693W000008yiGKQAY.png 

0693W000008yiGUQAY.png

KnarfB
Principal III

Lets say you find in the user manual Arduino connector that you want use pin PE10 as interrupt input. Enter PE10 in the search box bottom right of your screen shot, the matching pin(s) start blinking. Click on that pin and select GPIO_EXTI10 mode. Then, there appears a new entry in the GPIO list left. Select it to see or change the details. Now, if you right-click on that pin, you may give it a user name like "BLAST". Click also Pin Reserved and select Cortex-M4.

The user name appears as user label in the list and is used to generate two macros for your code:

(mian.h):

#define BLAST_Pin GPIO_PIN_10
#define BLAST_GPIO_Port GPIOE

Note that you could have directly used the generic names GPIOE and GPIO_PIN_10, but the user label assignment helps keeping track of all the pins and their modes.

Note also, that you can reconfigure already reserved pins. Then, you should check in the user manual and the schematics about the consequences.

hth

KnarfB

BSunw.1
Associate III

Thanks for your help!