Repository navigation
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughTwo targeted edits to ChangesLPC845 DMA trigger configuration and SYSCON shim correction
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h`:
- Around line 566-575: The TRIGPOL bit (bit 4) in the LPC_DMA->CHANNEL[base +
i].CFG register configuration is currently set to 0, but it needs to be set to 1
to correctly select the rising/high edge polarity that matches the SCT high
pulse triggers defined in rx_sct_capture.cpp.hpp. In the CFG assignment block,
change the line setting TRIGPOL from (0UL << 4) to (1UL << 1) to enable the
correct trigger polarity for edge-triggered DMA transfers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f43da66d-ffd9-45aa-98ff-8dad96c23a39
📒 Files selected for processing (1)
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
| // bit 4 TRIGPOL = 0 (Trigger Polarity: 0 = active high, 1 = active low.) | ||
| // bit 5 TRIGTYPE = 0 (Trigger Type: 0 = edge, 1 = level.) | ||
| // bit 6 TRIGBURST = 0 (Trigger Burst: 0 = single transfer, 1 = burst transfer.) | ||
| // bit 8-11 BURSTPOWER = 0 (Burst Power: 0 = 1 transfer, 1 = 2 transfers, ..., 15 = 16 transfers) | ||
| // bit 16-18 CHPRIORITY = 0 (Channel Priority: 0 = lowest, 15 = highest.) | ||
| LPC_DMA->CHANNEL[base + i].CFG = | ||
| (1UL << 0) | // PERIPHREQEN = 1 | ||
| (1UL << 1) | // HWTRIGEN = 1 | ||
| (0UL << 4) | // TRIGPOL = 0 | ||
| (0UL << 5); // TRIGTYPE = 0 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Set TRIGPOL for the SCT high pulse trigger.
Line 566 says TRIGPOL=0 is active-high, but the LPC DMA constants used in rx_sct_capture.cpp.hpp define bit 4 set as rising/high and use it for SCT DMA lines that pulse high. With TRIGTYPE=0 edge mode, leaving bit 4 clear can select the wrong edge/polarity and prevent the PWM DMA stream from firing at the intended match events.
Proposed fix
- // bit 4 TRIGPOL = 0 (Trigger Polarity: 0 = active high, 1 = active low.)
+ // bit 4 TRIGPOL = 1 (Trigger Polarity: rising edge / active high.)
// bit 5 TRIGTYPE = 0 (Trigger Type: 0 = edge, 1 = level.)
@@
(1UL << 0) | // PERIPHREQEN = 1
(1UL << 1) | // HWTRIGEN = 1
- (0UL << 4) | // TRIGPOL = 0
+ (1UL << 4) | // TRIGPOL = 1
(0UL << 5); // TRIGTYPE = 0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h` around lines 566 - 575,
The TRIGPOL bit (bit 4) in the LPC_DMA->CHANNEL[base + i].CFG register
configuration is currently set to 0, but it needs to be set to 1 to correctly
select the rising/high edge polarity that matches the SCT high pulse triggers
defined in rx_sct_capture.cpp.hpp. In the CFG assignment block, change the line
setting TRIGPOL from (0UL << 4) to (1UL << 1) to enable the correct trigger
polarity for edge-triggered DMA transfers.
|
I'm leaving this unmerged since it indicated WIP |
Two LPC845 register-offset bugs (issue FastLED#2990, fix PR FastLED#3349) traced back to hand-rolled `FL_LPC_*_Shim` structs whose offsets disagreed with NXP's `LPC845.h`. The bugs were invisible at compile time and only surfaced when contributors scoped the GPIO pin and noticed the LED pattern was wrong. Land documentation so future agents and contributors prefer vendor headers: - `agents/docs/register-maps.md` — new doc with the rule, why hand-rolled shims fail, a vendor-source table (NXP/ST/Nordic/Atmel/RPi/SiLabs/PJRC CMSIS repos with licenses), a tier-1/2/3 integration pattern, a reviewer checklist, and the LPC845 worked anti-example. - `CLAUDE.md` — new row in "Read the Right File for Your Task" pointing at the new doc. - `.claude/agents/platform-port-agent.md` + `.claude/skills/platform-port/SKILL.md` — cross-reference the doc before any peripheral struct is authored. - `src/platforms/arm/lpc/README.md` — pin the lesson at the scene of the crime; flag the existing shims as tier-3 fallbacks and tee up the longer-term tier-2 fix (vendor `LPC845.h` into `src/platforms/arm/lpc/cmsis/`). Closes the documentation gap behind issue FastLED#2990's "AI hallucinated register maps" comment. No code changes — follow-up PR will land the tier-2 LPC845 vendoring. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Hi @phatpaul — checking in on this one. The description still says "Still WIP, more to fix..." and the branch hasn't been updated in ~2 days. Could you let us know the current state? A few questions to help us figure out next steps:
If you want, we can merge what's here as an incremental step and you can follow up with the rest in a separate PR — just let us know. No rush, just don't want it to go stale. |
|
This is still very much unfinished WIP. I want to get the bit-bang version working before finishing this PWM+DMA driver. I want to remove all the hand-rolled register maps and require the use of the vendor provided CMSIS PAL files to build. If that is something your coding agent can do, please go ahead. Then I'll be happy to finish this implementation and test on real hardware. |
|
i see what's going on, the ai is not seeing the header files so it hallucinates and iterates on the register maps. And the fact that it kind of figured them out is pretty amazing. |
|
@phatpaul — picking up the register-map cleanup you flagged in #3349 (comment). Tracking it as meta #3437 (full 8-site audit of every hand-rolled LPC register map in the tree), and the first PR is in flight: #3438 — vendors NXP's #3438 is intentionally additive-only — it does NOT delete any shims yet, so it can't regress your branch. Subsequent PRs (per #3437's V5 / V6 / V2-V4 milestones) will:
Double-checked your #3349 fix against the vendor headerWhile preparing #3438 I cross-checked each shim member against the vendor ✅ ✅
Once #3438 + the V5/V6 follow-ups land, you should be unblocked to rebase #3349 onto a tree where 🤖 Generated with Claude Code |
|
Quick update on the #3437 cleanup path. After investigating where
Once that lands, FastLED stays on tier-1 ( PR #3438 is now a docs-only landing (audit list + policy clarification). The original V1 vendoring commits were reverted in 🤖 Generated with Claude Code |
Sites 1, 2, 3, 4 of FastLED #3437 audit list — clockless_arm_lpc_pwm_dma.h and spi_arm_lpc.h migrated to canonical NXP CMSIS PAL types/pointers. clockless_arm_lpc_pwm_dma.h: - Deletes FL_LPC_SCT_Shim, FL_LPC_DMA_Shim, FL_LPC_DMA_ChannelShim, FL_LPC_SYSCON_Shim and their #define LPC_SCT/LPC_DMA/LPC_SYSCON overrides - Deletes LPC_SCT_BASE/LPC_DMA_BASE/LPC_SYSCON_BASE #defines (vendor provides SCT0_BASE/DMA0_BASE/SYSCON_BASE) - Migrates all 26 call sites: LPC_SCT->... -> SCT0->... LPC_DMA->... -> DMA0->... LPC_SYSCON->... -> SYSCON->... LPC_SCT->MATCH[i].U -> SCT0->MATCH[i] (vendor stores as plain u32) LPC_SCT->MATCHREL[i].U -> SCT0->MATCHREL[i] LPC_SCT->LIMIT_L -> SCT0->LIMIT (vendor stores as plain u32) LPC_DMA->ENABLESET0 -> DMA0->COMMON[0].ENABLESET LPC_DMA->SETVALID0 -> DMA0->COMMON[0].SETVALID LPC_DMA->ACTIVE0 -> DMA0->COMMON[0].ACTIVE - Applies @phatpaul's #3349 DMA CHANNEL.CFG fix (was missing PERIPHREQEN bit, only setting HWTRIGEN). With vendor SYSCON_Type, the SYSAHBCLKCTRL0 bit-set in clockEnable() now writes to the correct hardware offset 0x80 (the pre-#3349 shim had it at 0x40). spi_arm_lpc.h: - Deletes FL_LPC_SPI_Type typedef; uses canonical vendor SPI_Type - FL_LPC_SPI0_BASE / FL_LPC_SPI1_BASE retained as aliases for the pSPIX template parameter (now defined as SPI0_BASE / SPI1_BASE from the vendor PAL) - All 6 SPI driver call sites now use SPI_Type via the pSPIX-cast pattern Three latent shim bugs structurally eliminated: 1. #3349 SYSAHBCLKCTRL0 offset (was 0x40, vendor truth: 0x80) 2. #3349 DMA CHANNEL.CFG missing PERIPHREQEN (now applied) 3. Newly uncovered SCT shim _L/_H pair bug (LIMIT/HALT/STOP/START were 8-byte pairs in the shim; vendor has them as single 4-byte regs). Every shim member from COUNT onwards was 16 bytes too high. Driver doesn't dereference those today, so this was latent — now impossible. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
V7 of FastLED #3437: hard-require the vendor PAL via #error checks in led_sysdefs_arm_lpc.h. If the toolchain failed to put <LPC845.h> / <LPC804.h> on the include path (no SCT0_BASE / PLU_BASE visible), the build now fails at preprocessing time instead of silently falling back on hand-rolled shims. agents/docs/register-maps.md: retires the 'Worked anti-example: LPC845' section. The three offset bugs are documented (#3349 fixed two, the third surfaced during #3437 cross-verification) along with the three-repo fix that resolved them. src/platforms/arm/lpc/README.md: marks audit sites 1, 2, 3, 4, 7 done. Sites 5 (LPC11 legacy, no CI), 6 (fastpin fallback, retained for LPC11/LPC15), and 8 (rx_sct_capture opt-in driver) deferred with rationale. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@phatpaul — your concern in #3349 (comment) is fully resolved. Three coordinated PRs landed end-to-end so the FastLED LPC drivers now consume NXP's canonical CMSIS PAL directly, no hand-rolled register maps in the build path. What landed
Your #3349 fix is now structurally guaranteed correctCross-checked your Your DMA Bonus latent bugs found while cross-verifyingThe migration uncovered four more offset bugs that were silently shipping but hadn't manifested:
The PLU bugs explain why the LPC804 PLU driver hadn't blinked an LED on hardware yet (#2880 pending). Vendoring the canonical What this means for #3349You're unblocked. Rebase
Three audit sites remain (LPC11 legacy GPIO, fastpin no-CMSIS fallback for LPC11Uxx/LPC15xx, and the rx_sct_capture opt-in driver) — all out of scope for your PWM+DMA work. They're tracked in the audit list in src/platforms/arm/lpc/README.md. Thanks for the push back in your original comment — the AI-hallucinated-register-map concern was exactly right, and the upstream-fix-first approach turned out to be the right move (no in-tree vendoring on the FastLED side, no maintenance burden). Looking forward to your hardware bring-up. |
First step of the meta FastLED#3437 plan to remove all hand-rolled LPC register maps. Vendors NXP's CMSIS Peripheral Access Layer for LPC845 (rev. 1.2, BSD-3-Clause) into src/platforms/arm/lpc/cmsis/ from upstream nxp-mcuxpresso/mcux-sdk @ SHA 8a289764. Purely additive — no existing call sites changed. Subsequent PRs will wire the header into led_sysdefs_arm_lpc.h (V5), then delete the three LPC845 PWM+DMA shims (FL_LPC_SCT_Shim, FL_LPC_DMA_Shim, FL_LPC_SYSCON_Shim) and migrate call sites to the vendor typedefs (SCT_Type, DMA_Type, SYSCON_Type) (V6). Verified against the new vendor header: - SYSCON_Type.SYSAHBCLKCTRL0 is at offset 0x80 — confirms @phatpaul's FastLED#3349 fix (_resv0[16]→[32]) is correct. The pre-FastLED#3349 master shim places it at 0x40, which is wrong. - DMA_Type.CHANNEL[].CFG/CTLSTAT/XFERCFG layout matches the shim's FL_LPC_DMA_ChannelShim member offsets. But the common-register block uses DMA0->COMMON[0].INTENSET (not LPC_DMA->INTENSET0) — the V6 call-site migration must rename these. - SCT_Type has each of LIMIT/HALT/STOP/START as a SINGLE 32-bit register (with optional 16-bit access via an inner union). The FL_LPC_SCT_Shim splits each into _L/_H 32-bit pairs (8 bytes each), which shifts every member from COUNT onwards 16 bytes too high. The driver does not (yet) dereference COUNT/STATE/INPUT/etc., so this hidden offset bug has not manifested — but it is a latent defect that vendoring eliminates structurally. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ad049ff to
483ccd4
Compare
(cherry picked from commit ea20f01)
|
Probably should have made a new PR. I'm adding some misc build fixes here as I find them. |
…C845 DMA cannot write GPIO at 0xA0000000 — ERRINT on the GPIO write! Needs new architectural plan. (cherry picked from commit 7c388f1)
|
Damn, seems that P0_0 (and any GPIO) can't be a DMA target on this chip. I can't find that in the datasheet or user manual. Edit: asked on the NXP forum: https://community.nxp.com/t5/LPC-Microcontrollers/LPC845-DMA-write-to-GPIO-fails/m-p/2389301#M59636 Edit: flagging @zackees |
|
DMA spi can be and it can be rerouted to any pin. Clock goes to -1 and data can be three bit resolution and fit in the ws2812 timing |
|
@phatpaul — you're right, and it's architectural, not an errata. Confirmed against the LPC824 user manual (same LPC800 family, same architecture, same bus topology as LPC845): UM10800 §1.4.1, p. 6: "The ARM Cortex-M0+ core supports a single-cycle I/O enabled port (IOP) for fast GPIO access at address 0xA000 0000." UM10800 Memory Map, p. 9: "The GPIO port and pin interrupt/pattern match registers are accessed by the ARM Cortex-M0+ single-cycle I/O enabled port (IOP)." UM10800 §12 DMA Block Diagram, Fig 19, p. 165: DMA controller connects to the AHB-LITE master interface at GPIO ( Practical consequence for this PR (#3349): the current Two paths forward that stay entirely on the AHB matrix: Path A — SPI-encoded WS2812 (@zackees's suggestion above, mechanically):
Path B — SCT-driven pin + DMA-fed MATCHREL:
Recommendation: ship Path A first — it reuses the shipped SPI-DMA transport, gets the LPC845 WS2812 story unblocked immediately, and works identically on LPC804 and LPC824. Path B is worth building as a follow-up chipset when SPI is needed for something else on a given board or when someone wants the extra RAM headroom. Thanks for pushing on this. Your NXP-forum question is the exact right escalation — if they confirm and get it into the DMA chapter of a future UM revision, it saves the next person a lot of scope time. Refs: LPC824 UM (UM10800) pp. 6 / 9 / 165 · This finding blocks the current #3349 architecture and reopens the discussion under closed meta #3517 · Related: #3506 peripheral-existence guardrail (needs extending to peripheral-capability / bus reachability) · NXP forum thread: https://community.nxp.com/t5/LPC-Microcontrollers/LPC845-DMA-write-to-GPIO-fails/m-p/2389301 |
|
Follow-up @phatpaul — UART+DMA is a viable third path too, and worth flagging because the LPC845 has more USART real estate than most people expect (bigger than LPC804 and LPC824), which makes "drive the LEDs and keep printing on the same chip" easy: LPC845 has 5 USARTs (USART0–USART4). Each one has:
Bus reachability sanity check: "Keep printing" mapping:
Encoding is fiddlier than SPI though. UART frames include start/stop bits and shift LSB-first, so the lookup table has to account for both. Standard recipe: baud ≈ 3–4 Mbaud, 6N1 or 8N1, encode each WS2812 bit as multiple UART bit-slots (start bit doubles as the mandatory HIGH edge in the WS2812 waveform), pre-bit-reverse each WS2812 byte before the lookup. Works well on other MCU families (STM32, ESP32 both have UART-WS2812 drivers in the wild) but the byte tables are less pretty than SPI's clean Three paths summary:
When to pick UART over SPI: if a board needs both SPIs for other peripherals (SD card + external DAC + APA102 strip, etc.), UART lets you keep them. If SPI is free, SPI is easier. Not blocking anything on #3349 — just wanted it in the record before you or anyone else picks the driver architecture. All three paths keep DMA on the AHB matrix and avoid the IOP wall. |
|
@phatpaul — promised status update: here's the full LPC845 driver inventory as of tonight, what's actually silicon-verified, and how to use each one. Everything below ran on a real LPC845-BRK today (2026-07-02); nothing is compile-only unless marked. ✅ Silicon-verified, ready to use1. SPI+DMA async driver (clocked strips — APA102/SK9822 class)
2. Async UART TX driver (drive a data lane AND keep printing)
3. Hardware watchdog + wedge backtrace
|
|
If I'm understanding correctly, Path B approach is similar to that described here: https://mcuoneclipse.com/2014/07/13/first-adafruit-neopixel-blinks-with-the-frdm-board/ we he uses DMA to write an array of 16-bit (2 bytes) Match values to the timer. That requires 2 bytes per bit * 24 WS2812 bits/LED = 48 bytes/LED. 300 LEDs = 14kB How did you reach the conclusion: "RAM cost: 3 bytes/LED (raw RGB, no expansion). Better memory density than Path A." Another note, since you said "and works identically on LPC804 and LPC824." - The LPC804 has no DMA, and max CPU clock is 15MHz so that practically rules out any approach that requires stuffing a TX register for each bit (SPI+DMA @ 2.4 MHz, UART+DMA @ ~3 Mbaud, SCT+DMA→MATCHREL). Additionally, LPC804 even lacks the SCTimer (it has the simpler CTimer, but that's a moot point b/c no DMA). I think the only viable option for LPC804 is the SPI+PLU method because it only requires 3 bytes per LED, so the software can keep up with filling the TX register. |
|
I would like to test thefl::ARMHardwareUARTOutputDMA<TX_PIN, BAUD> — src/platforms/arm/lpc/uart_arm_lpc_dma.h , but I don't see Also, is the fl::ARMHardwareSPIOutputDMA<DATA_PIN, CLOCK_PIN, CLOCK_DIVIDER> — src/platforms/arm/lpc/spi_arm_lpc_dma.h going to be capable of driving clockless strips too? Or will that be a separate driver? |
It's being added as a channel driver which is the new api because reasons. The template api will bind to it so you can just use addLeds<> as normal Yes the spi driver will also be a led driver with the clock pin either toggling harmlessly or set to -1 internally if it supports that. I'm not sure of the state of the spi driver for clockless but you can give it a try. I'll be on holiday and be back on the 5th. Feel free to let me know if it works for you |
|
The expansion to uart bits is an 8-1 expansion but the AI seems to believe that there is enough clock speed that the ISR can refill it so i think the memory requirements over bit bang will be a bounded constant |
|
@zackees Hope you had a great holiday. Sorry to be a pest, but the layers of abstraction are making my head hurt. I know you want this structured a certain way, so I don't want to waste time hacking it. |
|
@phatpaul You're not missing anything: The low-level transport exists in For normal LED-strip use through Short version: don't spend time hacking |
|
@phatpaul replying to your UART DMA test question here: #3349 (comment) The LPC845 UART DMA clockless path is now wired in as the default when The hardware loopback test is passing on LPC845 using USART TX-DMA plus USART RX-DMA through the normal FastLED API. Verified command: bash autoresearch lpc845 --uart --upload-port COM10 --no-auto-discover-pins --tx-pin 13 --rx-pin 11 --timeout 120s --skip-lintResult: PASS for Relevant links:
|
|
Promoting UART mode to auto mode so it's the default |
|
Ok it's promoted. Classical sketches should work on UART dma without modification now in the 845 I'm wrapping the tail end of issues and declaring victory on this. |




See #2990 corrected-more-lpc-registers
Still WIP, more to fix...
Summary by CodeRabbit