Skip to content

fix(lpc): LPC11Uxx/LPC15xx direction writes and base; LPC11xx legacy toggle, pin table, F_CPU - #5407

Merged
zackees merged 1 commit into
masterfrom
fix/5108-5110-lpc-gpio
Nov 22, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/5108-5110-lpc-gpio

Conversation

@zackees

@zackees zackees commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes the LPC11Uxx/LPC15xx GPIO template (#5108) and the LPC11xx legacy fastpin gaps (#5110).

#5108: LPC11Uxx / LPC15xx

NXP's CMSIS device headers settle it (the NXP user-manual PDFs are behind a bot wall from here; the headers carry the UM10462 chapter titles):

  • LPC11Uxx.h LPC_GPIO_Type (UM10462 GPIO chapter): base 0x50000000, DIR 0x2000, MASK 0x2080, PIN 0x2100, MPIN 0x2180, SET 0x2200, CLR 0x2280, NOT 0x2300. No DIRSET or DIRCLR.
  • LPC15xx.h LPC_GPIO_PORT_Type (UM10736; the old comment cited UM11074): base 0x1C000000, same offsets, no DIRSET or DIRCLR. SET is documented as "Read: port output bits", so hival()/loval() reading SET holds on both.

So setOutput()/setInput() wrote registers that don't exist on these parts, the 0xA0000000 fallback base only fits LPC8xx, and with the vendor header the ->DIRSET access would not compile on LPC11Uxx. The vendor macro is also LPC_GPIO_PORT on LPC15xx, which the header did not look for.

Changes in fastpin_arm_lpc.h:

  • The default base is chosen per family (0xA0000000 / 0x50000000 / 0x1C000000), and LPC_GPIO_PORT is accepted.
  • Direction backends are selected at the preprocessor boundary. LPC8xx keeps LpcGpioDirSetClr (one store each to DIRSET/DIRCLR). LPC11Uxx/LPC15xx use LpcGpioDirReadModifyWrite on DIR.
  • The DIRSET/DIRCLR accessors exist only where the hardware has them.

LPC845/LPC804 behaviour is unchanged: same base, same GPIO vendor macro, same single-store DIRSET/DIRCLR path. A new host case pins that (LpcGpioDir is LpcGpioDirSetClr, and setOutput/setInput store to DIRSET/DIRCLR without touching DIR). Both LPC845.h and LPC804.h in the fbuild LPC8xx core declare DIR, which the RMW backend references.

#5110: LPC11xx legacy (UM10398, cross-checked with NXP LPC11xx.h)

  1. F_CPU and FL_IS_ARM_M0 now have legacy defaults (12 MHz IRC boot clock). The per-family CPU block moved from led_sysdefs_arm_lpc.h into lpc_cpu_defaults.h with no other change, so a host test can include it.
  2. gpio() returns decltype(LPC_GPIO0), so the vendor LPC_GPIO_TypeDef* compiles.
  3. toggle() read-modify-writes the pin's MASKED_ACCESS[_MASK] slot, not full-port DATA, so a concurrent change to another pin is not overwritten.
  4. The comment no longer claims legacy parts use clockless_arm_lpc.h; its guard excludes them.
  5. Port 3 has only PIO3_0..PIO3_5 (the vendor IOCON list stops at PIO3_5). Pins 42..47 are removed and MAX_PIN is now 41.

Tests

  • tests/unit/platforms/arm/lpc/fastpin_arm_lpc.cpp: an LPC845 direction case, plus the RMW backend on the fake DIR word (keeps other bits, never touches DIRSET/DIRCLR).
  • tests/unit/platforms/arm/lpc/fastpin_arm_lpc11_legacy.cpp: a vendor-typed LPC_GPIO0..3, a masked toggle, the pin table ending at PIO3_5, and the F_CPU/M0 defaults.

The RED runs before the fix:

  • LPC test: compile error, no member named 'LpcGpioDir' in namespace 'fl::lpc_detail'.
  • Legacy test: first cannot initialize return object of type 'FL_LPC11_LEGACY_GPIO_Type *' with an rvalue of type 'LPC_GPIO_TypeDef *'. After the return-type fix, 3/9 cases failed: toggle, pin table and F_CPU.

GREEN: bash test fastpin_arm_lpc and bash test fastpin_arm_lpc11_legacy, both quick and --debug. bash lint --cpp is clean, and bash compile lpc845 --examples Blink builds with the real LPC845.h.

Limitations

  • No LPC11Uxx, LPC15xx or LPC11xx board entry or BSP exists, so nothing here ran on those parts. The LPC11Uxx/LPC15xx selection (base, vendor macro, RMW backend) is preprocessor-only and untested on host, because each test TU is fixed to one family.
  • The RMW of DIR is not atomic against an ISR changing another pin's direction on the same port.
  • LPC11Uxx/LPC15xx: verify modern GPIO template, no board entry in ci/boards.py #5108 item 3 (fl::bit_cast per access at -Os) applies only to builds without a vendor header. It is left as is.

Closes #5108
Closes #5110

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPIO compatibility across LPC11Uxx, LPC15xx, and LPC8xx boards, including family-specific pin direction handling.
    • Corrected legacy LPC11xx pin coverage and pin toggling behavior.
    • Added appropriate default clock settings for supported LPC families while preserving existing clock settings.
  • Documentation
    • Updated LPC GPIO address and register information, including distinctions between controller families.

…acy toggle, pin table and F_CPU (#5108, #5110)

LPC11Uxx (UM10462) and LPC15xx (UM10736) GPIO blocks have DIR but no
DIRSET/DIRCLR and sit at 0x50000000 / 0x1C000000, not 0xA0000000.
Select a read-modify-write DIR backend and the per-family base at the
preprocessor boundary; LPC8xx keeps DIRSET/DIRCLR unchanged.

LPC11xx legacy (UM10398): toggle through the masked-access slot, drop
nonexistent PIO3_6..PIO3_11 (MAX_PIN 41), accept the vendor
LPC_GPIO_TypeDef pointer, and add F_CPU / FL_IS_ARM_M0 defaults via a
new lpc_cpu_defaults.h split out of led_sysdefs_arm_lpc.h.
@zackees
zackees enabled auto-merge November 22, 2026 04:03
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

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
Walkthrough

The LPC GPIO implementation now selects family-specific base addresses and direction-register behavior. The LPC11 legacy pin map and toggle access are adjusted. CPU-class and default clock selection moved into a private header, with unit tests covering these paths.

Changes: LPC platform support

Layer / File(s) Summary
Centralize LPC CPU and clock defaults
src/platforms/arm/lpc/lpc_cpu_defaults.h, src/platforms/arm/lpc/led_sysdefs_arm_lpc.h, tests/unit/platforms/arm/lpc/fastpin_arm_lpc11_legacy.cpp
A private header defines family-specific CPU classes and default frequencies. The system definitions header includes it. The legacy unit test checks the 12 MHz Cortex-M0 default.
Select modern GPIO registers by family
src/platforms/arm/lpc/fastpin_arm_lpc.h, src/platforms/arm/lpc/fastled_arm_lpc.h, src/platforms/arm/lpc/is_lpc.h, src/platforms/arm/lpc/clockless_arm_lpc.h, src/platforms/arm/lpc/README.md, tests/unit/platforms/arm/lpc/fastpin_arm_lpc.cpp
LPC11Uxx and LPC15xx use their family-specific GPIO bases and DIR read-modify-write; LPC8xx retains DIRSET/DIRCLR. Documentation and tests describe and check these differences.
Adjust LPC11 legacy pin access
src/platforms/arm/lpc/fastpin_arm_lpc11_legacy.h, tests/unit/platforms/arm/lpc/fastpin_arm_lpc11_legacy.cpp
The legacy pin range ends at pin 41. The GPIO pointer preserves the vendor type, and toggle uses the pin's masked-access slot. Tests check the pin range and toggle behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Fastpin as _ARMPIN
  participant Direction as LpcGpioDir
  participant Registers as GPIO registers
  Fastpin->>Direction: setOutput(mask) or setInput(mask)
  alt LPC8xx
    Direction->>Registers: write mask to DIRSET or DIRCLR
  else LPC11Uxx or LPC15xx
    Direction->>Registers: read DIR, update mask, write DIR
  end
Loading

Possibly related issues

Merge Risk: Moderate · up to b12c0

On LPC11Uxx and LPC15xx, changing a pin's direction in the main code can silently undo a direction change made by an interrupt handler on the same port, which could turn an output pin into an input. The most common LPC8xx path is unchanged. Consider protecting the direction update before merging, or explicitly accept the documented limitation.

- [ ] 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

@github-actions github-actions Bot added the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 22, 2026
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 22, 2026
@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 added this pull request to the merge queue 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)

@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
Merged via the queue into master with commit 78d6c50 Nov 22, 2026
131 of 133 checks passed
@zackees
zackees deleted the fix/5108-5110-lpc-gpio branch November 22, 2026 04:13
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 22, 2026
@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
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

1 participant