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
rp2: Reading pin value from IRQ hangs forver
bugport-rp2proposed-close
from machine import Pin, idle, disable_irq, enable_irq
from time import sleep_ms
pin = Pin(1, Pin.IN)
def on_change(pin):
state = disable_irq()
pin.value()
enable_irq(state)
pin.irq(on_change, Pin.IRQ_RISING | Pin.IRQ_FALLING)
for i in range(1000):
idle()
sleep_ms(100)
print("WORKING")
It seems impossible to read the value of the pin object passed as an argument to the callback. As soon as it is triggered the RPI Pico stop working until I unplug/replug it. Using the pin from the global context works or even recreating a new Pin instance, but not using the one passed as an argument
firmware: rp2-pico-20230116-unstable-v1.19.1-803-g1583c1f67.uf2