Skip to content

ESP32 explicit FastPin specializations bypass forced software pin selection #5067

Closed

Description

@zackees

Parent: #5024. Related: #5056 (safe implementation of the primary forced-software fallback).

FASTLED_FORCE_SOFTWARE_PINS does not select that fallback for ESP32's explicitly specialized pins. This is a separate selection defect: fixing the primary fallback cannot make a specialization inherit it.

At f11e47323bcb0d9bb2c770d7112f5f86f4b053a1, src/fl/system/fastpin_base.h:73 selects FastPin<PIN> : detail::ForcedSoftwarePin<PIN> when the macro is defined. The ESP32 platform dispatch still includes src/platforms/esp/32/core/fastpin_esp32.h, whose unguarded _FL_DEFPIN declarations (269–288) explicitly specialize FastPin<0..63> using native _ESPPIN. Those specializations override the forced primary template.

Root built the actual public MY9221 producer on ESP32-C6 GPIO2/3 with both FASTLED_FORCE_SOFTWARE_PINS and FASTLED_NO_PINMAP defined before FastLED.h. The real vendor compile/link passed. Independent actual-ELF inspection found the selected callbacks still perform native GPIO MMIO at 0x60091008/0x6009100c, byte-identical to the native build, with no software-fallback digitalWrite/digitalRead route. This run is rejected as forced-fallback coverage; successful compilation and native IRAM placement cannot certify that configuration.

Retained local evidence: .build/spi-my9221-forced-c6/ contains producer, input hashes, build information, actual ELF/map and logs. The actual producer's macros are presence-based, matching the primary template's #ifdef; this is not a missing numeric macro value.

Required work:

  • Preserve ESP32 pin validity and user-mask compatibility while making forced selection reach the intended software implementation. Check mapped and NO_PINMAP variants, include order, native defaults, and supported ESP32 SDK/SoC configurations.
  • Prove the selected production type/route in actual SDK builds, then exercise GPIO ordering, init LOW, bit/byte/bulk output and subsequent reuse. Do not accept a macro merely appearing in a producer as evidence that it selected a branch.
  • Independently restore the old unguarded-specialization defect and require the selected-route control to fail. Bind exact sources, compiler/configuration, commands and artifacts in the managed completion gate.
  • Inspect actual fallback callees and code/data placement separately for MY9221 timing. Native callback IRAM evidence must not be imported as proof of forced-fallback execution or maximum phase timing.

No fix or electrical/timing compliance is claimed by this report.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Evidence: the selection defect is fixed by fadc722 (#5241). A remaining link defect is fixed in #5391.

    Baseline: master @ 38aa8f6. Real SDK builds were made from a git archive copy of that tree with a throwaway producer that was never committed. Board: esp32c6 (pioarduino 55.03.35, esp32-arduino 3.3.5, ESP-IDF 5.5.1, riscv32-esp-elf-gcc 14.2.0). Command: bash compile esp32c6 ForcedPinProbe.

    The producer is the MY9221 sketch from the report, with presence macros defined before FastLED.h:

    #define FASTLED_FORCE_SOFTWARE_PINS
    // #define FASTLED_NO_PINMAP       (second variant)
    #include <FastLED.h>
    CRGB leds[8];
    __attribute__((noinline)) void probeFastPinHi() { fl::FastPin<2>::hi(); }
    __attribute__((noinline)) void probeFastPinLo() { fl::FastPin<2>::lo(); }
    void setup() { FastLED.addLeds<MY9221, 2, 3>(leds, 8); }
    void loop() { probeFastPinHi(); probeFastPinLo(); leds[0] = CRGB(0x12, 0x34, 0x56); FastLED.show(); delay(10); }

    ELFs were disassembled with the fbuild-installed riscv32-esp-elf-objdump -d -C.

    Forced (FASTLED_FORCE_SOFTWARE_PINS), sha256 5fdd73fa6151d0a4…

    The forced and forced + FASTLED_NO_PINMAP ELFs are byte-identical. On ESP32 the NO_PINMAP macro has no further effect.

    4200026a <probeFastPinHi()>:
    42000278:  bfd1   j  4200024c <fl::NoPinMapPin<(unsigned char)2>::hi()>
    4200027a <fl::NoPinMapPin<(unsigned char)2>::lo()>:
    4200028a:  9c078ca3  sb  zero,-1575(a5)  # <fl::NoPinMapPin<(unsigned char)2>::sHigh>
    42000294:  00e0206f  j   420022a2 <fl::digitalWrite(int, fl::PinValue)>
    # fl::digitalWrite -> fl::platforms::digitalWrite -> j 4200425a <gpio_set_level>
    

    MY9221Controller<2,3,…>::sendWord and ::showPixels call only NoPinMapPin<2>::hi/lo, NoPinMapPin<3>::lo, and fl::digitalWrite. They contain no lui 0x60091 and no GPIO MMIO stores.

    Native control (no macros), sha256 c6c5bb04ad121a54…

    4200039e <probeFastPinHi()>:
    420003aa:  600917b7  lui a5,0x60091
    420003ae:  4711      li  a4,4
    420003b0:  c798      sw  a4,8(a5)     # 0x60091008 GPIO_OUT_W1TS
    420003b6 <probeFastPinLo()>:
    420003c2:  600917b7  lui a5,0x60091
    420003c8:  c7d8      sw  a4,12(a5)    # 0x6009100c GPIO_OUT_W1TC
    

    MY9221 sendWord loads lui 0x60091 three times and stores directly to the GPIO registers. It makes no NoPinMapPin or digitalWrite calls.

    Regression control

    In the build copy only, every FL_FASTPIN_HAS_NO_PINMAP guard in src/platforms/esp/32/core/fastpin_esp32.h (4 sites) was renamed to a macro that is never defined. That restores the pre-#5241 unguarded _ESPPIN specializations. Building with FASTLED_FORCE_SOFTWARE_PINS + FASTLED_NO_PINMAP then produced sha256 c6c5bb04ad121a54…, byte-identical to the native ELF, with the same W1TS/W1TC stores above. That is exactly the reported defect. The header was then restored, and cmp against the repository copy is clean.

    Remaining defect, fixed in #5391

    The forced route had no BitbangPin<FastPin<PIN>> specialization. So BitbangPinDefaults::delay() called fl::delaycycles<N>(), which is only defined for N <= 50, and the public SoftwareSPIOutput failed to link on a forced ESP32. SoftwareSPIOutput<2, 3, DATA_RATE_KHZ(250)> on esp32c6 gave:

    32 undefined reference to `void fl::delaycycles<314ll>()'
    32 undefined reference to `void fl::delaycycles<317ll>()'
    

    #5391 shares the existing inline cycle-counter delay with the forced policy. After the fix, GenericSoftwareSPIOutput<2,3,640>::writeByte (sha256 93ef70e5408408d4…) makes 16 NoPinMapPin<2> and 16 NoPinMapPin<3> calls. Its delays use csrr 0x7e2, and it has no 0x60091 references.

    On the device (ESP32-C6, /dev/ttyACM1)

    Commands:

    • bash autoresearch esp32c6 --upload-port /dev/ttyACM1 --define FASTLED_FORCE_SOFTWARE_PINS
    • the same command without the define

    Each run is followed by findConnectedPins and the new fastPinLoopback RPC from #5391. The board found its own jumper, TX=GPIO0 to RX=GPIO1. Spare SPI pins are 18/19.

    build FastPin route levels/toggle order clock HIGH, then LOW after init() 8 bytes as SoftwareSPIOutput data clock edges, idle LOW bit period result
    forced NoPinMapPin (softwareRoute=true, no HAS_HARDWARE_PIN_SUPPORT) 0 mismatches yes A5 3C 81 5A F0 0F 96 69 (0 bad bits) 64, yes 6485 ns pass
    native _ESPPIN MMIO 0 mismatches yes A5 3C 81 5A F0 0F 96 69 (0 bad bits) 64, yes 4653 ns pass

    Data is checked over two writer instances in one boot, and the pin is reused between the level, data and clock phases.

    Not covered here

    The issue's MY9221 maximum-phase / latch timing item is tracked by #5066 (fix in #5371). This evidence covers route selection and functional output only. It makes no MY9221 electrical or timing compliance claim, and none of the native IRAM evidence is applied to the forced route.

    Closing: the forced selection reaches the software fallback in actual SDK builds, the regression control fails as required, and the forced fallback drives correct GPIO and software-SPI output on hardware. The remaining link defect lands with #5391.

  3. moved this from Triage to Done in FastLED Trackeron Nov 22, 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

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions