You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(nrf52): forced software FastPin hi()/lo()/toggle() use OUTSET/OUTCLR (#5396) - #5401
With FASTLED_FORCE_SOFTWARE_PINS on nRF52, FastPin<PIN> is the runtime-port template in src/fl/system/fastpin_base.h. Its hi()/lo() did *sPort |= mask / *sPort &= ~mask, which loads and stores the whole OUT latch. If an interrupt changes another pin on the same port between the load and the store, the store reverts that change. toggle() had the same read-modify-write.
Fix
The writes now go through a SoftwarePinWriter type that the preprocessor selects once:
nRF52:hi()/lo() (and the hi(port)/lo(port) overloads) do a single store to OUTSET/OUTCLR. toggle() reads OUT and then writes only OUTSET or OUTCLR, the same approach fix(nrf51): make FastPin toggle() race-free via OUTSET/OUTCLR (#5047) #5158 took for nRF51. The Arduino map returns &NRF_GPIO_Type::OUT, and the vendor CMSIS NRF_GPIO_Type is used to find OUTSET/OUTCLR from it (FL_OFFSETOF). No offsets are hand-written.
Every other platform: no behaviour change. Writes are still a read-modify-write of the output latch, and AVR still toggles through its PIN register.
Tests
New test tests/fl/system/fastpin_nrf52_set_clr.cpp. It sits on the non-PCH list next to fastpin_mapped_toggle/fastpin_avr_toggle because it picks a different FastPin provider before including the header. It models a GPIO block in which OUTSET/OUTCLR do not fold into OUT, so any store to OUT shows up in the result.
RED on master: 3/3 cases fail (OUTSET stays 0 and OUT gets rewritten from 0x81 to 0x89).
GREEN: bash test fastpin_nrf52_set_clr passes, and so does --debug (ASAN/UBSAN).
fastpin_mapped_toggle, fastpin_avr_toggle, fastpin_forced_no_pinmap and nrf52_pin still pass.
bash lint --cpp passes.
Limitation
No nRF52 board was attached, so this has not run on a device. The nRF52 changes were checked by host tests and by compiling with fbuild only: bash compile adafruit_feather_nrf52840_sense --examples Blink --defines FASTLED_FORCE_SOFTWARE_PINS succeeds.
Summary by CodeRabbit
Bug Fixes
Software-driven pin writes on nRF52 now set or clear the requested pin without changing the output state of other pins.
Pin toggling and writes continue to use platform-appropriate behavior across supported ports.
…OUTSET/OUTCLR (#5396)
The runtime-port FastPin used by FASTLED_FORCE_SOFTWARE_PINS did a
read-modify-write of the whole OUT latch, so an interrupt that changed
another pin on the same port between the load and the store was undone.
On nRF52 the pin writes now go through the vendor NRF_GPIO_Type's
OUTSET/OUTCLR, one store each; other platforms keep their existing writes.
A host test with a modelled GPIO block fails on the old code.
CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.
Parsing warnings: 1
Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
No actionable comments were generated in the recent review.
Walkthrough
With FASTLED_FORCE_SOFTWARE_PINS, runtime-port FastPin writes now use a platform-specific writer. On nRF52, the writer uses GPIO set and clear registers. Tests cover these writes and compile without the shared PCH.
Changes: Forced-software pin writes
Layer / File(s)
Summary
Platform-specific writes and validation src/fl/system/fastpin_base.h, tests/fl/system/fastpin_nrf52_set_clr.cpp, tests/meson.build
SoftwarePinWriter uses OUTSET and OUTCLR for nRF52 writes. Other platforms retain output-latch updates, with platform-specific toggle operations. Runtime-port FastPin methods delegate to the writer. Tests check nRF52 writes and confirm OUT is unchanged. Meson compiles the new test without the shared PCH.
FastLED/FastLED#5149: It selects the shared software FastPin template on nRF52, the same forced-mode path updated here.
Merge Risk: Minimal · up to cf4aa
This change makes forced-software pin writes on nRF52 use the GPIO set and clear registers, so an interrupt's update to another pin on the same port is no longer overwritten. Other platforms keep their existing behavior. No merge-blocking issues remain. The change is covered by a host test and has no on-device run.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: forced software FastPin hi()/lo()/toggle() writes on nRF52 now use OUTSET/OUTCLR. The raw summary confirms this is the core of the change. The title is specific and ma…
Linked Issues check
[#5396] The reviewed head implements the required fix in src/fl/system/fastpin_base.h. Under FASTLED_FORCE_SOFTWARE_PINS on FL_IS_NRF52, SoftwarePinWriter::hi()/lo() perform one store to OUTSET/OUTCLR…
Out of Scope Changes check
All changes support the objective of #5396. The fastpin_base.h changes add the SoftwarePinWriter selection and route the FastPin writes through it. The added includes (fl/stl/cstddef.h, fl/stl/int.h) …
Full details: Title check
Explanation
The title names the main change: forced software FastPin hi()/lo()/toggle() writes on nRF52 now use OUTSET/OUTCLR. The raw summary confirms this is the core of the change. The title is specific and matches the changeset. The fix(nrf52) prefix and the issue number #5396 are conventional and do not reduce relevance. The title is 80 characters, which is at the upper end of a concise title but still readable.
Full details: Linked Issues check
Explanation
[#5396] The reviewed head implements the required fix in src/fl/system/fastpin_base.h. Under FASTLED_FORCE_SOFTWARE_PINS on FL_IS_NRF52, SoftwarePinWriter::hi()/lo() perform one store to OUTSET/OUTCLR. The hi(port)/lo(port) overloads use the same writer. The OUTSET/OUTCLR offsets come from FL_OFFSETOF(NRF_GPIO_Type, OUT) and are not hand-written. toggle() reads OUT and writes only OUTSET or OUTCLR, so no store to OUT occurs for a single-pin write. The non-nRF52 branch keeps the prior read-modify-write and the AVR PIN-register toggle, so other platforms keep their behaviour. The new test tests/fl/system/fastpin_nrf52_set_clr.cpp models OUT, OUTSET and OUTCLR as separate registers. It asserts OUT is unchanged after hi(), lo(), hi(port), lo(port) and toggle(). This covers the host-test acceptance criterion. The author reports that the test fails 3/3 on master, that fastpin_mapped_toggle, fastpin_avr_toggle, fastpin_forced_no_pinmap and nrf52_pin pass, and that the forced nRF52 build succeeds. I did not re-run these results. No device run was done, so the real Nordic GPIO layout is not verified on hardware.
Full details: Out of Scope Changes check
Explanation
All changes support the objective of #5396. The fastpin_base.h changes add the SoftwarePinWriter selection and route the FastPin writes through it. The added includes (fl/stl/cstddef.h, fl/stl/int.h) support the new types and macros. The tests/meson.build change excludes fastpin_nrf52_set_clr from the shared PCH, as the other FastPin provider tests are excluded, so the test can select its own provider. The new test file covers the changed behaviour. No unrelated functional change was found in the reviewed diff.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Reviewing files that changed from the base of the PR and between 0df0973 and cf4aad0.
Files selected for processing: 3
src/fl/system/fastpin_base.h
tests/fl/system/fastpin_nrf52_set_clr.cpp
tests/meson.build
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 22, 2026
Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).
Target
FLASH [bytes]
RAM [bytes]
attiny85
2,460 (Same)
136 (Same)
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 22, 2026
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sanitizedTitle, body and conversation screened; review text requires separate screening.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5396.
Problem
With
FASTLED_FORCE_SOFTWARE_PINSon nRF52,FastPin<PIN>is the runtime-port template insrc/fl/system/fastpin_base.h. Itshi()/lo()did*sPort |= mask/*sPort &= ~mask, which loads and stores the wholeOUTlatch. If an interrupt changes another pin on the same port between the load and the store, the store reverts that change.toggle()had the same read-modify-write.Fix
The writes now go through a
SoftwarePinWritertype that the preprocessor selects once:hi()/lo()(and thehi(port)/lo(port)overloads) do a single store toOUTSET/OUTCLR.toggle()readsOUTand then writes onlyOUTSETorOUTCLR, the same approach fix(nrf51): make FastPin toggle() race-free via OUTSET/OUTCLR (#5047) #5158 took for nRF51. The Arduino map returns&NRF_GPIO_Type::OUT, and the vendor CMSISNRF_GPIO_Typeis used to findOUTSET/OUTCLRfrom it (FL_OFFSETOF). No offsets are hand-written.Tests
New test
tests/fl/system/fastpin_nrf52_set_clr.cpp. It sits on the non-PCH list next tofastpin_mapped_toggle/fastpin_avr_togglebecause it picks a different FastPin provider before including the header. It models a GPIO block in whichOUTSET/OUTCLRdo not fold intoOUT, so any store toOUTshows up in the result.OUTSETstays 0 andOUTgets rewritten from 0x81 to 0x89).bash test fastpin_nrf52_set_clrpasses, and so does--debug(ASAN/UBSAN).fastpin_mapped_toggle,fastpin_avr_toggle,fastpin_forced_no_pinmapandnrf52_pinstill pass.bash lint --cpppasses.Limitation
No nRF52 board was attached, so this has not run on a device. The nRF52 changes were checked by host tests and by compiling with fbuild only:
bash compile adafruit_feather_nrf52840_sense --examples Blink --defines FASTLED_FORCE_SOFTWARE_PINSsucceeds.Summary by CodeRabbit