← index #18080PR #17781
Related · medium · value 2.699
QUERY · ISSUE

RP2040 PIO: Script fails on some GPIO numbers

openby peterhinchopened 2025-09-15updated 2026-03-25
bug

Port, board and/or hardware

RP Pico (RP2040)

MicroPython version

MicroPython v1.26.1 on 2025-09-11; Raspberry Pi Pico with RP2040

Reproduction

Link GPIO 1-17, attach a scope/LA to GPIO 2, and run the following:

from machine import Pin, PWM
import rp2
import time

inp = Pin(0, Pin.IN)
jmp = Pin(1, Pin.IN)
opp = Pin(2, Pin.OUT, value=1)
pwm = PWM(Pin(17))  # Link GPIO 17 to GPIO 1
pwm.freq(1000)
pwm.duty_u16(0xFFFF // 2)

@rp2.asm_pio(out_init=rp2.PIO.OUT_LOW) 
def sm_test():
    set(x, 0)
    wrap_target()
    wait(0, pins, 1)  # Wait for GPIO 1 to go low
    mov(osr, x)  # Ouput==0 while input==0
    out(pins, 1)
    label("loop")  # Loop until jump pin goes high
    jmp(pin, "pulse") 
    jmp("loop")
    label("pulse")
    mov(osr, invert(x))  # Emit a pulse
    out(pins, 1)
    mov(osr, x)
    out(pins, 1)
    wrap()

sm0 = rp2.StateMachine(0, sm_test, freq=100_000, out_base=opp , in_base=inp, jmp_pin=jmp)
sm0.restart()
sm0.active(1)
while True:
    time.sleep(1)
    print("Running")

Expected behaviour

Expected to output a single pulse on GPIO 2 after every positive going edge of GPIO 17.

Observed behaviour

As written, works as designed.

If the link is changed to link GPIO 17 and 14, and the code changed to read

inp = Pin(13, Pin.IN)
jmp = Pin(14, Pin.IN)

pulses are emitted all the time the input is high. If GPIO 1 is strapped to 3V3, pulses stop. Note GPIO 1 is not referenced in the code.

If GPIO 1 and GPIO 14 are linked it runs as designed. This behaviour continues after a power cycle!

Additional Information

RP2350 behaves similarly except that the sensitivity to GPIO 1 is lacking.

The decorator arg is necessary for the code to work. If this is intended it should be documented as this seems unexpected.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

rp2: on RP2350 configure jmp pins as input if they are in isolation mode

mergedby dpgeorgeopened 2025-07-29updated 2025-08-01
port-rp2

Summary

On RP2350, enable PIO jmp pins as input if they haven't already been configured. This allows them to work as input pins to the PIO. Otherwise the pin remains in isolation mode from reset and doesn't work as expected, in particular code that works on RP2040 does not work on RP2350.

Resolves issue #17047.

Testing

Tested with the code in #17047. Without the fix here the test fails (as described there). With the fix, it passes.

Trade-offs and Alternatives

The alternative would be to just document this. But I think a little bit of code to help things work "out of the box" makes it easier for users.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied