Skip to content

ESP8266: APA102 bit-bangs at ~1.4 Mbit/s (requested 6 MHz); no native HSPI path #4925

Closed

Description

@zackees

Summary

On ESP8266, the APA102 controller bit-bangs at about 1.42 Mbit/s. Its default clock is DATA_RATE_MHZ(6), so it runs about 4.2× slower than requested. The output is correct. Only the rate is wrong. This happens even when the strip is on GPIO13/GPIO14, which are the HSPI MOSI/SCK pins.

Measurements

The measurements were taken on an ESP8266EX at 80 MHz, through the AutoResearch apa102Show(nLeds, 20) RPC (examples/AutoResearch/AutoResearchEsp8266.h). Data is on GPIO13 and the clock is on GPIO14. Each figure is the shortest frame time over 20 frames.

LEDs Frame time
1 75 µs
8 228 µs
32 771 µs
64 1,489 µs

Each LED adds 22.5 µs. That is 32 bits at about 704 ns per bit, roughly 56 CPU cycles per bit. At 6 MHz, 64 LEDs would take about 0.35 ms on the wire.

Cause

  • src/platforms/esp/8266/fastled_esp8266.h includes the hardware SPI driver only under #ifdef FASTLED_ALL_PINS_HARDWARE_SPI. Without that define, APA102 goes through src/platforms/shared/spi_bitbang/generic_software_spi.h.
  • In that path, the delay macros aim for about 13 cycles per bit at 80 MHz. The measured cost is about 56 cycles per bit. That suggests the per-bit GPIO register writes dominate, not the pacing delay. This is inferred and not yet profiled.
  • The opt-in ESP8266SPIOutput in src/platforms/esp/8266/fastspi_esp8266.h wraps the Arduino <SPI.h> library, not the native SDK and HSPI registers.

Proposed follow-up

  1. When DATA_PIN == 13 && CLOCK_PIN == 14, select a native register-level HSPI output by default. It should write SPI1W0..15 and SPI1CMD directly, with no Arduino SPI.h. Use bit-bang for any other pin pair. Keep the #if choice at the dispatch boundary, as described in agents/docs/cpp-standards.md.
  2. Optionally, speed up the bit-bang loop for non-HSPI pins.
  3. Fix the doc mismatch in src/fl/chipsets/apa102.h. Line 24 says the default is DATA_RATE_MHZ(12), but lines 33 and 302 use DATA_RATE_MHZ(6).
  4. Use the AutoResearch bench as the acceptance test. A wire to an RX pin can read the clock and data back, the same way the UART WS2812 pin-level loopback does in feat(esp8266): AutoResearch bring-up, native console, UART/clockless drivers #4917.

Found during the ESP8266 bring-up (#4917).

Activity

  1. zackees commented on Oct 26, 2026

    @zackees
    MemberAuthor

    Checked against master. The cause analysis holds: fastled_esp8266.h:8 gates fastspi_esp8266.h on FASTLED_ALL_PINS_HARDWARE_SPI, and that file wraps Arduino <SPI.h>. Two additions:

    1. The opt-in hardware path ignores SPI_SPEED too. ESP8266SPIOutput::select() (fastspi_esp8266.h:88) hard-codes SPISettings(3200000, ...). So FASTLED_ALL_PINS_HARDWARE_SPI still can't reach the default 6 MHz, and any requested rate collapses to 3.2 MHz. The native HSPI output in step 1 should derive its divider from SPI_SPEED.

    2. The doc mismatch in src/fl/chipsets/apa102.h is wider than line 24:

      • Line 292 (APA102 HD) says 24 MHz; the code (line 302) is DATA_RATE_MHZ(6).
      • Lines 321 and 343 say 24 MHz; the code (lines 326 and 348) is DATA_RATE_MHZ(12).

      Step 3 should fix all four comments, not just line 24.

  2. moved this from Triage to Done in FastLED Trackeron Oct 27, 2026
  3. added a commit that references this issue on Oct 31, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions