AttachInterrupt use for shared IRQ handlers

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
hreintke
Posts: 6
Joined: Thu Oct 15, 2020 10:53 am

AttachInterrupt use for shared IRQ handlers

Post by hreintke »

Hi,

I am new to STM32 but have experience with arduino framework in using esp8266 & esp32.
Using now a stm32f411ce

Question here is about interrupts/attachinterrupt.
I have read https://stm32f4-discovery.net/2014/08/s ... -tutorial/

This states : 16 interrupt lines but only 7 interupt handlers.

In STM32Duino I use attachInterrupt(pin, callback, type);

How is that handling f.e the
EXTI9_5_IRQn -> EXTI9_5_IRQHandler ->Handler for pins connected to line 5 to 9

Can I attach an interrupt callback to each of the 5-9 pins and the core handles that the correct one is called ?

Or is there only one callback active (the last attachInterrupt) ?
If so, is there a way to find out in the callback which of the pins initiated the interrupt /

Same question to f.e. PA0, PB0, PC0.
According to the documentation they are all connected to :
EXTI0_IRQn -> EXTI0_IRQHandler -> Handler for pins connected to line 0
by GonzoG » Thu Oct 15, 2020 11:47 am
I think that every thing is quite clearly explained on the site you linked.
All pins with same number are connected to line with same number. They are multiplexed to one line.

IMPORTANT: You can not use two pins on one line simultaneously:

PA0 and PB0 and PC0 and so on, are connected to Line0, so you can use only one pin at one time to handle interrupt from there.
You can use only one pin with the same number (eg. one of Px01) as interrupt pin.
And you can use pins 5-9 for different interrupts.
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: AttachInterrupt use for shared IRQ handlers

Post by GonzoG »

I think that every thing is quite clearly explained on the site you linked.
All pins with same number are connected to line with same number. They are multiplexed to one line.

IMPORTANT: You can not use two pins on one line simultaneously:

PA0 and PB0 and PC0 and so on, are connected to Line0, so you can use only one pin at one time to handle interrupt from there.
You can use only one pin with the same number (eg. one of Px01) as interrupt pin.
And you can use pins 5-9 for different interrupts.
hreintke
Posts: 6
Joined: Thu Oct 15, 2020 10:53 am

Re: AttachInterrupt use for shared IRQ handlers

Post by hreintke »

Yes, agree on the PA0, PB0 interrupts.

On the interrupt handlers for multiple lines I still have the question.

Within esp8266/esp32, the core handles splitting the one interrupt handler into multiple for the application.
It loops over the attached lines and calls the right callback.

Is that also done in the STM32 core ?

If not, is there a way that I can have an interrupt handler like this ?

Code: Select all

void inthandler_5_9()
{
	if (intline == 5) {...}
	else if (intline ==6) {...}
}
How would I know the correct line ?
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: AttachInterrupt use for shared IRQ handlers

Post by fpiSTM »

https://github.com/stm32duino/Arduino_C ... #L378-L384

Code: Select all

void EXTI9_5_IRQHandler(void)
{
  uint32_t pin;
  for (pin = GPIO_PIN_5; pin <= GPIO_PIN_9; pin = pin << 1) {
    HAL_GPIO_EXTI_IRQHandler(pin);
  }
}
IRQHandler is caller for all possible pin, then check if done per pin to call the HAL_GPIO_EXTI_Callback

Code: Select all

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
  /* EXTI line interrupt detected */
  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
  {
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  }
}
which callback you registered, one for each pin:

Code: Select all

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  uint8_t irq_id = get_pin_id(GPIO_Pin);

  if (gpio_irq_conf[irq_id].callback != NULL) {
    gpio_irq_conf[irq_id].callback();
  }
}

So simply attach interrupt with your callback.
Post Reply

Return to “General discussion”