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
fix(spi): pace SPIBusManager software SPI at the requested speed (#5124) - #5200
SPIBusManager::softwareSPIWrite never received the device's requested_speed_hz and added no delay, so the software SPI clock ran as fast as the loop allowed.
Fix
Pass the speed in: the SOFT_SPI transmit path now hands requested_speed_hz to softwareSPIWrite. It converts the speed to a half period (softwareSpiHalfPeriodNs).
Pace both writer loops: the fast-register loop (writeRuntimeSoftwareSpi) and the per-pin Pin fallback both wait half a period after setting data, before the rising edge. The clock then stays high for another half period. The first wait also gives data a real setup time before the edge.
Unchanged default: a speed of 0 means no pacing, as before.
Bench tooling
softSpiClockLoopback AutoResearch RPC: drives fl::SPIOutput<2, 0, 250000>, ESP32's SPIBusManager adapter, from a small custom controller and measures the clock on the RX jumper. It passes only when the RX capture starts, completes and records at least 8 high and 8 low clock edges, and the clock is no faster than requested.
It goes through SPIOutput because on ESP32 addLeds<APA102> uses the Channels SPI_UNIFIED hardware driver. That driver never reaches this writer, even with FASTLED_FORCE_SOFTWARE_SPI; a first attempt through addLeds measured hardware SPI at exactly 1000 kHz.
bash autoresearch --define NAME[=VALUE]: a repeatable flag that adds compile defines to the staged build.
Built with bash autoresearch esp32c6 --define FASTLED_FORCE_SOFTWARE_SPI=1. Each run was reset first, then ran findConnectedPins and the RPC. busType 0 (software SPI) was reported on every run.
Requested 250 kHz
Clock high
Clock low
Period
Measured
RED (master, 2 runs)
260 / 235 ns
728 / 750 ns
988 / 985 ns
1012 / 1015 kHz
GREEN (this PR, 2 builds)
2970 / 3077 ns
3416 / 3496 ns
6386 / 6573 ns
156 / 152 kHz
Other checks:
C++ tests:bash test --cpp --clean passes (361/361 unit, 95/95 examples).
Slow, not exact: the clock never runs faster than requested, but at 250 kHz it runs about 38% slow. delayNanoseconds(2000) measures about 2.9-3.1 µs on this chip, and the loop's own time adds to it. No calibration is attempted.
Only ESP32-C6 measured: the change is in shared code. The Pin-fallback loop was not measured, because ESP32 takes the fast-register path.
Flaky first capture: the first capture straight after a flash sometimes records no edges, a bench quirk; a reset clears it. The RPC now reports such a run as a failure instead of passing it.
Added a repeatable --define NAME[=VALUE] option for supplying build definitions.
Added an example SPI loopback check on supported ESP32 builds, reporting bus status, capture diagnostics, and measured clock timing. The check requires GPIO 0-to-1 wiring and a board reset before a subsequent run.
Improvements
Software SPI transfers now use the requested clock speed to pace data and clock transitions.
The AutoResearch CLI now accepts compile definitions for staged builds. Software-SPI writes now use the device’s requested speed for pacing. An ESP32 RPC sends a software-SPI probe and reports captured clock timing.
Changes: AutoResearch compile definitions
Layer / File(s)
Summary
Define argument and build integration ci/autoresearch/args.py, ci/autoresearch/phases.py
The parser accepts repeatable --define NAME[=VALUE] arguments and stores them in Args. The build phase adds the values to its define list.
The new RPC runs on ESP32, captures RX edges, and reports clock interval measurements and capture diagnostics. The help entry describes its setup and response fields.
Issue 5049: The change adds pacing to softwareSPIWrite, which is the function named in the issue’s timing requirements.
Issue 5024: The change adds requested-speed pacing to the software-SPI path covered by this umbrella issue.
Issue 5031: The new loopback RPC reports board-captured timing data, but the PR does not implement the issue’s full validation gate.
Merge Risk: Moderate · up to 8bd9e
Resolve definition forwarding and shared-clock pacing before merging: auto-detected builds can omit requested features, and shared software-SPI devices can exceed their requested speed. Smaller argument-compatibility and repository-requirement issues also remain.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 9, 2026
Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).
Target
FLASH [bytes]
RAM [bytes]
attiny85
2,460 (Same)
136 (Same)
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 9, 2026
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sanitizedTitle, body and conversation screened; review text requires separate screening.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5124. Part of #5024.
SPIBusManager::softwareSPIWritenever received the device'srequested_speed_hzand added no delay, so the software SPI clock ran as fast as the loop allowed.Fix
SOFT_SPItransmit path now handsrequested_speed_hztosoftwareSPIWrite. It converts the speed to a half period (softwareSpiHalfPeriodNs).writeRuntimeSoftwareSpi) and the per-pinPinfallback both wait half a period after setting data, before the rising edge. The clock then stays high for another half period. The first wait also gives data a real setup time before the edge.Bench tooling
softSpiClockLoopbackAutoResearch RPC: drivesfl::SPIOutput<2, 0, 250000>, ESP32'sSPIBusManageradapter, from a small custom controller and measures the clock on the RX jumper. It passes only when the RX capture starts, completes and records at least 8 high and 8 low clock edges, and the clock is no faster than requested.SPIOutputbecause on ESP32addLeds<APA102>uses the ChannelsSPI_UNIFIEDhardware driver. That driver never reaches this writer, even withFASTLED_FORCE_SOFTWARE_SPI; a first attempt throughaddLedsmeasured hardware SPI at exactly 1000 kHz.bash autoresearch --define NAME[=VALUE]: a repeatable flag that adds compile defines to the staged build.Evidence (ESP32-C6, physical jumper GPIO 0 → GPIO 1)
Built with
bash autoresearch esp32c6 --define FASTLED_FORCE_SOFTWARE_SPI=1. Each run was reset first, then ranfindConnectedPinsand the RPC.busType0 (software SPI) was reported on every run.Other checks:
bash test --cpp --cleanpasses (361/361 unit, 95/95 examples).bash lintexits 0.bash compile teensy41 --examples AutoResearchsucceeds.Limits
delayNanoseconds(2000)measures about 2.9-3.1 µs on this chip, and the loop's own time adds to it. No calibration is attempted.ci/tests/test_autoresearch_phases.pyalready fail on master with a missingmax_power_mwArgsargument. Open PR fix(ci): name max_power_mw in the autoresearch Args test defaults #5164 fixes that.BitBangChannelDriver's rate grouping and setup time, which is a different writer.Summary by CodeRabbit
--define NAME[=VALUE]option for supplying build definitions.