You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(esp32): support an optional weak Arduino SPI transaction provider #4890
fastspi_esp32.h defaults to native ESP-IDF SPI and retains an explicit Arduino escape hatch. The Arduino implementation owns a SPIClass instance and uses begin/beginTransaction/transfer/endTransaction. Detecting the global SPI object would not identify this instance or establish safe shared ownership.
Proposal
Investigate and implement the smallest optional weak provider for a complete SPI transaction on an explicitly application-owned Arduino bus. Without a provider, retain native SPI. Select the provider before native driver acquisition, so both implementations cannot initialize the same bus concurrently. Keep Arduino types in the adapter.
Acceptance criteria
RED -> GREEN: reproduce the missing optional-provider/sharing behavior with a real clocked-LED sketch and a second SPI client before implementing the fix.
Provider absence preserves current native behavior and does not extract Arduino SPIClass/global constructors; presence routes the complete transaction through the selected application bus.
Verify bus/pins, frequency, bit order, mode, CS handling, locking, error/partial-transfer handling and release. No implicit reconfiguration of an unrelated bus owner.
Cover transfers larger than backend buffers and controller lifetime/reconfiguration. Avoid per-byte weak-call overhead when a complete-buffer operation is available.
Physical clocked-LED output plus a second SPI client remains correct under contention; report throughput and matched flash/static RAM/runtime heap for both paths.
Document explicit provider linkage and archive behavior; retain legacy addLeds functionality and existing native tests/lint. No new GHA.
Decisions
Native SPI remains default. Availability of SPI.h or the global SPI address is insufficient to opt in.
Provider contract must cover acquisition/configuration/write/release as one ownership lifecycle; no guessed SPIClass ABI.
This is a compatibility/sharing improvement; no default-build size saving is claimed until measured.
Related issues
#4887 provides the optional-writer pattern; this task requires SPI-specific ownership semantics.
Implements #4890, under #4888. Stacked on #4894 (feat/esp32-optional-embedded-fs). This branch also incorporates current master host/frequency fixes at 47ad6f0; those upstream changes remain visible until the stack base catches up.
Select a weak default SpiHw1 factory before native acquisition. A directly linked strong application factory supplies an application-owned Arduino SPI bus; a null result disables the host without fallback.
Explicit Arduino adapter retains the owner, checks allocation/configuration, holds one guard/transaction over a complete transfer, and offers withBus for existing library operations. It never begins/ends or changes the owner's pins.
Fix native DMA lifetime after an SDK timeout and reject a buffer whose object exists but storage allocation failed.
Add actual ELF selection/linkage tests and staged canonical AutoResearch fixtures. No new workflows.
Real production path
Legacy FastLED.addLeds<APA102,4,18,RGB,DATA_RATE_KHZ(500)>(leds,32,fl::Esp32SpiBus::HOST2) -> SlimSpiBridge -> SpiChannelEngineAdapter -> SpiHw1 -> selected factory. Use explicit HOST2 to select SPI_UNIFIED; automatically chosen I2S_SPI is separate.
Explicit provider saves 16824 flash / 332 static RAM bytes by eliding duplicate native SDK SPI master code. Baseline owner case has no working sharing; these are footprint controls. Native correctness changes cost 52 flash bytes, no static RAM. Symbol/map analysis and limitations are documented in docs/ESP32_SPI_PROVIDER.md.
Validation
Original real legacy Arduino-owner fixture RED: providerCalls=0; repaired factory selected twice without native takeover.
IDF4.4.1 on-device Arduino provider: complete 140-byte GPIO/SPI3 receiver capture, zero mismatches, real mode/order/clock/CS witnesses, 257-byte second client, exact-mutex contention observation, invalid/OOM/error/lifetime checks. Both settled warm cycles retain zero heap; contended show about6.2ms includes peer traffic and scheduling.
Native SDK timeout and DMA allocation fault RED -> GREEN; later completion, poll recovery and another transfer pass; warm heap unchanged.
Ordinary AutoResearch restored; legacy RMT GPIO connectivity and both three-frame payload checks pass (3/3 scenarios, captures4/4 each).
Actual production selection ELF tests: absent/archive/direct provider and caching. Focused Python/link tests25 pass.
Full native debug suite:326 unit targets and95 examples pass. Lint passes. Independent code review passes.
ESP32-P4 / Arduino3.3.11 / IDF5.5.5 explicit provider compiles and links; no physical P4 SPI claim.
Full Python debug suite:1980 passed,47 skipped,2 xfailed. The sole failure was QEMU smoke before compilation due to an unhealthy fbuild daemon; its focused verbose debug rerun passed. Full stack/master CI is pending; ci-full requested.
Limitations
Arduino writeBytes is blocking and returns no partial-transfer result; the explicit adapter does not claim async DMA. Native DMA stays asynchronous. Every app client must cooperate through the same guard. APA102 has no CS: a mutex prevents interleaving but unrelated ungated SPI traffic still clocks the strip; use actual gating/mux wiring when isolation is needed. Overrides only in unreferenced archives are not extracted. Different runtime fixtures do not provide matched absolute heap comparisons.
Closes #4890 when integrated and all validation gates pass.
Activity
zackees commentedon Oct 22, 2026
Summary
Implements #4890, under #4888. Stacked on #4894 (
feat/esp32-optional-embedded-fs). This branch also incorporates current master host/frequency fixes at 47ad6f0; those upstream changes remain visible until the stack base catches up.Real production path
Legacy
FastLED.addLeds<APA102,4,18,RGB,DATA_RATE_KHZ(500)>(leds,32,fl::Esp32SpiBus::HOST2)-> SlimSpiBridge -> SpiChannelEngineAdapter -> SpiHw1 -> selected factory. Use explicit HOST2 to select SPI_UNIFIED; automatically chosen I2S_SPI is separate.Matched fbuild bloat
Lolin D32, [email protected], baseline 47ad6f0, same sketch/flags.
Explicit provider saves 16824 flash / 332 static RAM bytes by eliding duplicate native SDK SPI master code. Baseline owner case has no working sharing; these are footprint controls. Native correctness changes cost 52 flash bytes, no static RAM. Symbol/map analysis and limitations are documented in docs/ESP32_SPI_PROVIDER.md.
Validation
Limitations
Arduino writeBytes is blocking and returns no partial-transfer result; the explicit adapter does not claim async DMA. Native DMA stays asynchronous. Every app client must cooperate through the same guard. APA102 has no CS: a mutex prevents interleaving but unrelated ungated SPI traffic still clocks the strip; use actual gating/mux wiring when isolation is needed. Overrides only in unreferenced archives are not extracted. Different runtime fixtures do not provide matched absolute heap comparisons.
Closes #4890 when integrated and all validation gates pass.
docs(todo): update #4889/#4890/#4891 narrative lines to match merged …