Knowledge Base

External interrupts

Could you guys help me out getting an external interrupt working? I tried using the gpio_cfg_extirq(), IRQ_PIN() and NVIC functions but all to no avail.

I suspect I need to enable something else besides just the IO pin, but I've been digging around the stack too long now trying to get it to work.
The next release of Basic MAC will contain a platform-independent unified external interrupt service (uexti) that simplifies the dispatching of such events to different consumers.

Until then, you can define your own custom EXTI handler that will be called by the stack after it handles its own events (mainly the DIO* lines to the radio chip) and use the STM32 HAL-specific functions to configure the interrupts.

To configure a GPIO line as input and receive interrupts, initialize it as follows:

#include "lmic.h"
#include "peripherals.h"

#define GPIO_EVENT        BRD_GPIO(PORT_B, 9) // event line on PB9

// configure GPIO as input/hi-z

// configure interrupt on both rising and falling edge
gpio_cfg_extirq_ex(BRD_PORT(GPIO_EVENT), BRD_PIN(GPIO_EVENT), true, true);

// enable interrupt
gpio_set_extirq(BRD_PIN(GPIO_EVENT), true);

Then, define a global function for the custom EXTI handler in your application, let's call it my_exti_handler:

void my_exti_handler (void) {
    // read EXTI->PR to get pending interrupts
    // handle pending interrupts, if any
    // don't forget to clear the handled ones in EXTI->PR

Last, you need to add your handler to the build environment by adding this line to your projects' Makefile:

LMICCFG += EXTI_IRQ_HANDLER=my_exti_handler

Hope that helps!
Thanks for your help! The entry in the makefile did the trick (I think I called the interrupt handler the wrong way previously). But we can move on now;)