Skip to content

perf: optimize ESP32 explicit software SPI atomic GPIO sequence #5028

Closed

Description

@zackees

Context

Discovery at 94dab9c for #5024, two source investigation rounds; no builds or device measurements were performed. src/fastspi.h:117-119 exposes SoftwareSPIOutput publicly. Normal ESP32 SPIOutput uses the hardware proxy (src/platforms/esp/32/drivers/spi/spi_output_template.h:15); this work concerns explicit software output only.

src/platforms/shared/spi_bitbang/generic_software_spi.h:204-238 has a separate ESP32 path: it branches on each data bit, issues an extra clock-low store for ones, then calls clock toggle(). src/platforms/esp/32/core/fastpin_esp32.h:63-71 implements toggle through an output-register read and another branch. Set/clear addresses are already selected per GPIO bank at lines 33-40, and hi/lo are atomic stores at lines 49-54. The generic atomic BitbangPin mechanism is bypassed entirely by this ESP32 branch.

Proposal

Introduce an ESP32-specific verified atomic data write and explicit clock edge sequence for the software implementation, eliminating data-dependent control flow and clock readback where vendor GPIO ordering permits. Preserve the historical adjacent-write restriction documented at lines 215-218 until target evidence permits removing it. Do not route normal hardware output through software.

Acceptance criteria

  • Record RED -> GREEN evidence using actual production SoftwareSPIOutput writeByte/writeBytes/writeBytesValueRaw/writePixels paths: all 256 byte values, back-to-back bytes, start bits, empty transfers, first/last edges and delay boundaries. Trace data stability at every rising edge and preserve unrelated pins during injected concurrent updates.
  • Compile actual ESP32, esp32s2, esp32s3, esp32c3, esp32c6 and esp32p4 configurations (ci/boards.py:956-1049 includes these variants); use safe valid output pin pairs, test low-bank and upper-bank pairs where silicon supports them, cross-bank pairs and invalid/input-only pins. Native fake headers alone do not satisfy board compilation.
  • Save target disassembly proving production data writes have no data-bit branch, clock output readback or out-of-line tiny-delay call. For Xtensa and RISC-V separately establish legal consecutive MMIO ordering from vendor sources, then verify representative real boards through existing AutoResearch and fbuild routes. Preserve interrupt safety; do not claim cycle/ns or physical throughput gains from host traces.
  • Restore the old ESP32 writeBit/toggle path as a mutation: the focused branch/readback/transaction evidence must fail, then pass after restoration. Merely changing kAtomicWrite or kTwoWriteStream must not satisfy the gate.

Decisions

  • One child for the shared ESP32 implementation, with the target/bank matrix above rather than one issue per chip.
  • Keep whole-port two-store streaming disabled: output snapshot ownership and concurrent GPIO safety are separate from per-pin atomic writes.
  • Search metadata: software SPI ESP32, BitbangPin; screened title query ESP32 software SPI label:sanitized returned no items. Unsanitized issue bodies/titles were not ingested.

Open questions

The old adjacent-write workaround needs target-specific vendor evidence; no physical speedup or safe universal sequence has been established by this audit. Next step is a focused failing code-generation/edge trace before implementation.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. moved this from Triage to Done in FastLED Trackeron Nov 6, 2026
  3. added a commit that references this issue on Nov 8, 2026
    3b4ef13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions