Skip to content

fix(lpc): F_CPU=24MHz + platform-detection ordering + SCT macro shim - #3055

Merged
zackees merged 1 commit into
masterfrom
fix/lpc845-fcpu-and-platform-detection
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/lpc845-fcpu-and-platform-detection

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Four source-tree fixes uncovered while bringing up the LPC845 SCT+DMA WS2812 driver against the consolidated AutoResearch sketch. Each is a real bug independent of the bring-up effort.

File Fix
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h LPC845 F_CPU corrected from 30 MHz to 24 MHz. The chip's FRO native direct-path rate is 24 MHz per UM11029 §4.1; both Arduino core boards.txt and fbuild lpc845brk.json declare f_cpu=24000000L. Previous 30 MHz default → ~25 % cycle-count drift on bit-bang + SCT+DMA. PLL users override via -DF_CPU=30000000UL.
src/fl/system/sketch_macros.h Pulls in platforms/is_platform.h before tier classification fires. Without this, FL_IS_ARM_LPC was undefined when sketch_macros.h came in via fl/system/engine_events.h before any other platform-aware include — LPC builds got FL_PLATFORM_HAS_LARGE_MEMORY=1 (wrong), FASTLED_HAS_ENGINE_EVENTS=1, and CLEDController::showLeds() emitted unresolved refs to fl::EngineEvents::getInstance() etc.
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h (a) #pragma push_macro around FL_LPC_SCT_Shim so Arduino.h's INPUT 0x0 / OUTPUT 0x1 macros don't corrupt SCT register field names INPUT (0x048) / OUTPUT (0x054). Macros pop at struct close so user pinMode(pin, OUTPUT) still works. (b) SCT timing comment block updated to reflect 24 MHz match counts (tick = 41.67 ns, T0_FALL=9, T1_FALL=19, T_END=30).
examples/AutoResearch/AutoResearchLowMemory.h ws2812SctTest migrated to the current fl::make4PhaseTiming(const ChipsetTiming&, u32 reset_us) signature using fl::to_runtime_timing<fl::WS2812ChipsetTiming>(). The retired LPC sketch used a 3-u32 prototype that no longer exists.

Test plan

  • AutoResearch.ino in low-memory mode compiles end-to-end for lpc845brk via local fbuild against zackees/ArduinoCore-LPC8xx.
  • SCT+DMA driver header compiles cleanly under -DFASTLED_LPC_PWM_DMA=1.
  • EngineEvents link errors that fired on the prior platform-detection-ordering bug are gone.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed build issues caused by incorrect platform detection macro ordering during header inclusion
    • Added protection to prevent Arduino core macros from corrupting internal register definitions on LPC platforms
  • Documentation

    • Updated LPC845 timing documentation to reflect canonical default clock frequency and derived register values
  • Chores

    • Adjusted default system clock configuration for LPC845 from 30 MHz to 24 MHz

Four source-tree fixes uncovered while bringing up the LPC845 SCT+DMA
WS2812 driver against the consolidated AutoResearch sketch:

1. src/platforms/arm/lpc/led_sysdefs_arm_lpc.h -- F_CPU for LPC845 is
   24 MHz, NOT 30 MHz. The LPC845 FRO native direct-path rate is
   24 MHz per NXP UM11029 sec. 4.1; 30 MHz is only reachable via the
   PLL, which neither the Arduino core (zackees/ArduinoCore-LPC8xx
   boards.txt declares f_cpu=24000000L) nor fbuild
   (lpc845brk.json declares f_cpu=24000000L) configures by default.
   The previous 30 MHz default introduced a ~25% cycle-count drift on
   both the bit-bang clockless driver and the SCT+DMA hardware driver.
   Users programming the PLL up to 30 MHz can override via
   -DF_CPU=30000000UL.

2. src/fl/system/sketch_macros.h -- pulls in platforms/is_platform.h
   BEFORE the four-tier memory-tier classification fires. Without
   this, FL_IS_ARM_LPC (set inside platforms/arm/lpc/is_lpc.h, included
   transitively via platforms/arm/is_arm.h) is undefined when
   sketch_macros.h is transitively included via
   fl/system/engine_events.h before any other platform-aware include.
   Result: LPC builds got FL_PLATFORM_HAS_LARGE_MEMORY=1 (wrong) which
   set FASTLED_HAS_ENGINE_EVENTS=1, causing
   fl::CLEDController::showLeds() to emit calls to
   fl::EngineEvents::getInstance() / _onEndFrame() / _onEndShowLeds()
   that fail at link time because the matching definitions in
   engine_events.cpp.hpp are gated out. With the unified is_platform.h
   include, platform detection is canonical regardless of include
   order, and the gating evaluates correctly on Low-memory targets.

3. src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h -- two fixes:
   (a) #pragma push_macro around the FL_LPC_SCT_Shim struct
       definition so Arduino.h's INPUT / OUTPUT macros
       (#define INPUT 0x0 / #define OUTPUT 0x1) do not corrupt the
       SCT register field names INPUT (offset 0x048) and
       OUTPUT (offset 0x054) per UM11029 sec. 16.6. The macros are
       pop'd at the struct close so downstream user code calling
       pinMode(pin, OUTPUT) continues to work as expected.
   (b) Updated the SCT timing comment block to reflect the 24 MHz
       default match counts (T0_FALL=9, T1_FALL=19, T_END=30, tick =
       41.67 ns). The compile-time derivation macro at line 313
       (ns * F_CPU + 5e8) / 1e9 picks up whichever F_CPU is set; the
       comment now matches reality.

4. examples/AutoResearch/AutoResearchLowMemory.h -- migrated the
   ws2812SctTest RPC handler to the current fl::make4PhaseTiming
   signature: takes a const fl::ChipsetTiming& + reset_us (u32) rather
   than three individual T1/T2/T3 u32 args. Constructs the
   ChipsetTiming via fl::to_runtime_timing<fl::WS2812ChipsetTiming>().
   The pre-merge LPC sketch used an older 3-u32 prototype that no
   longer exists in fl/channels/rx.h.

Net effect: AutoResearch.ino in low-memory mode compiles end-to-end
for lpc845brk; the SCT+DMA driver header compiles cleanly under
-DFASTLED_LPC_PWM_DMA=1. Remaining 64 KB flash-budget work is
tracked separately.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit dc92fe1 into master Jun 15, 2026
6 of 8 checks passed
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 88c65d36-c897-4f9a-b7b5-2a610c10c6c3

📥 Commits

Reviewing files that changed from the base of the PR and between 4c1afa3 and 0c79e87.

📒 Files selected for processing (4)
  • examples/AutoResearch/AutoResearchLowMemory.h
  • src/fl/system/sketch_macros.h
  • src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
  • src/platforms/arm/lpc/led_sysdefs_arm_lpc.h

📝 Walkthrough

Walkthrough

Changes the LPC845 default F_CPU from 30 MHz to 24 MHz (native FRO), updates the SCT/WS2812 timing comment block to match, adds #pragma push_macro/pop_macro guards around the SCT shim struct to prevent Arduino INPUT/OUTPUT macro corruption, adds an early platforms/is_platform.h include to sketch_macros.h, and updates the ws2812SctTest example to use fl::to_runtime_timing.

Changes

LPC845 Platform Corrections and Supporting Fixes

Layer / File(s) Summary
LPC845 F_CPU default and timing comment update
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h, src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
F_CPU for FL_IS_ARM_LPC_845 changed from 30000000UL to 24000000UL with a PLL override note; SCT/WS2812 timing comment block updated from 30 MHz tick values to 24 MHz values with matching PLL opt-in note.
Arduino macro guards around SCT shim struct
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
#pragma push_macro / #undef INPUT / #undef OUTPUT inserted before the SCT shim struct definition, with #pragma pop_macro after it, preventing Arduino core macros from corrupting SCT register field identifiers.
Platform detection early include in sketch_macros.h
src/fl/system/sketch_macros.h
platforms/is_platform.h included explicitly at the top of the header so FL_IS_* macros are defined before the tiny/large/huge tier-selection logic runs.
ws2812SctTest timing construction
examples/AutoResearch/AutoResearchLowMemory.h
ws2812SctTest updated to build fl::ChipsetTiming4Phase via fl::to_runtime_timing<fl::WS2812ChipsetTiming>() with reset_us = 0u, replacing the prior fl::make4PhaseTiming call using fl::TimingTraits<WS2812Chipset> constants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2837: This PR directly revises the LPC845 F_CPU value set up in that PR, changing led_sysdefs_arm_lpc.h from 30 MHz to 24 MHz.
  • FastLED/FastLED#3041: That PR introduced ws2812SctTest in AutoResearchLowMemory.h; this PR modifies its ChipsetTiming4Phase construction and reset_us parameter.
  • FastLED/FastLED#3019: Both PRs modify the tier/macro-classification logic in src/fl/system/sketch_macros.h; this PR fixes the platform detection include order in the same header.

Poem

🐇 Hop hop, the clock was wrong, twenty-four's the native song,
INPUT and OUTPUT, pushed away so the SCT fields can play,
Platform detection comes early now, no mix-up shall be allowed,
Timing built at runtime too, reset_us set to zero true—
FastLED bunnies hop on through! 🌟

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lpc845-fcpu-and-platform-detection

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant