Skip to content

Fixed wrong offsets in FL_LPC_GPIO_Type for LPC GPIO register map. - #3212

Merged
zackees merged 1 commit into
FastLED:masterfrom
phatpaul:fix/fastpin_arm_lpc_registermap
Jun 18, 2026
Merged

zackees merged 1 commit into
FastLED:masterfrom
phatpaul:fix/fastpin_arm_lpc_registermap

Conversation

@phatpaul

@phatpaul phatpaul commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Also, I had to add a line that inits the clock gating to the GPIO port in my main.cpp before calling fl::FastPin<LED_PIN>::setOutput(); Seems that is missing from the FastPin class and I didn't know where best to put it.

/*
 * main.cpp  
 * Based on example project from MCUXpresso SDK on LPC845
 */

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "app.h"

// #include "FastLED/fl/log/log.h"                          // fl::println
#include "FastLED/bitswap.cpp.hpp"                        // fl::platforms::begin
#include "FastLED/platforms/arm/lpc/platform_time_lpc.cpp.hpp"  // fl::platforms::delay, millis SysTick-based time implementation for LPC
#include "FastLED/platforms/arm/lpc/fastpin_arm_lpc.h"   // fl::FastPin<>

/*******************************************************************************
 * Definitions
 ******************************************************************************/

namespace {
// PIO0_15 on the LPC845-BRK / LPCXpresso845-MAX breakout header.
// Wire an external LED + series resistor here.
// (FastPin only covers PORT0 today, so the on-board RGB LED on
//  PORT1 isn't reachable yet — see fastpin_arm_lpc.h.)
constexpr unsigned LED_PIN  = 16;
constexpr unsigned BLINK_MS = 250;   // 2 Hz toggle
}  // namespace

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Main function
 */

extern "C" int main(void)
{
    /* Init board hardware. */
    BOARD_InitHardware();

    PRINTF("MCUX SDK version: %s\r\n", MCUXSDK_VERSION_FULL_STR);

    PRINTF("hello world.\r\n");

    GPIO_PortInit(GPIO, 0); // needed for FastPin<16> to work, since it uses the PORT0 DIR/SET/CLR registers directly without going through the GPIO driver
    fl::FastPin<LED_PIN>::setOutput();

    fl::u32 last_log_ms = fl::platforms::millis();

    for (;;) {
        fl::FastPin<LED_PIN>::hi();
        fl::platforms::delay(BLINK_MS);
        fl::FastPin<LED_PIN>::lo();
        fl::platforms::delay(BLINK_MS);
        PRINTF(".");

        const fl::u32 now = fl::platforms::millis();
        if ((now - last_log_ms) >= 2000) {
            PRINTF("heartbeat.\r\n");
            last_log_ms = now;
        }
    }
    return 0;
}

Summary by CodeRabbit

  • Bug Fixes
    • Corrected memory layout alignment for ARM LPC GPIO register handling to ensure proper operation.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75eac31b-6560-4d22-8972-aab04270fa47

📥 Commits

Reviewing files that changed from the base of the PR and between ec7dcc3 and 8fb06db.

📒 Files selected for processing (1)
  • src/platforms/arm/lpc/fastpin_arm_lpc.h

📝 Walkthrough

Walkthrough

The padding arrays inside the FL_LPC_GPIO_Type memory-mapped register struct are corrected: RESERVED0[1024 - 256] is replaced by an explicit RESERVED00[4032], and a separate RESERVED0[3840] field is introduced to preserve correct byte offsets for the DIR/MASK/PIN/MPIN/SET/CLR/NOT register block.

Changes

LPC GPIO Register Layout Fix

Layer / File(s) Summary
FL_LPC_GPIO_Type padding correction
src/platforms/arm/lpc/fastpin_arm_lpc.h
Replaces the previously computed RESERVED0[1024 - 256] with RESERVED00[4032] and updates the subsequent pad to RESERVED0[3840], realigning the struct's internal byte-pin (B) to word-pin (W) gap and the word-pin to control-register gap to the expected 0x1000/0x2000 boundaries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 A rabbit checked the offsets, found the padding wasn't right,
The RESERVED0 was shrinking, oh what a dreadful plight!
Now RESERVED00 stretches wide — four thousand thirty-two,
And RESERVED0 trims to three-eight-four-oh, perfectly in view.
The GPIO struct stands tall now, each byte aligned with care,
Hippity-hoppity memory maps — precision fills the air! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing incorrect register offsets in the FL_LPC_GPIO_Type structure, which is the primary focus of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@zackees
zackees merged commit 903f589 into FastLED:master Jun 18, 2026
1 check passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 18, 2026
@phatpaul
phatpaul deleted the fix/fastpin_arm_lpc_registermap branch June 24, 2026 17:19
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.

2 participants