class ExtInt – configure I/O pins to interrupt on external events

STM32 MCUs split the external interrupt controller (EXTI) into two ranges: lines 0-15 are driven from GPIO pins, and the lines above 15 are tied to internal sources (RTC alarm, RTC wakeup, USB wakeup, etc.). The total line count and the mapping of internal lines above 15 are MCU-specific; consult the EXTI section of the reference manual for the OpenMV Cam’s MCU for the exact assignments.

Each GPIO line N can be driven by pin PxN on any one GPIO port at a time – for example line 0 may map to PA0, PB0, PC0 or any other port-A through port-K pin 0, but only one at a time.

Example:

def callback(line):
    print("line =", line)

extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)

Every falling edge on pin then invokes callback. ExtInt automatically configures the GPIO line as an input; you do not need to do that yourself.

Note

Mechanical pushbuttons “bounce” and a single press or release often generates multiple edges. See for example this debouncing primer for techniques.

Registering two callbacks on the same pin raises an exception.

If pin is passed as an integer it is assumed to identify one of the internal interrupt lines and must be >= 16 and below the MCU’s total EXTI line count. Any other pin value is resolved through the standard pin mapper.

In addition to the IRQ_* modes there are EVT_RISING, EVT_FALLING and EVT_RISING_FALLING event modes that route a transition to the processor’s event input (used with the WFE instruction for low-power wait). The EVT_* modes do not invoke the Python callback and are intended for sleep / power-management use; ordinary application code should use the IRQ_* modes.

Constructors

class pyb.ExtInt(pin: int | str | Pin, mode: int, pull: int, callback: Callable[[int], None])

Create an ExtInt object.

Class methods

classmethod regs() None

Dump the contents of the EXTI peripheral registers (for debugging).

Methods

disable() None

Disable the interrupt associated with this ExtInt object. Useful for software debouncing.

enable() None

Re-enable an interrupt previously disabled with disable().

line() int

Return the EXTI line number this object is mapped to.

swint() None

Trigger the callback from software (as if the configured edge had occurred on the line).

Constants

IRQ_RISING: int

Trigger an interrupt on a rising edge. The Python callback runs.

IRQ_FALLING: int

Trigger an interrupt on a falling edge. The Python callback runs.

IRQ_RISING_FALLING: int

Trigger an interrupt on either edge. The Python callback runs.

EVT_RISING: int

Route a rising edge to the Cortex event input. No Python callback is invoked; intended for use with the WFE instruction in low-power code.

EVT_FALLING: int

Route a falling edge to the Cortex event input. No Python callback is invoked.

EVT_RISING_FALLING: int

Route either edge to the Cortex event input. No Python callback is invoked.