Skip to content

fix: restore ObjectFLED SPI GPIO bank and pin state after deinit #5065

Closed

Description

@zackees

Context

The actual ObjectFLED SPI DMA implementation remaps selected pads from fast GPIO6 to eDMA-reachable GPIO1 by clearing IOMUXC_GPR_GPR26 bits during init. Deinit restores saved mux ALT values but deliberately leaves the GPR26 remap and changes direction/latch state. The comment calls this harmless for undriven pads; it breaks later reuse through normal GPIO6-based APIs.

The installed real Teensy SDK confirms the mismatch: cores/teensy4/core_pins.h maps pin14 PORTREG to GPIO6_DR; digital.c pinMode() (162–190) changes direction/pad/mux but never restores GPR26. After init/deinit, pinMode(14, OUTPUT) followed by ordinary GPIO writes can therefore address the disconnected bank. Pad settings are also overwritten rather than fully restored.

Source at pinned baseline 94dab9c, unchanged current implementation blob e4c2241ae19503cca5127863d9fe7107afae8a5e:

The implementation is a hardware-assisted GPIO serializer (CPU builds two port words per bit, QTimer/XBAR drives DMA into GPIO1_DR), not a FIFO-only peripheral exclusion. It already uses two words per bit; this report makes no speculative speedup claim.

Proposal

Save and restore the selected pads' bank/mux/pad/direction/output state at the correct ownership boundary, with safe ordering after DMA drain. Cover failed initialization and timeout cleanup too. Preserve unrelated bits and any documented exclusive-bank contract instead of leaving stale remaps for later generic/ordinary GPIO users.

Acceptance criteria

  • Show focused RED using the actual production init/show/wait/deinit path and real vendor register definitions, then GREEN. Do not replace it with a copied driver or fabricated MCU struct.
  • Test both selected pads starting in GPIO6 and relevant other prior states. Verify selected GPR26, mux, pad, direction and latch restoration, unrelated-bit preservation, repeated init/show/deinit, failed init and timeout cleanup.
  • After deinit, exercise actual ordinary pinMode/digitalWrite and/or production FastPin/software-SPI use on the same pins; prove the restored bank is connected rather than only comparing saved metadata.
  • Actual Teensy vendor compilation and register-value/code-generation evidence are required. Physical timing or throughput claims require physical measurements, which this finding does not supply.
  • Restore the old no-GPR-restore path (and independently omitted pad/state restoration) and require the focused signal to fail, then exact restoration and GREEN. Bind producer, helper, SDK, register and configuration inputs into test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.

Decisions

One child tracks verified pin-state/remap restoration, distinct from generic Teensy pin policy #5026. Whole-bank snapshotted DMA writes and bypassed manager coordination remain a separate ownership/concurrency question until a permitted conflicting producer is verified; they are not falsely claimed as a demonstrated concurrent corruption repro here. Do not resolve this issue through a hardware-only classification, a source comment, or an absent physical board.

Part of #5024.

Activity

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

    @zackees
    MemberAuthor

    #5148 covers part of this issue. SPI-mode init now captures the two pads' GPR26 bank bits, GPIO1 direction and latch bits, and mux and pad-control values. Deinit (and so timeout cleanup) and both init failure paths restore them through one shared teardown, which also clears QTimer3 ch0. Bank select is restored first, and only those pads' bits are written in the shared registers.

    Still open here:

    • Real driver not run on the host: the host test runs the pad-state helper against a pad model, with a hand-written stand-in for init's pad writes, not the real init/show/wait/deinit. Wiring evidence is teensy41/teensy40 builds of that chain only.
    • Restore ordering: not observable in the test.
    • No device run, and no codegen or register dump.
    • test: gate software SPI changes on exhaustive production-path and mutation evidence #5031 binding: not done.
    • Clockless ObjectFLED (ObjectFLED.cpp.hpp begin): has the same GPR26 leak and is not changed.
  3. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Closing with an accepted limitation. The clockless-path leak moves to #5395.

    Fix: #5148 (a43c8bc). objectfled_spi_mode.cpp.hpp:136-156 captures the SPI pads' GPR26 bank bits, GPIO1 GDIR/DR bits and mux/pad control at init. It restores them via ObjectFLEDPadState (objectfled_pad_state.h) on deinit, on timeout cleanup and on both init-failure paths, with bank select restored first and only those pads' bits written.

    Proven by: tests/platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_pad_state.cpp, run against a pad-register model, plus teensy40 and teensy41 builds of the init/deinit chain.

    Accepted limitations:

    The #5031 binding is replaced by a rescoped host-side gate, tracked in #5031.

  4. 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