Repository navigation
fix(lpc): LPC11Uxx/LPC15xx direction writes and base; LPC11xx legacy toggle, pin table, F_CPU - #5407
Conversation
…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.
|
Caution Review failedThe pull request is closed. Note
|
| 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
Possibly related issues
- Modern LPC native FastPin definitions bypass forced software pin selection #5073: The unguarded native
_FL_DEFPINspecializations remain in the edited LPC header, so the issue's forced software pin selection defect is not addressed.
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.
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.
Memory usage (this PR vs. its merge base)Change in
|
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.hLPC_GPIO_Type(UM10462 GPIO chapter): base0x50000000,DIR0x2000,MASK0x2080,PIN0x2100,MPIN0x2180,SET0x2200,CLR0x2280,NOT0x2300. NoDIRSETorDIRCLR.LPC15xx.hLPC_GPIO_PORT_Type(UM10736; the old comment cited UM11074): base0x1C000000, same offsets, noDIRSETorDIRCLR.SETis documented as "Read: port output bits", sohival()/loval()readingSETholds 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->DIRSETaccess would not compile on LPC11Uxx. The vendor macro is alsoLPC_GPIO_PORTon LPC15xx, which the header did not look for.Changes in
fastpin_arm_lpc.h:LPC_GPIO_PORTis accepted.LpcGpioDirSetClr(one store each to DIRSET/DIRCLR). LPC11Uxx/LPC15xx useLpcGpioDirReadModifyWriteonDIR.LPC845/LPC804 behaviour is unchanged: same base, same
GPIOvendor macro, same single-store DIRSET/DIRCLR path. A new host case pins that (LpcGpioDirisLpcGpioDirSetClr, and setOutput/setInput store to DIRSET/DIRCLR without touching DIR). BothLPC845.handLPC804.hin the fbuild LPC8xx core declareDIR, which the RMW backend references.#5110: LPC11xx legacy (UM10398, cross-checked with NXP
LPC11xx.h)F_CPUandFL_IS_ARM_M0now have legacy defaults (12 MHz IRC boot clock). The per-family CPU block moved fromled_sysdefs_arm_lpc.hintolpc_cpu_defaults.hwith no other change, so a host test can include it.gpio()returnsdecltype(LPC_GPIO0), so the vendorLPC_GPIO_TypeDef*compiles.toggle()read-modify-writes the pin'sMASKED_ACCESS[_MASK]slot, not full-portDATA, so a concurrent change to another pin is not overwritten.clockless_arm_lpc.h; its guard excludes them.MAX_PINis 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-typedLPC_GPIO0..3, a masked toggle, the pin table ending at PIO3_5, and the F_CPU/M0 defaults.The RED runs before the fix:
no member named 'LpcGpioDir' in namespace 'fl::lpc_detail'.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_lpcandbash test fastpin_arm_lpc11_legacy, both quick and--debug.bash lint --cppis clean, andbash compile lpc845 --examples Blinkbuilds with the realLPC845.h.Limitations
DIRis not atomic against an ISR changing another pin's direction on the same port.fl::bit_castper access at -Os) applies only to builds without a vendor header. It is left as is.Closes #5108
Closes #5110
Summary by CodeRabbit