Repository navigation
Description
Context
Two source investigation rounds at 94dab9c for #5024; no builds/tests. src/fastspi.h:82-89 makes DATA_RATE_MHZ/KHZ return Hz for ESP32, e.g. DATA_RATE_MHZ(1) = 1000000. Its public SoftwareSPIOutput (:117-119) forwards that value unchanged to GenericSoftwareSPIOutput. Only FL_IS_TEENSY_4X gets the Hz interpretation (generic_software_spi.h:169-172); ESP32 follows cycle-divider delay macros (:174-198). Thus a documented rate macro for explicit ESP32 software SPI is consumed as a huge cycle count instead of converted to a CPU-period divider. Normal SPIOutput hardware proxy uses Hz correctly and must retain that contract.
Proposal
Normalize explicit ESP32 software-output rate units at a clear dispatch/type boundary, preserving Hz semantics for hardware SPI and documenting the public software template parameter. Keep literal-divider compatibility where it is part of the existing API contract; resolve ambiguity explicitly rather than heuristic value guessing.
Acceptance criteria
- Capture RED compile/code-generation or production delay trace for
SoftwareSPIOutput<valid_data,valid_clock,DATA_RATE_MHZ(1)>and DATA_RATE_KHZ variants on ESP32. Show GREEN requested period normalization at actual CPU clocks after the fix; exercise scalar/bulk/pixel/start-bit APIs and slow/fast boundaries. - Compile actual ESP32/S2/S3 and RISC-V C3/C6/P4 board configurations using vendor cores, including CPU-frequency variations; verify hardware SPIOutput still receives the unchanged Hz value and explicit software path is selected.
- Check unsigned padding bounds, code-size growth for slow rates, tiny-delay calls and minimum pulse constraints. Generated code/host delay tracing does not imply physical timing; device measurements via AutoResearch/fbuild are required for physical rate claims.
- Restore old raw-Hz forwarding or cycle-delay interpretation as a mutation; the focused rate test must fail and return GREEN after restoration. Changing metadata/flags without executing the software path must fail shared gate test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.
Decisions
- Separate correctness child from ESP32 atomic sequence optimization perf: optimize ESP32 explicit software SPI atomic GPIO sequence #5028; fixing fewer MMIO stores cannot correct the rate-unit mismatch.
- Normal ESP32 hardware SPI rate contract remains Hz. The explicit SoftwareSPIOutput public path is the reproducible production entry point.
- Duplicate metadata searches
software SPI ESP32/BitbangPinfound no verified screened same unit-contract issue; screened ESP32 software-SPI title query returned none.
Open questions
Clarify compatibility for downstream code supplying literal software dividers on ESP32 before changing the template contract. Next step is the focused failing production-rate repro; no physical speedup is claimed.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Nov 6, 2026
Contract decision for this fix (not in the coming release):
SoftwareSPIOutput<..., RATE>on ESP32 takes Hz, matchingDATA_RATE_*and the hardware path, and converts to cycles inside the wrapper. Values below 1000 are rejected at compile time, so an old literal divider fails loudly.fl::GenericSoftwareSPIOutputremains the cycle-divider path. A literal of 1000 or more would be reinterpreted, so the release notes must call that out.zackees commentedon Nov 6, 2026
Note from #5028 validation:
SoftwareSPIOutput<...,DATA_RATE_MHZ(1)>failed to link on ESP32 at baseline (undefineddelaycycles<499991>).zackees commentedon Nov 7, 2026
#5129 adds the Hz-to-divider conversion, so this stays open. Still unmet: a committed test that fails when the ESP32 branch is reverted (host builds skip it; the RED/GREEN came from a temporary sketch probe), delay traces of scalar, bulk, pixel and start-bit APIs, CPU-frequency variations, code-size and minimum-pulse checks, device timing, and gate #5031. Literal divider semantics changed on ESP32 and need maintainer confirmation; see the PR body.
fix(esp32): convert SoftwareSPIOutput rates from Hz to a divider (Fas…
zackees commentedon Nov 22, 2026
Closing via #5411. Host test:
SoftwareSPIOutput<2,3,DATA_RATE_MHZ(1)/KHZ(250)/KHZ(100)>must derive from thebitbangDividerFromHzdivider; removing the #5129 Hz branch fails 5 checks. ESP32-C6 bench (fastPinLoopback, jumper GPIO0->GPIO1): 250 kHz = 4651-4653 ns, 100 kHz = 10653-10654 ns, difference 6001-6003 ns (want 6000 +/-5%); the legacy writer gives 4550 ns, difference 5941-6068 ns. The constant ~650 ns per-bit excess is the writer's GPIO work, added on top of the requested delay.Not covered, left as stated limitations: ESP32/S2/S3/C3/P4 builds, CPU-frequency variation, code-size and minimum-pulse checks, scalar/pixel/start-bit delay traces, and gate #5031. The question about literal-divider semantics is open in the PR body.
fix(esp32): pin SoftwareSPIOutput Hz-to-divider mapping with host + C…
test(spi): give the SoftwareSPIOutput wrapper test a rate in Hz after…