Skip to content

fix(lpc): use vendor SYSCON_SYSAHBCLKCTRL0_*_MASK — closes #3517 Phase B.3 SYSCON audit - #3533

Merged
zackees merged 1 commit into
masterfrom
feat/lpc-syscon-vendor-macros
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/lpc-syscon-vendor-macros

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Phase B.3 of #3517 partial delivery — migrate the two SYSCON->SYSAHBCLKCTRL0 |= (1UL << 29) sites to vendor CMSIS macros with UM section citations.

Verified against NXP mcux-sdk

#define SYSCON_SYSAHBCLKCTRL0_DMA_MASK  (0x20000000U)  // SHIFT = 29U
#define SYSCON_SYSAHBCLKCTRL0_SCT_MASK  (0x100U)       // SHIFT = 8U

Both match the existing raw literals. UM11029 §4.6.13 Table 41 is the datasheet source.

Sites touched

  • src/platforms/arm/lpc/spi_arm_lpc_dma.h — replaces (1UL << 29) with SYSCON_SYSAHBCLKCTRL0_DMA_MASK, drops TODO(3453): verify SYSCON->SYSAHBCLKCTRL0 bit 29
  • src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp — replaces (1UL << 8) | (1UL << 29) with SYSCON_SYSAHBCLKCTRL0_SCT_MASK | SYSCON_SYSAHBCLKCTRL0_DMA_MASK, drops TODO(2842)

No behavioral change — the mask values are identical.

Verification

  • bash test --cpp — 345/345 pass

Refs: #3517 Phase B.3, agents/docs/register-maps.md.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Summary by CodeRabbit

  • Refactor
    • Updated low-level hardware initialization to use standard named clock-enable constants instead of hard-coded bit values.
    • Kept device startup behavior unchanged while improving consistency and maintainability across ARM/LPC DMA and SPI support.

…e B.3 SYSCON audit

Two matched call sites — SPI+DMA driver (`spi_arm_lpc_dma.h`) and SCT+DMA
runtime (`drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp`) — both power up
DMA0 via `SYSCON->SYSAHBCLKCTRL0 |= (1UL << 29)` with `TODO(3453)` /
`TODO(2842)` markers asking for the bit position to be verified against
UM11029 §4.6.13.

Verified against NXP mcux-sdk `devices/LPC845/LPC845.h`:

    #define SYSCON_SYSAHBCLKCTRL0_DMA_MASK  (0x20000000U)
    #define SYSCON_SYSAHBCLKCTRL0_DMA_SHIFT (29U)

    #define SYSCON_SYSAHBCLKCTRL0_SCT_MASK  (0x100U)
    #define SYSCON_SYSAHBCLKCTRL0_SCT_SHIFT (8U)

Both match the legacy driver's bit assignments (bit 29 = DMA clock,
bit 8 = SCT clock). Migrating to the vendor macros:

- Kills the raw `(1UL << 29)` / `(1UL << 8)` magic numbers at the call
  sites.
- Removes the "TODO verify" markers — the vendor CMSIS PAL is the source
  of truth per `agents/docs/register-maps.md`.
- Adds an authoritative citation (UM11029 §4.6.13 Table 41 + vendor
  macro name) on every touched line, per `agents/docs/register-maps.md`
  reviewer checklist bullet 3.

Contributes toward #3517 Phase B.3 acceptance (\"verify
SYSCON->SYSAHBCLKCTRL0 bit 29 is DMA per UM11029 §4.6.13 and cite the
section\").

## Verification

- `bash test --cpp` — 345/345 pass (unchanged)
- Grep confirms no other `(1UL << 29)` sites remain in the LPC tree
  that need the same migration
- No behavioral change — the mask value is identical to the prior
  literal, just now expressed via the vendor CMSIS macro

Refs: #3517 Phase B.3, `agents/docs/register-maps.md`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit f83569a into master Jul 1, 2026
8 checks passed
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cfb04e8d-0138-4dcb-8568-978ec796d10c

📥 Commits

Reviewing files that changed from the base of the PR and between 508a5db and 8602cba.

📒 Files selected for processing (2)
  • src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp
  • src/platforms/arm/lpc/spi_arm_lpc_dma.h

📝 Walkthrough

Walkthrough

Two LPC845 driver files were updated to replace hard-coded bit-shift expressions for enabling SCT and DMA clocks with named SYSCON_SYSAHBCLKCTRL0 mask constants. Comments were revised to reference these constants. No functional behavior or public API changes occurred.

Changes

SYSCON Clock Mask Usage

Layer / File(s) Summary
Named mask constants for SCT/DMA clock enable
src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp, src/platforms/arm/lpc/spi_arm_lpc_dma.h
Replaces hard-coded shifts (1UL << 8, 1UL << 29) with SYSCON_SYSAHBCLKCTRL0_SCT_MASK/SYSCON_SYSAHBCLKCTRL0_DMA_MASK when writing SYSAHBCLKCTRL0 to enable SCT and DMA0 clocks; comments updated to match.

Estimated code review effort: 1 (Trivial) | ~3 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/lpc-syscon-vendor-macros

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

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant