Skip to content

fix(objectfled): restore clockless pins' GPR26-29 bank and pad state on deinit (#5395) - #5406

Merged
zackees merged 1 commit into
masterfrom
fix/5395-objectfled-clockless-gpr26
Nov 22, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/5395-objectfled-clockless-gpr26

Conversation

@zackees

@zackees zackees commented Nov 22, 2026

Copy link
Copy Markdown
Member

Closes #5395.

Problem

In clockless mode, ObjectFLED::begin() takes each output pin over:

  • it clears the pin's bit in IOMUXC_GPR_GPR26..29, which moves the pin from GPIO6-9 to GPIO1-4,
  • it sets the pin as an output in GPIO1-4 GDIR,
  • it rewrites the pin's mux and pad-control registers.

~ObjectFLED() restored none of this. Teensy pinMode()/digitalWrite() and FastPin drive GPIO6-9, so once the driver was destroyed or reconfigured, ordinary GPIO on those pins no longer reached the pad. #5148 fixed the same leak for SPI mode.

Fix

This reuses ObjectFLEDPadState from #5148 rather than adding a second copy. New in objectfled_pad_state.h:

  • objectfled_single_pad_regs() builds an ObjectFLEDPadRegs for one pad: both pad slots name the same mux and pad registers, and gpr26 is the pad's own GPR26..29 bank.
  • objectfled_clockless_claim_pad() does the per-pin setup that used to sit inline in begin(), and takes the snapshot before it. On a repeated begin() it keeps the first snapshot.
  • objectfled_clockless_release_pads() restores every captured slot in reverse claim order, so a pin listed twice ends in its pre-driver state.

ObjectFLED holds one ObjectFLEDPadState per pinlist slot. releasePads() runs in two places:

  • In the destructor, after the existing wait for DMA to finish.
  • On both DMA-allocation failure paths in begin().

ObjectFLEDPadState::restore() puts the bank select back first and touches only the driven pins' bits in the shared registers.

Tests

New case in tests/platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_pad_state.cpp. It runs the clockless begin/destroy sequence against a register model with GPR26..29, GPIO1..4 and two pads:

  • three pins across two banks, one of them listed twice;
  • unrelated bits change while the driver owns the pads.
  • RED (helpers in place, release doing nothing, as master's destructor does): the case fails. GPR26 reads 0xBFFFFFF7 where 0xBFFFFFFF is expected, GPR28 reads 0xFFFFFFDF where 0xFFFFFFFF is expected, GDIR and the mux/pad registers are not restored, and the snapshots are never consumed.
  • GREEN: bash test objectfled_pad_state passes (7/7), and so does --debug (ASAN/UBSAN).
  • channel_engine_objectfled passes.
  • bash lint --cpp passes.
  • bash compile teensy41 --examples Blink and bash compile teensy40 --examples Blink succeed. ObjectFLED.cpp.hpp is in the library build, so both compiles include the driver change.

Limitation

No Teensy 4.x board was attached, so the restore has not run on hardware. Two things have not been tested on a device: the pad going back to GPIO6 after teardown, and a pin re-claimed by a new instance. Coverage is the host register model plus the teensy40/41 compiles. Each instance uses about 36 B × NUM_DIGITAL_PINS of extra RAM for the snapshots, roughly 2 KB on a Teensy 4.1.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ff396df and a0b71ba.

Files selected for processing: 4

  • src/platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_pad_state.h
  • src/third_party/object_fled/src/ObjectFLED.cpp.hpp
  • src/third_party/object_fled/src/ObjectFLED.h
  • tests/unit/platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_pad_state.cpp

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
  • 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.

Share

@zackees
zackees enabled auto-merge November 22, 2026 03:42
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 22, 2026
@github-actions github-actions Bot added the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 22, 2026
@zackees
zackees added this pull request to the merge queue Nov 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Memory usage (this PR vs. its merge base)

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)
teensy41 47,104 (Same) 21,738 (Same)

…on deinit (#5395)

Clockless begin() cleared each pin's IOMUXC_GPR26..29 bit to move it
from GPIO6-9 to GPIO1-4, made it a GPIO1-4 output and took its mux and
pad control, and nothing gave them back. Teensy pinMode()/FastPin drive
GPIO6-9, so ordinary GPIO on those pins stayed disconnected after the
driver went away. begin() now snapshots each pad with the
ObjectFLEDPadState from #5148 before claiming it; the destructor and
both DMA-allocation failure paths restore the snapshots.
@zackees
zackees force-pushed the fix/5395-objectfled-clockless-gpr26 branch from 375f6df to a0b71ba Compare November 22, 2026 04:07
@github-actions github-actions Bot 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 22, 2026
@zackees
zackees enabled auto-merge November 22, 2026 04:07
@zackees
zackees added this pull request to the merge queue Nov 22, 2026
Merged via the queue into master with commit 8269db5 Nov 22, 2026
131 checks passed
@zackees
zackees deleted the fix/5395-objectfled-clockless-gpr26 branch November 22, 2026 04:17
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanitized Title, body and conversation screened; review text requires separate screening.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(objectfled): clockless ObjectFLED leaks the GPR26 bank on deinit (same as the SPI path fixed in #5148)

1 participant