Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All state machines in use for more than two PIO on Pi Pico #4237

Closed
kevinjwalters opened this issue Feb 21, 2021 · 2 comments
Closed

All state machines in use for more than two PIO on Pi Pico #4237

kevinjwalters opened this issue Feb 21, 2021 · 2 comments
Labels
bug rp2040 Raspberry Pi RP2040
Milestone

Comments

@kevinjwalters
Copy link

kevinjwalters commented Feb 21, 2021

On Adafruit CircuitPython 6.2.0-beta.2-18-g2a467f137 on 2021-02-15 this code spits a RuntimeError: All state machines in use

import time

import board
import rp2pio
import adafruit_pioasm

print("15 second pause in case anything bad happens")
time.sleep(15)


flash_pio_code_2pin = """
.program flash2
    set x, 31
onloop:
    set pins, 3  [5]
    jmp x-- onloop

    set y, 31
offloop:  
    set pins, 0  [5]
    jmp y-- offloop
"""

flash_pio_code_3pin = """
.program flash3
    set x, 31
onloop:
    set pins, 7  [5]
    jmp x-- onloop
    set y, 31
offloop:  
    set pins, 0  [5]
    jmp y-- offloop
"""

flash_pio_code_4pin = """
.program flash4
    set x, 31
onloop:
    set pins, 15  [5]
    jmp x-- onloop

    set y, 31
offloop:  
    set pins, 0  [5]
    jmp y-- offloop
"""

KILLER_THIRD = True
KILLER_FOURTH = False
MIN_FREQUENCY=1908

sm1 = rp2pio.StateMachine(
    adafruit_pioasm.assemble(flash_pio_code_2pin),
    init=adafruit_pioasm.assemble("set pindirs {:d}".format(2**2 - 1)),
    frequency=MIN_FREQUENCY,
    first_set_pin=board.GP0,
    set_pin_count=2,
)

sm2 = rp2pio.StateMachine(
    adafruit_pioasm.assemble(flash_pio_code_2pin),
    init=adafruit_pioasm.assemble("set pindirs {:d}".format(2**2 - 1)),
    frequency=MIN_FREQUENCY,
    first_set_pin=board.GP3,
    set_pin_count=2,
)

if KILLER_THIRD:
    sm3 = rp2pio.StateMachine(
        adafruit_pioasm.assemble(flash_pio_code_3pin),
        init=adafruit_pioasm.assemble("set pindirs {:d}".format(2**3 - 1)),
        frequency=MIN_FREQUENCY,
        first_set_pin=board.GP8,
        set_pin_count=3,
    )

if KILLER_FOURTH:
    sm4 = rp2pio.StateMachine(
        adafruit_pioasm.assemble(flash_pio_code_4pin),
        init=adafruit_pioasm.assemble("set pindirs {:d}".format(2**4 - 1)),
        frequency=MIN_FREQUENCY,
        first_set_pin=board.GP11,
        set_pin_count=4,
    )

time.sleep(30)

Based on discussion in Adafruit Forums: Can RP2040 PIO PULL be used in CircuitPython? this should work either due to code sharing or packing code into shared memory.

@dhalbert dhalbert added this to the 6.2.0 milestone Feb 21, 2021
@dhalbert dhalbert added the rp2040 Raspberry Pi RP2040 label Feb 21, 2021
@tannewt tannewt added the bug label Feb 22, 2021
@kevinjwalters
Copy link
Author

FYI, I think code sharing kicks in based on the assembed code object, sm1 and sm2 would need to refer to same assembled code to do this.

Unrelated, elite users with 32 bytes of pio code may get a disappointment: raspberrypi/pico-sdk#261

@dhalbert
Copy link
Collaborator

I'm closing this because #4405 does fix it. I ran the test program above without error.

tyomitch pushed a commit to tyomitch/circuitpython that referenced this issue Apr 30, 2021
This adds an initial specification of the machine.PWM class, to provide a
way to generate PWM output that is portable across the different ports.
Such functionality may already be available in one way or another (eg
through a Timer object), but because configuring PWM via a Timer is very
port-specific, and because it's a common thing to do, it's beneficial to
have a top-level construct for it.

The specification in this commit aims to provide core functionality in a
minimal way.  It also somewhat matches most existing ad-hoc implementations
of machine.PWM.

See discussion in adafruit#2283 and adafruit#4237.

Signed-off-by: Damien George <damien@micropython.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rp2040 Raspberry Pi RP2040
Projects
None yet
Development

No branches or pull requests

3 participants