Repository navigation
refactor(platform/lpc): replace sparse GPIO register padding with safer offset-based accessors #3218
Description
Follow-up to #3212.
Background
PR #3212 fixes a real bug in src/platforms/arm/lpc/fastpin_arm_lpc.h: the fallback FL_LPC_GPIO_Type mirror did not include the large holes in the modern LPC GPIO register map, so fields such as W, DIR, PIN, SET, CLR, NOT, DIRSET, and DIRCLR landed at the wrong byte offsets.
That PR corrects the immediate issue by adding explicit padding so the fallback mirror matches the NXP/CMSIS GPIO_Type layout:
Bat0x0000Wat0x1000DIRat0x2000PINat0x2100SETat0x2200CLRat0x2280NOTat0x2300DIRSETat0x2380DIRCLRat0x2400DIRNOTat0x2480
The padding does not allocate SRAM because this is a typed view over a fixed hardware address, not an instantiated object. However, it is visually bulky and easy to get wrong again.
Better fix
Replace the sparse fallback struct with one of these safer representations:
- Direct offset accessors/constants for the small register subset FastLED actually uses, e.g.
PIN,SET,CLR,NOT,DIRSET,DIRCLR; or - Keep the CMSIS-style struct mirror, but add compile-time
offsetofassertions for every register FastLED touches.
Direct offsets are probably the cleaner long-term fit for FastLED because the LPC FastPin code only needs a handful of registers and the controller map has large sparse gaps.
Acceptance criteria
- FastPin LPC fallback no longer depends on unverified sparse padding arithmetic, or every used padded-field offset is protected by
static_assert(offsetof(...)). - Register offsets used by
FastPin<>::setOutput,setInput,hi,lo,toggle,hival,loval,port,sport, andcportare covered. - The implementation still defers to the SDK/CMSIS
LPC_GPIO/GPIOdefinition when available, or documents why the fallback address constants are authoritative. - A host-side compile/layout test covers the fallback path if practical.
- Do not conflate this with GPIO clock gating:
GPIO_PortInit(GPIO, 0)/ clock ungating remains separate follow-up behavior unless this issue explicitly expands to include it.
Related work
- Fixed wrong offsets in FL_LPC_GPIO_Type for LPC GPIO register map. #3212 — immediate register-map padding fix that should be merged first.
- feat(platform): LPC845 bit-bang clockless driver (Stage 2a of #2836) #2837 — introduced LPC8xx
fastpin_arm_lpc.hand the bit-banged LPC clockless path usingLPC_GPIO->SET[0]/CLR[0]/DIRSET[0]/DIRCLR[0]. - feat(platform/lpc): scope LPC8xx driver code to LPC8xx-only (#2865) #2866 — scoped LPC driver gates after broader LPC detection landed.
- feat(platform/lpc): complete Stage 4 wiring for LPC11Uxx + LPC15xx + APA102 SPI on LPC8xx (#2845) #2872 — widened modern LPC GPIO reuse for LPC11Uxx and LPC15xx.
- feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (#2842) #2850 / feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (Stage 2c of #2836) #2842 — LPC845 PWM+DMA-to-GPIO driver also depends on correct GPIO
SET[0]/CLR[0]destination addresses. - feat(platform/lpc): legacy LPC1110/1112/1114/1115 clockless driver (fastpin for 0x50000000 masked-access GPIO) — Stage 4.1 (legacy) from #2845 #2878 — legacy LPC11xx work, relevant because it intentionally avoids the modern
0xA0000000GPIO layout. - meta: LPC dev roadmap — Stages 3 + 4 (port completion, family expansion) #2845 — LPC roadmap/meta issue for the broader family-expansion context.
- hardware: bring up LPC845 + WS2812 + AutoResearch UART (Stages 3.5, 3.6 from #2845) #2880 — hardware bring-up context for LPC845 verification.
Notes
The immediate PR #3212 is correct and should not be blocked on this cleanup. This issue is about making the fallback representation harder to break in the future.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Fix LPC GPIO register map offsets
zackees commentedon Jun 18, 2026
cc @phatpaul — this is the follow-up cleanup issue from #3212 so you can track the safer long-term fix for the LPC GPIO register-map fallback. The immediate offset fix from your PR has been merged.