QUERY · ISSUE
rp2: Crash with hard pin IRQ
bugport-rp2
Measuring hard IRQ latency with this script:
from machine import Pin, PWM
from time import sleep_ms
import math
# Link 16-17, time 16-18
pin18 = Pin(18, Pin.OUT)
def callback(_):
pin18(1) # Trigger
pin18(0)
pin17 = Pin(17, Pin.IN)
_ = pin17.irq(callback, trigger=Pin.IRQ_RISING, hard=True)
pwm = PWM(Pin(16))
pwm.freq(1000)
pwm.duty_u16(0xffff // 2)
while True:
y = 0
for x in range(100):
y += math.sin(x * 2 * math.pi/100) # 6.2ms of busywork
sleep_ms(10)
The usual latency was a creditable 25μs, but I have measured 100μs. It was not practicable to measure a worst case because the the machine suffers a hard crash usually almost immediately. If I comment out the busywork, leaving just the sleep_ms(10), it runs indefinitely with about 20μs latency.
CANDIDATE · ISSUE
Crash on RP2 with pin IRQ's
bugport-rp2
The problem has appeared on nightly builds since 20th Dec. This build fails: rp2-pico-20230120-unstable-v1.19.1-831-g4f3780a15.uf2. The following is the smallest repro I've come up with so far:
import uasyncio as asyncio
from machine import Pin
class Encoder:
def __init__(self):
pin_x = Pin(20, Pin.IN, Pin.PULL_UP)
pin_y = Pin(17, Pin.IN, Pin.PULL_UP)
self._x = 0
self._y = 0
self._v = 0
trig = Pin.IRQ_RISING | Pin.IRQ_FALLING
pin_x.irq(trigger=trig, handler=self._x_cb, hard=False)
pin_y.irq(trigger=trig, handler=self._y_cb, hard=False)
def _x_cb(self, pin_x):
print('x')
if (x := pin_x.value()) != self._x: # Crash seems to occur here
pass
def _y_cb(self, pin_y):
print('y')
if (y := pin_y.value()) != self._y: # or here
pass
async def main():
e = Encoder()
while True:
await asyncio.sleep(1)
print(e._v)
asyncio.run(main())
When either pin changes state the ISR prints then the board crashes. If I reduce the ISR's to just a print statement the code runs. Note hard and soft IRQ's behave similarly.