← index #7117PR #11390
Off-topic · high · value 0.270
QUERY · ISSUE

rp2 import PIO, StateMachine, asm_pio -> Info -> Black Cat in a Coal Bunker

openby kevindawsonopened 2021-04-13updated 2021-08-20
  • μpython v1.14 on 2021-04-09 (GNU 10.2.0 MinSizeRel)

from - Raspberry Pi Pico Python SDK (2021-04-07)
The idea is that for the 4 sets of pins ( in , out , set , sideset , excluding jmp ) that can be connected to a state machine,
there’s the following that need configuring for each set:

Sample code:

from rp2 import PIO, StateMachine, asm_pio
from machine import Pin

@asm_pio(set_pins=(PIO.OUT_LOW, PIO.OUT_HIGH,  PIO.IN_LOW), sideset_pins=PIO.OUT_LOW)
def foo():
    pass

sm0 = StateMachine( 0, foo, freq=2000, set_pins=Pin(15), sideset_pins=Pin(22))

it just produces errors

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "rp2.py", line 230, in asm_pio
TypeError: unexpected keyword argument 'set_pins'

I can find info -> machine -> https://docs.micropython.org/en/latest/library/machine.html
but info for rp2 -> null

looking in the rp2 stubs - StateMachine

def __init__(self, id, prog, freq: int=-1, *, in_base: Pin=None, out_base: Pin=None, set_base: Pin=None, jmp_pin: Pin=None, sideset_base: Pin=None, in_shiftdir: int=None, out_shiftdir: int=None, push_thresh: int=None, pull_thresh: int=None):

Ureka - moment - there NO set_pins in StateMachine instantiation

from rp2 import PIO, StateMachine, asm_pio
from machine import Pin

@asm_pio(set_pins=(PIO.OUT_LOW, PIO.OUT_HIGH,  PIO.IN_LOW), sideset_pins=PIO.OUT_LOW)
def foo():
    pass

sm0 = StateMachine( 0, foo, freq=2000, set_base=Pin(15), out_base=Pin(16), sideset_base=Pin(22))

looking in the rp2 stubs - asm_pio

def asm_pio(set_init: int = None, out_shiftdir: int = None, autopull: bool = None, pull_thresh: int = None, set_pins: Iterable[Sequence[int]] = None, sideset_pins: int = None, sideset_init: int = None, out_init: int = None, autopush: bool = None, push_thresh: int = None, in_base: int = None, out_base: int = None) -> Any:

Just hit the brick wall:(

Any chance someone that knows can put a working example up:
The idea is that for the 4 sets of pins ( in , out , set , sideset , excluding jmp ) that can be connected to a state machine,
there’s the following that need configuring for each set:

  1. base GPIO
  2. number of consecutive GPIO
  3. initial GPIO direction (in or out pin)
  4. initial GPIO value (high or low)

or do I need to add a documentation request -> Roadmap to next release v1.15

Thanks in Adv.

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