Skip to content

hardware_pio: clarify pio_sm_restart docs (PC, running state)#2945

Open
anoshyn wants to merge 1 commit into
raspberrypi:developfrom
anoshyn:fix-pio-sm-restart-doc
Open

hardware_pio: clarify pio_sm_restart docs (PC, running state)#2945
anoshyn wants to merge 1 commit into
raspberrypi:developfrom
anoshyn:fix-pio-sm-restart-doc

Conversation

@anoshyn
Copy link
Copy Markdown

@anoshyn anoshyn commented May 16, 2026

Summary

Per #2844, the doxygen for pio_sm_restart() doesn't mention the program counter or the state machine's enable/running state, and includes a couple of inaccuracies.

This PR rewrites the doxygen for pio_sm_restart and its multi-SM sibling pio_restart_sm_mask against the authoritative wording from the PIO_CTRL.SM_RESTART field description in hardware/regs/pio.h (same text on both RP2040 and RP2350):

Fixed inaccuracies:

  • The clock divider counter is NOT cleared by SM_RESTART — that's a separate bit (CLKDIV_RESTART, exposed via pio_sm_clkdiv_restart). The old doc claimed it was cleared.
  • "ISR" was ambiguous (input shift register vs interrupt service routine); now spelled out.
  • The @param mask description on pio_restart_sm_mask said "modify the enabled state of", but the function does not touch SM_ENABLE.

Filled in:

  • Explicit note that the state machine's enable/running state is preserved (the issue's main ask — the _restart suffix is misleading without this).
  • Explicit note that the program counter is preserved, with a pointer to pio_sm_exec for the "set PC after restart" use case.

PC behavior is documented as "not affected" on RP2040 in the datasheet; the RP2350 datasheet's SM_RESTART description omits the PC from its not-affected list, but the underlying hardware bit is identical and the rest of the description matches. Happy to soften the wording if maintainers know of a behavior difference on RP2350.

Fixes #2844.

Test plan

  • cmake --build build --target docs produces no new warnings; specifically nothing on the changed block in src/rp2_common/hardware_pio/include/hardware/pio.h.
  • Rendered HTML inspected: cross-references to pio_sm_set_enabled, pio_sm_clkdiv_restart, pio_sm_exec resolve; backtick code spans render as <code>.
  • Full SDK build still succeeds (cmake --build build); no code change.
  • CI to confirm broader configurations (RP2350 / RISC-V / etc.).

…ts cleared)

The previous doxygen claimed pio_sm_restart() clears "the ISR, shift
counters, clock divider counter, pin write flags, delay counter, latched
EXEC instruction, and IRQ wait condition". That list mixed up a few
things and was missing the points users actually trip over (per raspberrypi#2844):

- The clock divider counter is NOT cleared by SM_RESTART; that requires
  CLKDIV_RESTART (pio_sm_clkdiv_restart).
- "ISR" was ambiguous (the input shift register vs interrupt service
  routine); spell it out.
- The function name ends in "_restart" but the SM's enable/running state
  is not affected; SM_RESTART only clears internal bookkeeping.
- The program counter is not affected either (the issue's main ask).

Rewrite both pio_sm_restart and pio_restart_sm_mask doxygen to track the
authoritative wording from the RP2040/RP2350 PIO_CTRL.SM_RESTART field
descriptions: list exactly what is cleared (input/output shift counters,
input shift register contents, delay counter, waiting-on-IRQ state,
stalled SMx_INSTR / OUT|MOV EXEC instruction, OUT_STICKY pin writes) and
exactly what is preserved (enable state, PC, output shift register, X/Y
scratch). Point readers at pio_sm_clkdiv_restart and pio_sm_exec for the
operations they may have expected this function to perform.

Also fix the @param description on pio_restart_sm_mask, which previously
said "modify the enabled state of" - that function doesn't touch the
enable bits.

Doxygen build verified locally: no new warnings, cross-references to
pio_sm_set_enabled / pio_sm_clkdiv_restart / pio_sm_exec resolve, and
the rendered HTML reads cleanly.

Fixes raspberrypi#2844.
@anoshyn anoshyn force-pushed the fix-pio-sm-restart-doc branch from 2a9a996 to 392cd87 Compare May 19, 2026 19:53
@anoshyn
Copy link
Copy Markdown
Author

anoshyn commented May 19, 2026

Force-pushed to drop the Co-Authored-By trailer. New HEAD: 392cd87.

@kilograham kilograham requested review from Wren6991 and lurch May 20, 2026 22:27
@kilograham kilograham added this to the 2.2.1 milestone May 20, 2026
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.

2 participants