Pin Interrupt Priority RT1062

What interrupts have higher priority than pin Interrupt? Does timer or USB interrupt have a higher priority then pin interrupt? Is there a way to set the pin interrupt as the highest priority?

Use of the priority and hard keywords in Pin.irq cause TypeError: extra keyword arguments given

sensor_pin = Pin(‘P7’, mode=Pin.IN, pull=None)
sensor_int = sensor_pin.irq(handler=sensor_cb, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, priority=5)

Hi, the pin interrupt is pretty much the lowest: micropython/ports/mimxrt/irq.h at e6ad965cd3d4138b57329aecb752aec582a0033a · openmv/micropython · GitHub

We don’t support raising this to be higher. If the system is fairly idle when you receive that pin interrupt, it should be handled quickly.

Would it be possible to add the priority to the pin Interrupt? It looks like it is supported by micropython on the RT1062. The pin interrupt appears to be superceded by a timer interrupt that is causing issues.

Hi, it looks like the irq() method should support hard:

However, it doesn’t appear to do anything. All interrupts for pins are called directly and not scheduled: micropython/ports/mimxrt/machine_pin.c at e6ad965cd3d4138b57329aecb752aec582a0033a · openmv/micropython · GitHub

So, CSI and USB have a higher priority interrupt. The camera driver for the RT1062 interrupts the processor per line coming in from the camera. This is likely why you are seeing some sort of delay.

The camera interrupts need to be processed though otherwise the frame grabber will miss a line and have to drop a frame. Similarly, for USB, it’s important the processor is responsive to these.

What are you trying to do such that the interrupt on the rising edge has to have perfect timing?

Adding hard=True causes TypeError: extra keyword arguments

I’m using both timer interrupt and pin Interrupt and the timer interrupt appears to have a higher priority than the pin, but I need the pin to take priority.

Mmm, machine timers are all through the systick interrupt, which has the highest priority out of all interrupts. You definitely don’t want to change the systick priority.

So, I guess you need to see the pin interrupt while the timer interrupt is happening?

This is one of those priority inversion issues…

Can you use micropython.schedule() in the timer interrupt to defer the execution of the code in that interrupt out of interrupt time? This will then allow you to receive the pin interrupt because the timer interrupt will quickly exit.