cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple function for interrupt

SBaro.11
Associate III

Hi all,

I'd like to know if is ti possible to have multiple callback for interrupt. Beceause with HAL and CubeMX if I have multiple interrupt, I have only one function for callback

HAL_GPIO_EXTI_IRQHandler

example in stm32f4xx_it.c :

 

 

void EXTI0_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */

  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(B1_Pin);
  /* USER CODE BEGIN EXTI0_IRQn 1 */

  /* USER CODE END EXTI0_IRQn 1 */
}

/**
  * @brief This function handles EXTI line4 interrupt.
  */
void EXTI4_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI4_IRQn 0 */

  /* USER CODE END EXTI4_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(RFM_INT_Pin);
  /* USER CODE BEGIN EXTI4_IRQn 1 */

  /* USER CODE END EXTI4_IRQn 1 */
}

 

 

So if I want to have specific callback for EXTI4 there is a solution from CubeMx or not ?

Maybe :

void EXTI4_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI4_IRQn 0 */
  My_callback(RFM_INT_Pin);
  return;
  /* USER CODE END EXTI4_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(RFM_INT_Pin);
  /* USER CODE BEGIN EXTI4_IRQn 1 */

  /* USER CODE END EXTI4_IRQn 1 */
}
1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

@SBaro.11 HAL_GPIO_EXTI_IRQHandler is not a callback. It is a library handler of the EXTI interrupts. It then calls your callback that must be named HAL_GPIO_EXTI_Callback.

Some STM32 models can distinguish rising vs falling edge events and thus have two callbacks: HAL_GPIO_EXTI_Falling_Callback and HAL_GPIO_EXTI_Rising_Callback.

Cube and HAL library support only one EXTI callback. If you want anything else, just do what you like, in these callback functions or directly in USER CODE sections of the interrupt handlers.

 

View solution in original post

3 REPLIES 3
Andrew Neil
Evangelist III

Not all of the EXTI lines have unique interrupts; eg,

  • lines 5 - 9 all share an interrupt;
  • lines 10 - 15 all share an interrupt.

As there's only one interrupt, you can only have one handler.

The handler has to determine which of the lines caused the interrupt 

Pavel A.
Evangelist III

@SBaro.11 HAL_GPIO_EXTI_IRQHandler is not a callback. It is a library handler of the EXTI interrupts. It then calls your callback that must be named HAL_GPIO_EXTI_Callback.

Some STM32 models can distinguish rising vs falling edge events and thus have two callbacks: HAL_GPIO_EXTI_Falling_Callback and HAL_GPIO_EXTI_Rising_Callback.

Cube and HAL library support only one EXTI callback. If you want anything else, just do what you like, in these callback functions or directly in USER CODE sections of the interrupt handlers.

 

Muhammed Güler
Senior III

You can simply read pin states in the loop and in the interrupt. If the interrupt you read is 0 in the loop, and vice versa, you can find out which pin change triggered the interrupt.