← index #7903Issue #9325
Off-topic · high · value 0.379
QUERY · ISSUE

rp2 asm_pio parameterization

openby odewdneyopened 2021-10-15updated 2026-03-24
enhancementport-rp2

Hi,

I would like to pass parameters into the RP2 assembler to configure the generated code, eg adjust a delay loop, change number of bits shifted etc.

I propose an additional parameter to the asm_pio function decorator 'vars' that takes a dictionary, that gets added to the global context that assembler runs in eg:

@asm_pio(vars={"DELAY":10})
def statemachine():
  label("wait")
  set(x,DELAY)
  jmp(x_dec,"wait")

with an addition of gl.update(vars) in the asp_pio dec function

CANDIDATE · 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

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