Skip to content

rp2pio: document that write() blocks until sent; fix txstall docstring - #11969

Open
tyeth wants to merge 1 commit into
adafruit:mainfrom
tyeth:rp2pio-write-blocking-docs
Open

tyeth wants to merge 1 commit into
adafruit:mainfrom
tyeth:rp2pio-write-blocking-docs

Conversation

@tyeth

@tyeth tyeth commented Nov 26, 2026

Copy link
Copy Markdown
Member

This is a documentation-only change to rp2pio.StateMachine. No code changes.

write() / write_readinto(): both wait for the written data to be sent, not just queued. With the default wait_for_txstall=True they return once the TX FIFO and OSR are empty and the state machine has stalled (common-hal/rp2pio/StateMachine.c, the wait loop after the transfer). Until now this was only described under the constructor's wait_for_txstall parameter. The write() docstring didn't mention it, and MicroPython's rp2.StateMachine.put() and the Pico SDK's pio_sm_put_blocking() return as soon as the data is queued. That makes it easy to add a redundant "wait for the FIFO to drain" sleep after write(). I did exactly that in a 433 MHz OOK transmitter, and it doubled the time between frames: an SDR measured a 150 ms frame period where 55 ms was intended. The new paragraph:

  • describes both wait_for_txstall modes
  • says to use wait_for_txstall=False if the program never stalls on a blocking pull (pull noblock)
  • points to background_write for sending without blocking

txstall: the docstring said the flag is set when the state machine stalls "due to a full TX FIFO". TXSTALL is set when it stalls on an empty TX FIFO, during a blocking pull or an autopull (RP2040 datasheet, FDEBUG register). The docstring now says that, and notes that write clears the flag once its data is queued and then uses it to detect when transmission has finished.

Testing

  • I regenerated the stubs with tools/extract_pyi.py ports/raspberrypi/bindings. The result was 0 failed, 3 passed, and the new text appears in rp2pio/__init__.pyi.
  • I ran pre-commit run --files ports/raspberrypi/bindings/rp2pio/StateMachine.c:
    • Passed: codespell, trailing whitespace, end-of-file.
    • Not run: the translations and formatting hooks need make/xgettext/uncrustify, which weren't available on this Windows machine. The change only touches //| comment lines and adds no MP_ERROR_TEXT strings.
  • I confirmed the blocking behaviour on a Pico 2 W running a recent CircuitPython: a 2 s PIO output kept write() from returning for its full length.

🤖 Generated with Claude Code

StateMachine.write() and write_readinto() wait for the written data to
be sent, not just queued: with the default wait_for_txstall=True they
return once the TX FIFO and OSR are empty and the state machine has
stalled. This was only mentioned under the constructor's
wait_for_txstall parameter, so it was easy to add a redundant "wait for
the FIFO to drain" sleep after write().

The txstall docstring said the flag is set on a full TX FIFO. TXSTALL
is set when the state machine stalls on an empty TX FIFO (blocking pull
or autopull), which is what write() relies on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant