← index #9325PR #11390
Off-topic · high · value 3.627
QUERY · ISSUE

rp2: rp2.asm_pio_encode incorrectly accepts 'pins' as src for 'wait'

openby ccanepaopened 2022-09-15updated 2026-03-19
bugport-rp2
  • https://docs.micropython.org/en/latest/library/rp2.html#module-rp2 specifies the pio asm syntax for 'wait' as
    wait(polarity, src, index) where 'src' one of (gpio, pin, irq)
  • The rp2040-datasheet.pdf similary uses (GPIO, PIN, IRQ)

The bug is that rp2.asm_pio_encode silently accepts the invalid src value 'pins'. It should raise an exception.

Incidentaly it encodes "wait(1, pins, 0)" the same as "wait(1, gpio, 0)"

demo code

import rp2
try:
    rp2.asm_pio_encode("wait(1, pins, 0)")
    exception_raised = False
except Exception:
    exception_raised = True

assert exception_raised
CANDIDATE · PULL REQUEST

rp2: Make rp2_state_machine_exec accept integers.

mergedby adamgreenopened 2023-05-01updated 2023-05-18
port-rp2

Currently rp2.StateMachine.exec(instr_in) requires that the instr_in parameter be a string representing the PIO assembly language instruction to be encoded by rp2.asm_pio_encode(). This commit allows the parameter to also be of integral type. This is useful if the exec() method is being called often where the use of pre-encoded machine code is desireable.

This PR still supports calls like:

    sm.exec("set(0, 1)")

It also now supports calls like:

    # Performed once earlier, maybe in __init__()
    assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0)
    # Performed multiple times later as the PIO state machine is
    # configured for its next run.
    sm.exec(assembled_instr)

I didn't find any rp2 specific tests to run or extend but I did find 2 rp2 examples (examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py) that exercise the rp2.StateMachine.exec() method. I ran those 2 examples to make sure that they weren't broken by my change.

I look forward to any feedback which helps improve this PR and its suitableness for merging.

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