Repository navigation
Description
Problem
On every LPC target (FL_IS_ARM_LPC), FastLED's portable runtime pin API does nothing. src/platforms/pin.h:42-43 sends LPC to platforms/shared/pin_noop.hpp. Every other real MCU family has a backend (pin_rp.hpp, pin_nrf52.hpp, pin_renesas.hpp, pin_silabs.hpp, pin_ci13xx.hpp, ...).
Effects, from master b95c3031fc:
FASTLED_FORCE_SOFTWARE_PINSis rejected. Forced pins on LPC resolve toNoPinMapPin, because LPC definesFASTLED_NO_PINMAP(led_sysdefs_arm_lpc.h:77-78) andfastpin_base.h:84-99selectsNoPinMapPin.NoPinMapPincallsfl::pinMode/fl::digitalWrite(fastpin_no_pinmap.h:24-34, from fix(fastpin): use digitalWrite for forced pins with no pin map #5137). Those calls are no-ops on LPC, so fix(lpc): reject FASTLED_FORCE_SOFTWARE_PINS instead of silently ignoring it (#5073) #5152 and fix(lpc): reject FASTLED_FORCE_SOFTWARE_PINS in shared fastpin_base.h (#5189) #5229 added#erroratsrc/fl/system/fastpin_base.h:14-20. That turns software pins, and software SPI over forced pins, into an unsupported configuration. This is a gap in the implementation, not a hardware limit. LPC8xx has an ordinary GPIO block that the CMSIS PAL already describes.- Runtime-pin users write nothing, with no warning. Callers that reach
pin_noopon LPC:fl::DigitalMultiWrite8::applyNibble(src/fl/system/pins.cpp.hpp:254-260, and the 16-pin version at:371-377) writes only throughfl::digitalWrite. The sharedBitBangChannelDriveruses it for all data lanes and for the SPI clock (src/platforms/shared/bitbang/bitbang_channel_driver.cpp.hpp:89,99-100,320-324). On LPC845,FastLED.enableAllDrivers()registers that driver asBusTraits<Bus::BIT_BANG,0>unlessFASTLED_LPC_PWM_DMAis set (src/platforms/arm/lpc/channel_drivers_lpc.impl.hpp:20-37). Today the LPC845 channels-API BIT_BANG driver sends no signal at all.fl::DigitalPin/ button input (src/fl/sensors/digital_pin.cpp.hpp:38-46) always readsLow.fl::Pinruntime class (src/platforms/generic_pin.h:62-149).src/fl/chipsets/analog.h:23-25(analog RGBpinMode).- ISR software PWM in
fl/system/pin.cpp.hpp:140-147,228,355-356. This also needs anfl::isrtimer, and LPC has none (platforms/isr.hfalls through toisr_null.hpp), sosetPwmFrequencyalready fails cleanly. Out of scope here. - Channel RX validation (
src/fl/channels/detail/validation/rx_test.cpp.hpp:26-64). - Not affected:
examples/AutoResearch/AutoResearchLowMemory.h:372-383andAutoResearchRemote.cpp:238-251call the Arduino core's::pinMode/::digitalWritedirectly, so today's--pin-toggle-rxbench never goes throughfl::digitalWrite.
Related: #5073, #5074 (native FastPin specializations bypass forced selection), #5189 (closed), PRs #5152, #5229 (added the #error), #5137 (NoPinMapPin → digitalWrite). Also related: #5108 (LPC11Uxx/LPC15xx have no board) and #5110 (LPC11xx legacy has no target). Precedents for honoring forced pins: #5241 (ESP32), #5258 (ESP8266).
Required interface (from src/platforms/shared/pin_noop.hpp)
The backend goes in namespace fl::platforms. fl/system/pin.cpp.hpp wraps every function (:51-63, :261-287, :311-381, :398-407). Keep the parenthesized names (pinMode) etc. (#4914):
inline void (pinMode)(int pin, PinMode mode) FL_NO_EXCEPT;
inline void (digitalWrite)(int pin, PinValue val) FL_NO_EXCEPT;
inline PinValue (digitalRead)(int pin) FL_NO_EXCEPT;
inline u16 (analogRead)(int pin) FL_NO_EXCEPT; // stub OK: return 0
inline void (analogWrite)(int pin, u16 val) FL_NO_EXCEPT; // stub OK
inline void setPwm16(int pin, u16 val) FL_NO_EXCEPT; // stub OK
inline void setAdcRange(AdcRange range) FL_NO_EXCEPT; // stub OK
inline bool needsPwmIsrFallback(int pin, u32 frequency_hz); // return true (as noop/nrf51)
inline int setPwmFrequencyNative(int pin, u32 frequency_hz); // return -4
inline u32 getPwmFrequencyNative(int pin); // return 0Reference shapes: pin_nrf51.hpp / pin_ci13xx.hpp (adapters to Arduino-core functions) and pin_renesas.hpp (native HAL with analog stubs). Analog and PWM can stay stubs. The LPC8xx Arduino core's own analogRead / analogWrite are stubs too (cores/lpc8xx/wiring_analog.c: analogRead returns 0, analogWrite does nothing).
Is there an Arduino core underneath?
Yes, for LPC8xx only. Every LPC board in ci/boards.py:1292-1344 uses framework="arduino" on FastLED/platform-nxp-lpc8xx@4b6d395c, which pulls FastLED/framework-arduino-lpc8xx (fbuild cache: 0.2.3+g9e8be02, SHA 9e8be028892e…). That core does provide pinMode / digitalWrite / digitalRead (cores/lpc8xx/wiring_digital.c). I still recommend not delegating to it, for three reasons:
- The core's
pinModehas a bug in IOCON indexing. It writesLPC8XX_IOCON->PIO[info.bit], i.e. it indexes IOCON by GPIO bit. On LPC8xx the IOCON array is in a scrambled order: in the vendorLPC845.h,IOCON_INDEX_PIO0_0 == 17andIOCON_INDEX_PIO0_17 == 0(variants/lpc845/LPC845.h:4029-4083;LPC804.h:3126-3155is similar). SopinMode(0, INPUT_PULLUP)sets the pull-up on PIO0_17, and everypinMode()clears the pull mode of an unrelated pin. This bug should also be filed upstream againstFastLED/framework-arduino-lpc8xx. It currently affects AutoResearchpinMode(rx, INPUT_PULLUP)as well. - The core covers fewer pins than FastPin. Its pin table stops at
VARIANT_NUM_DIGITAL_PINS= 30 (LPC845) and 22 (LPC804) (variants/*/variant.h,variant.cppmaps Arduino pin N → PIO0_N). FastPin covers PIO0_0..31 (fastpin_arm_lpc.h:188-201), so PIO0_30/31 on LPC845 and PIO0_22..30 on LPC804 would be dropped without any error. - A native backend does not depend on
Arduino.h, and it uses the same registers and pin numbers asFastPin.
LPC11Uxx, LPC15xx, and LPC11xx legacy have no board entry, no core, and no vendor header on any include path.
Per-family register mapping
The pin-number mapping is the same everywhere FastPin already defines it: runtime pin N → port 0, mask 1u << N for the modern controller (_FL_DEFPIN(PIN) … _ARMPIN<PIN, (1u << (PIN))>, fastpin_arm_lpc.h:188). For legacy LPC11xx it is port N/12, bit N%12 (LpcLegacyPinAddr, fastpin_arm_lpc11_legacy.h:98-102). pinToPort() already groups LPC pins as pin/32, because FASTLED_NO_PINMAP is set (pins.cpp.hpp:103-111). That is consistent with the modern mapping.
LPC845 / LPC804 (buildable; vendor PAL is tier 1)
<LPC845.h> / <LPC804.h> come from the core's variants/<chip>/ and are already included by led_sysdefs_arm_lpc.h:109-121, with an INPUT/OUTPUT push/pop.
| Op | CMSIS | Notes |
|---|---|---|
| direction out / in | GPIO->DIRSET[0] / GPIO->DIRCLR[0] = mask |
GPIO_Type @ GPIO_BASE 0xA0000000; LPC845 has [2] arrays (LPC845.h:2885-2903), LPC804 has [1] (LPC804.h:2134-2149) |
| write high / low | GPIO->SET[0] / GPIO->CLR[0] = mask |
same registers _ARMPIN::hi()/lo() already use via lpc_detail::lpc_gpio_set()/clr() (fastpin_arm_lpc.h:58-94) |
| read | GPIO->PIN[0] & mask |
|
| pulls | IOCON->PIO[IOCON_INDEX_PIO0_n], field IOCON_PIO_MODE_MASK / IOCON_PIO_MODE(x): 0 = inactive, 1 = pull-down, 2 = pull-up |
IOCON_Type (LPC845.h:3928, PIO[56]; LPC804.h:3055, PIO[30]). The index is not N. Build a constexpr u8 kIoconIndex[32] from the vendor IOCON_INDEX_PIO0_n macros. LPC804 has no IOCON_INDEX_PIO0_31, so reject pin 31 there (#ifdef IOCON_INDEX_PIO0_31). LPC8xx supports a real pull-down, so InputPulldown maps to MODE=1. |
| clocks | SYSCON->SYSAHBCLKCTRL0 |= SYSCON_SYSAHBCLKCTRL0_GPIO0_MASK | SYSCON_SYSAHBCLKCTRL0_IOCON_MASK |
The core's initVariant() already does this at boot (lpc8xx_basic_peripheral_init). An idempotent OR in pinMode costs little and covers non-core builds. Masks exist in both headers (LPC804.h:5651,5714). |
| function select | SWM (SWM0->PINASSIGN*, SWM0->PINENABLE0) |
LPC8xx has no FUNC field in IOCON. GPIO is the default when no movable or fixed function is assigned. Do not touch SWM in pinMode: disabling SWM_PINENABLE0_SWCLK/SWDIO/RESETN would cut off SWD/reset. Match the current FastPin/core behavior and document that a pin routed to USART/SPI/SCT by SWM is not under GPIO control. |
LPC11Uxx (no target; the existing FastPin template is wrong for it)
Vendor LPC11Uxx.h (NXP CMSIS, e.g. as vendored in mbed-os targets/TARGET_NXP/TARGET_LPC11UXX/device/LPC11Uxx.h): LPC_GPIO_Type sits at LPC_GPIO_BASE 0x50000000, not 0xA0000000. It has DIR[2]@0x2000, MASK, PIN[2]@0x2100, MPIN, SET[2]@0X2200, CLR[2]@0x2280, NOT[2]@0x2300, and no DIRSET/DIRCLR. IOCON is a struct of named members in linear order (RESET_PIO0_0, …, SWCLK_PIO0_10, …, PIO0_23, PIO1_0@0x060 … PIO1_31), with a FUNC field. Several port-0 pins boot as RESET/SWD/JTAG, so a correct pinMode must set FUNC=GPIO and clear ADMODE on AD pins.
Note: fastpin_arm_lpc.h claims LPC11Uxx and LPC15xx share the "DIR/MASK/PIN/SET/CLR/NOT layout at 0xA0000000" (:22-31, and fastled_arm_lpc.h status block). According to the vendor headers this is wrong on two counts. (a) The fallback FL_LPC_GPIO_BASE 0xA0000000 (:49) is the wrong base for both families. (b) setOutput()/setInput() write DIRSET/DIRCLR (0x2380/0x2400), which do not exist on these parts. With the vendor header present, FL_LPC_GPIO_HW = LPC_GPIO would fail to compile on ->DIRSET. This belongs to #5108, but it blocks any runtime backend for these families.
LPC15xx (no target; same problem)
Vendor LPC15xx.h (mbed-os TARGET_LPC15XX/device/LPC15xx.h): LPC_GPIO_PORT_Type at LPC_GPIO_PORT_BASE 0x1C000000, with DIR[3], MASK[3], PIN[3], MPIN[3], SET[3], CLR[3], NOT[3], and no DIRSET/DIRCLR. The pointer is named LPC_GPIO_PORT, which the defined(LPC_GPIO) / defined(GPIO) probe at fastpin_arm_lpc.h:52-56 never matches. IOCON is linear (LPC_IOCON_Type PIO0_0, PIO0_1, … @0x400F8000). Pin function goes through SWM LPC_SWM->PINENABLE0/1, as on LPC8xx.
LPC11xx legacy (no target)
Vendor LPC11xx.h (mbed-os TARGET_LPC11XX_11CXX/device/LPC11xx.h): LPC_GPIO_TypeDef with MASKED_ACCESS[4096], DATA@0x3FFC, DIR@0x8000; LPC_GPIO0..3 at 0x50000000 + n·0x10000. This matches the local mirror in fastpin_arm_lpc11_legacy.h:62-89. Runtime writes would use LPC_GPIOn->MASKED_ACCESS[mask] = mask / 0 and DIR |= / &= ~mask. IOCON is non-linear named registers (LPC_IOCON_TypeDef: PIO2_6@0x000, RESET_PIO0_0@0x00c, SWCLK_PIO0_10@0x068, R_PIO0_11@0x074, R_PIO1_0@0x078, …), with FUNC values per pin (the R_ pins need FUNC=1 for GPIO). That calls for a 48-entry offset table taken from the vendor struct (offsetof), not a hand-typed one.
Proposed design
- New
src/platforms/arm/lpc/pin_lpc.hpp, scoped toFL_IS_ARM_LPC_845 || FL_IS_ARM_LPC_804.- Include
platforms/arm/lpc/fastpin_arm_lpc.h(or a new smalllpc_gpio_regs.hsplit out of itslpc_detailblock) so the runtime path and FastPin share one register accessor set (lpc_gpio_set/clr/pin/dirset/dirclr) and one pin→mask rule (1u << pin,pin <= MAX_PIN). The runtime backend must calllpc_detaildirectly, notFastPin<N>. Under forced pinsFastPin<N>isNoPinMapPin, which calls back intofl::digitalWriteand would recurse. - Add
kIoconIndex[32], built fromIOCON_INDEX_PIO0_n, as the only new table, and place it next to the FastPin grid so the two stay in sync. Out-of-range or nonexistent pins return or no-op (digitalReadreturnsLow), matching other backends. - Analog/PWM stubs as in
pin_noop.hpp.
- Include
- Dispatch (
src/platforms/pin.h:42-43):#elif defined(FL_IS_ARM_LPC_845) || defined(FL_IS_ARM_LPC_804) #include "platforms/arm/lpc/pin_lpc.hpp" #elif defined(FL_IS_ARM_LPC) #include "platforms/shared/pin_noop.hpp" // LPC11xx / LPC15xx: no verified target (#5108, #5110)
- Honor forced pins on LPC8xx (closes Modern LPC native FastPin definitions bypass forced software pin selection #5073 for LPC8xx), following the ESP8266 fix(esp8266): honor forced software pins in native FastPin specializations #5258 / ESP32 fix(esp32): honor forced software pins without Arduino port maps #5241 pattern:
- Narrow the
#errorinfastpin_base.h:14-20toFL_IS_ARM_LPC && !(FL_IS_ARM_LPC_845 || FL_IS_ARM_LPC_804). Rewrite the message to say that the LPC11xx/LPC15xx pin backend is pending LPC11Uxx/LPC15xx: verify modern GPIO template, no board entry in ci/boards.py #5108/LPC11xx legacy: no buildable target; F_CPU, vendor types, toggle and pin table gaps #5110. Do not remove it for those families while their FastPin base address is unverified. - In
fastpin_arm_lpc.h, underFL_FASTPIN_HAS_NO_PINMAP, make_ARMPIN<PIN,MASK>derive fromNoPinMapPin<PIN>and keep the_FL_DEFPINgrid, sovalidpin()still bounds pins at 0..31. That way the explicit specializations stop bypassing the forced primary template, which is the root cause of Modern LPC native FastPin definitions bypass forced software pin selection #5073. Gate theFL_LPC_ENABLE_FAST_SOFTWARE_SPIBitbangPinspecialization (:162-185) andHAS_HARDWARE_PIN_SUPPORT(:203) off in that mode.isNoPinMapPin()then resolves through the base class, andGenericSoftwareSPIOutputtakes the per-pin path (generic_software_spi.h:72-75). - Drivers that dereference
FastPin<>::port()plus fixed offsets must fail at compile time in forced mode. Otherwise they would write tonullptr + 0x100/0x180. Affected:clockless_arm_lpc.h:55-90(the default clockless driver on LPC804 and on LPC845 withFASTLED_LPC_UART_DMA=0) andclockless_arm_lpc_plu.h:294-310. AddFL_STATIC_ASSERT(DATA_PIN != DATA_PIN, "FASTLED_FORCE_SOFTWARE_PINS is not supported by the LPC clockless driver …"), as inclockless_avr.h:223and the ESP8266 block driver. The LPC845 default UART-DMA clockless path and the hardwarespi_arm_lpc.hdo not useport(). TheirFastPin::setOutput()becomesfl::pinMode, which is now real.
- Narrow the
- LPC11Uxx / LPC15xx / LPC11xx legacy: no runtime backend in this issue. These families have no buildable target, and the vendor headers contradict the current FastPin base addresses (see above). Keep
pin_noopand the narrowed#errorthere. Track the base-address andDIRSETfix in LPC11Uxx/LPC15xx: verify modern GPIO template, no board entry in ci/boards.py #5108/LPC11xx legacy: no buildable target; F_CPU, vendor types, toggle and pin table gaps #5110, then addpin_lpc11u.hpp/pin_lpc15.hpp/pin_lpc11_legacy.hpponce a board entry exists. Writing compile-only register code for parts nobody can build is whatregister-maps.mdwarns against. - Update the docs:
src/platforms/arm/lpc/README.md(files list, the forced-pins note, and the stale:196claim thatfastled_arm_lpc.hemits#errorfor LPC11/15).
Test & verification plan
Buildable LPC targets (bash ci-labels list --json → ci-platform:lpc845, lpc845brk, lpc804, lpcxpresso845max, lpcxpresso804; workflows build_lpc*.yml/build). LPC11xx/LPC15xx have no target.
# default builds must be unchanged
bash compile lpc845 --examples Blink
bash compile lpc804 --examples Blink
# forced software pins: was #error, must now compile on LPC845 (UART-DMA clockless + core GPIO)
bash compile lpc845 --examples Blink --defines FASTLED_FORCE_SOFTWARE_PINS
# LPC804 Blink uses the cycle-counted clockless driver -> expect the new static_assert, not a silent no-op
bash compile lpc804 --examples Blink --defines FASTLED_FORCE_SOFTWARE_PINS # expected: clear static_assert
# software SPI (APA102 on non-SPI pins) through NoPinMapPin -> fl::digitalWrite -> pin_lpc.hpp
bash compile lpc845 --examples Apa102 --defines FASTLED_FORCE_SOFTWARE_PINS,STRIP_DATA_PIN=20,STRIP_CLOCK_PIN=21
bash compile lpc804 --examples Apa102 --defines FASTLED_FORCE_SOFTWARE_PINS,STRIP_DATA_PIN=20,STRIP_CLOCK_PIN=21
bash compile lpc845 --examples Apa102 --defines STRIP_DATA_PIN=20,STRIP_CLOCK_PIN=21 # native FastPin path, unchangedAlso check that the FastLED.enableAllDrivers() path on LPC845 now links pin_lpc.hpp (an AutoResearch build is enough). Check flash/RAM on LPC804 (32 KB / 4 KB) with bash bloat lpc804 before and after. The expected cost is a 32-byte IOCON table plus a few small functions.
Tests to update or add:
ci/tests/test_lpc_forced_software_pins.py:test_premise_lpc_pin_api_is_a_noopis designed to fail once a backend lands, so replace it with an assertion that LPC845/804 dispatch topin_lpc.hpp. Narrowtest_shared_fastpin_base_rejects_lpc_forced_software_pinsand thetest_direct_fastpin_include_*cases: LPC845/LPC804 forced mode must now succeed (preprocess-only stubs still work). Add an__LPC11xx__/__LPC15xx__case that still expects the#error.- Add assertions modeled on
ci/tests/test_esp8266_forced_software_pins.py/test_mgm240_forced_software_pins.py:_ARMPINderives fromNoPinMapPinunderFL_FASTPIN_HAS_NO_PINMAP, the BitbangPin policy andHAS_HARDWARE_PIN_SUPPORTare gated, and the clockless static_assert is present. - Optionally, a host check that
kIoconIndex[n] == IOCON_INDEX_PIO0_nfor n in 0..31 against the real vendor headers, if they can be found on the host. Otherwise a compile-timeFL_STATIC_ASSERTper entry insidepin_lpc.hpp.
Hardware (not run as part of filing this): the LPC845-BRK on LPC-Link2 CMSIS-DAP is the documented bench board (agents/docs/hardware-autoresearch.md). Run fbuild port scan, then bash autoresearch lpc845 --pin-toggle-rx --upload-port <port> --timeout 120s --skip-lint. That bench currently toggles through the core's ::digitalWrite (AutoResearchLowMemory.h:372-383), so it does not test the new path. Switch it, or add a mode, to drive fl::pinMode/fl::digitalWrite, and run it with and without -DFASTLED_FORCE_SOFTWARE_PINS. A --ws2812-loopback run under the channels-API BIT_BANG driver would also show that bus now produces a signal. Also check an INPUT_PULLUP read on a pin whose IOCON index differs from its bit (e.g. PIO0_0 → index 17).
Risks / open questions
- Clockless under forced pins: static_assert (the precedent) versus keeping the native register path in
clockless_arm_lpc.hregardless of the forced setting. A WS2812 bit-bang at 15–24 MHz cannot run through a function call per edge, so static_assert seems right. The maintainer should confirm. - SWM ownership:
pinMode(Output)does not reclaim a pin from an SWM-assigned movable function or an enabled fixed function. This is documented, not fixed. Clearing PINENABLE0 automatically risks losing SWD. pinMode(Output)and IOCON MODE: the reset default on LPC8xx is pull-up. ShouldOutputleave MODE alone (Arduino convention) or set it inactive? The core sets it inactive (on the wrong pin).- Upstream core bug: the IOCON mis-indexing in
FastLED/framework-arduino-lpc8xxwiring_digital.cshould get its own issue in that repo. User sketches that callpinMode(n, INPUT_PULLUP)are affected today. - LPC11Uxx/LPC15xx FastPin base address/DIRSET: this is a pre-existing latent bug, not caused by this change. Reference it from LPC11Uxx/LPC15xx: verify modern GPIO template, no board entry in ci/boards.py #5108 so nobody "removes the #error" for those families on the assumption that the modern template is correct.
FL_IS_ARM_LPC_11_USB/_15without a vendor header: today they fall back to raw0xA0000000offsets, which are wrong for both. Any future backend for them must use tier-1/2 vendor headers peragents/docs/register-maps.md.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(lpc): native LPC845/LPC804 pin backend; honor forced software pins (
fix(lpc): on-board jumper scan; LPC845 pin-toggle-rx passes on silicon (