← index #10210PR #18133
Likely Duplicate · medium · value 3.144
QUERY · ISSUE

RP2: Make PIO EXECCTRL_STATUS_SEL settable through API

openby pigrewopened 2022-12-13updated 2023-12-21
enhancement

Please add setting EXECCTRL_STATUS_SEL to the initializer of a PIO state machine for the RP2040.

I'd imagine this would be something like:

StateMachine.init(program,...,status_sel=PIO.TX_FIFO, status_n=3)

The new initialization routine could then call sm_config_set_mov_status(...) from the pico-sdk.

Thanks!

As a workaround, for now, I'm doing something like:

import machine
import rp2
PIO0_BASE = const(0x50200000)
PIO1_BASE = 0x50300000
PIO_SM1_EXECTRL = const(0x00e4)

# Setup status flag for the SSU PIO code
ecv = machine.mem32[PIO0_BASE + PIO_SM1_EXECTRL]
ecv = (ecv & (~0x0000001F)) | 0x02 # status_sel = TX FIFO, N=3
machine.mem32[PIO0_BASE + PIO_SM1_EXECTRL] = ecv
CANDIDATE · PULL REQUEST

rp2: Add execctrl option for the PIO decorator.

openby arachsysopened 2025-09-24updated 2026-02-24
docsport-rp2

Summary

The rp2 PIO assembler includes support for instructions like

mov(y, status)

which can be used to detect when the TX and RX FIFOs pass a configurable threshold, for example to trigger an interrupt handler to fill/empty them.

However, to actually use these instructions, the relevant threshold needs to be configured in the execctrl register, and at present, only the side_pindir bit can be set.

Expose an execctrl= keyword argument in the PIO decorator to do this, together with constants in rp2.PIO which can be used like

@rp2.asm_pio(execctrl = rp2.PIO.STATUS_TXLEVEL + n)
def program():
    [...]
    mov(y, status)
    jmp(not_y, "skip")
    irq(rel(0))
    label("skip")
    [...]

to generate an interrupt if the TX FIFO has fewer than n words left.

This also fixes a bug with the existing side_pindir option, which is meant to be boolean. Previously, if it was passed an integer other than 0 or 1, unintended high bits in the execctrl value would be set, not just the intended bit 29.

Testing

I've tested (and used) this functionality on a real rp2350 board.

Unfortunately there are no in-tree tests at all for the rp2 PIO assembler yet, so there isn't a natural place to add a simple test for this new option. I propose to write a full set of tests to cover as much as I can of that decorator, but will submit in a separate PR.

Trade-offs and Alternatives

It is possible to work around the lack of assembler execctrl support by patching the word of the program array that corresponds to the execctrl register, for example

program[4] = program[4] & ~127 | 1 # set status if txlevel < 1

but this assumes undocumented internal details of the rp2 pio module.

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