Repository navigation
Closed as not planned
Labels
area: driversChipset drivers (WS2812, APA102, etc)platform: teensyTeensy 3.x, 4.xpriority: mediumCode smell, missing test — fix soontype: featureNew capability or enhancement
Description
Part of #3481 (Tier 2b).
Task
Migrate the 7 file-scope statics in src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hpp to fl::Singleton<T> using the same cached-pointer-in-IRAM pattern as #3489.
The FlexIO ISR problem
FlexIO on Teensy 4 uses DMA + interrupt-driven RX capture (recent PR chain: #3222 FlexPWM RX byte capture, #3431 FlexIO unified engine). The ISR reads and writes driver state at high frequency. Singleton<T>::instance()'s function-local-static guard is not ISR-safe.
Required pattern
Same as #3489:
struct FlexIODriverState { /* all 7 fields */ };
static FlexIODriverState* IRAM_ATTR s_flexio_state = nullptr;
void FlexIODriver::begin() {
auto& s = fl::Singleton<FlexIODriverState>::instance();
s_flexio_state = &s;
// ...
}
IRAM_ATTR static void flexio_isr(void*) {
if (!s_flexio_state) return;
// access s_flexio_state->foo
}Approach
- Enumerate the 7 statics from the
SingletonElisionCheckerwarn output. - Collect into
FlexIODriverState. - Introduce the cached IRAM pointer.
- Route all accesses (init, teardown, ISR, user API) through the singleton or the cached pointer.
- Verify with
bash autoresearch teensy41 --flexio(live device test — FlexIO has autoresearch coverage from the fix(teensy): restore FlexPWM RX byte capture #3222/feat(flexio): unified clockless+SPI engine scaffolding (#3428) #3431 series). - Verify elision with
bash bloat teensy41 --examples Blink.
Acceptance criteria
- File clean of
SingletonElisionCheckerwarnings except cached pointer (annotate + allowlist). - FlexIO autoresearch passes.
- Blink flash size drops by FlexIO driver's data footprint on teensy41.
Coordinate with
- singleton: migrate i2s_esp32dev driver state — 19 hits, ISR pattern (Tier 2a) #3489 (i2s_esp32dev) — same ISR-cache pattern. Land i2s first so the pattern is validated on one platform before applying to another.
Metadata
Metadata
Assignees
Labels
area: driversChipset drivers (WS2812, APA102, etc)platform: teensyTeensy 3.x, 4.xpriority: mediumCode smell, missing test — fix soontype: featureNew capability or enhancement
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jul 28, 2026
Audited against the finding in #3754 / #3486:
fl::Singletonelision pays off only for objects with dynamic initialization (those register.init_arrayentries that pull in a ctor and resist--gc-sections). It does nothing for constant-initialized PODs — builds already pass-ffunction-sections -fdata-sections(ci/boards.py:795), so those are already dropped when unreferenced. For PODs the wrap is a net loss: storage grows by aT*, every access gains a null-check, and constant-initialization (race-free) is replaced bySingleton<T>::instance()'s hand-rolledif (!ptr), which bypasses the C++11 magic-static guard.All 7 hits are constant-initialized PODs, and migration here is actively risky.
flexio_driver.cpp.hpp:139-143,149-150:DMAChannel* sDmaChannel = nullptr,volatile bool sDmaComplete = true,bool sInitialized,u8 sFlexIOPin,u32 sLatchCycles,volatile u32 sDmaErrorCount/sLastDmaEs— all constant-init.Specific to this issue:
sDmaComplete,sDmaErrorCountandsLastDmaEsarevolatileand written fromflexio_dma_isr()(L152). Routing ISR-touched state throughSingleton<T>::instance()'sif (!ptr)placement-new is precisely the race the issue's own "cached IRAM pointer" workaround exists to dodge — and that workaround costs an extra pointer plus an indirection to protect storage-fdata-sectionsalready handles.(
flexio_spi_mode.cpp.hppadds 5 more of the same class, not listed in the issue.)Recommend closing as not-planned. See #3492.
zackees commentedon Aug 20, 2026
Closing as not planned after re-validating the singleton premise against current FlexIO state.
The seven targeted variables (
sDmaChannel,sDmaComplete,sInitialized,sFlexIOPin,sLatchCycles,sDmaErrorCount,sLastDmaEs) are constant-initialized pointer/integer/bool PODs. With-fdata-sectionsand linker GC, their storage already elides when the FlexIO TU is unreachable; there is no dynamic initializer to remove.The proposed cached-pointer pattern would instead add:
sDmaComplete,sDmaErrorCount, andsLastDmaEs.The large
DMAMEM sPixelBufferalso must remain explicitly placed/aligned DMA storage and is not aSingletoncandidate. The sibling SPI mode contains the same class of constant-initialized, ISR-touched state, reinforcing that this is driver-owned static storage rather than dynamic-constructor bloat.Parent #3481 is closed, and the checker rollout intentionally distinguishes dynamically initialized globals from constant POD state. No code or hardware run is warranted for a migration that cannot produce the acceptance criterion's claimed Blink size drop and would make ISR access more fragile.