cancel
Showing results for 
Search instead for 
Did you mean: 

trying to operate an external interrupt on stm32f031k6

deep_rune
Associate III

Im trying to operate an external interrupt on my STM32F031K6, using STM32cube IDE. Ive been following a tutorial here https://simonmartin.ch/resources/stm32/dl/STM32%20Tutorial%2007%20-%20GPIO%20Interrupts%20(EXTI)%20using%20HAL%20(and%20FreeRTOS).pdf but im not sure it really applies to my chip...

The first difference is although I have pins PA11 and PA12 setup for GPIO_EXTI11 and GPIO_EXTI12 in the cubemx, I in the setup preamble

  /*Configure GPIO pins : PA11 PA12 */
  GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

but i don't see anything like

/* EXTI interrupt init*/
 HAL_NVIC_SetPriority(EXTI4_15_IRQn, 3, 0);
 HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); 

as is mentioned in the tutorial, in fact there doesn't seem to be any mention of interrupts in the setup outside GPIO pa11 & pa12 setup - is this right?

Secondly, the file stm32f0xx_it.c doesn't contain the interrupt handler, it says in the file

/******************************************************************************/
/* STM32F0xx Peripheral Interrupt Handlers                                    */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_stm32f0xx.s).                    */
/******************************************************************************/

ok, no problem so i add the code

void EXTI0_1_IRQHandler(void)
{
	GPIOB->ODR ^= 1<<1;
}

but this doesn't do anything. There is no include for the stm32f0xx_it.c file including in main.c, but if i add it I get lots of errors. is this the correct interrupt handler?

any help much appreciated

1 REPLY 1
TDK
Guru

The correct interrupt handler for pins 11 and 12 is EXTI4_15_IRQHandler.

Don't #include a source file from another source file, the compiler/linker will take care of this.

If you configure all of this in STM32CubeMX as in the tutorial, it should be generating all of this code for you. Make sure you enable the interrupt generation in System Core -> NVIC -> NVIC -> EXTI linex interrupt.

If you feel a post has answered your question, please click "Accept as Solution".