Skip to content

fix(nrf54): route SoC events drained by the flash driver through the SD event handler - #12048

Open
cvaldess wants to merge 5 commits into
meshtastic:developfrom
cvaldess:fix/nrf54-soc-events-during-flash-wait
Open

cvaldess wants to merge 5 commits into
meshtastic:developfrom
cvaldess:fix/nrf54-soc-events-during-flash-wait

Conversation

@cvaldess

@cvaldess cvaldess commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Arduino core's flash driver now bounds its wait for the SoftDevice flash-completion event and drains the SoC event queue itself while it waits (meshtastic/nRF54_Arduino#1). On the nRF54L15-DK, a LittleFS commit during a BLE connection used to freeze the whole firmware, BLE included, when that completion got lost; a reset in the middle of the write is what wiped the saved config.

Any other SoC event the driver pulls out of the queue while it waits has to get the same handling as in checkSDEvents(). This factors the switch into handleSDEvent() and hands it to the driver's weak flash_nrf5x_soc_event_hook.

Without the core change the hook is never called, and the firmware behaves exactly as before, so the two can land in either order.

Testing

nRF54L15-DK + E22-900M30S with the core change, Meshtastic 2.8.1 and 2.8.2, iOS app connected over BLE, on a live mesh: config saves over BLE complete. Every hang captured live since 2026-09-20 (several multi-day soaks) was the GRTC idle hang fixed in the core; none happened in a flash write.

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

nRF54L15-DK only; the change is in src/platform/nrf54/.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of device power warnings, flash-operation results, and random-seed requests. These events are now handled consistently whether received through the SoftDevice event queue or passed along by the flash driver. Unexpected events continue to be logged, helping make device behavior and diagnostics more consistent.

…SD event handler

The core's flash driver now bounds its wait for the SoftDevice flash-completion event and
drains the SoC event queue itself while waiting, so a lost completion can no longer park the
writing task forever (seen on the nRF54L15-DK: a LittleFS commit during a BLE connection froze
the whole firmware, BLE included, and a reset mid-write is what wiped the saved config).
Whatever else it pulls out of the queue must get the same treatment as checkSDEvents(), so
factor the switch into handleSDEvent() and hand it to the driver's flash_nrf5x_soc_event_hook.
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: meshtastic/firmware/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb3b0a35-dc89-46e6-be63-d9bd8b69ef60
📥 Commits

Reviewing files that changed from the base of the PR and between 3f8347b and 9fa220a.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: meshtastic/firmware/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 10f78c03-3683-48cd-ad92-5594b44fc0c7

📥 Commits

Reviewing files that changed from the base of the PR and between 80ea7f1 and 5dc1741.

📒 Files selected for processing (1)
  • src/platform/nrf54/main-nrf54.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

SoftDevice event handling now uses a shared dispatcher. The flash-driver hook routes drained events through it, and checkSDEvents uses it for polled events.

Changes: nRF54 event dispatch

Layer / File(s) Summary
Shared SoftDevice event dispatch
src/platform/nrf54/main-nrf54.cpp
handleSDEvent handles brownout warnings, flash results, random-seed requests, and unexpected events. The new flash_nrf5x_soc_event_hook and checkSDEvents both route events through this handler.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 5dc17

No demonstrated issue blocks merging. Confirm that the paired core change invokes the hook during flash waits as part of integration testing.

### Architecture Summary

Architecture risk: 🟡 Medium · up to 5dc17

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/platform/nrf54/main-nrf54.cpp: Added handleSDEvent to dispatch SoftDevice events and a C-linkage flash_nrf5x_soc_event_hook that sends events drained by the core flash driver through the same dispatch. Brownout events record a critical error; flash completion/error events reach the flash driver; random-seed requests invoke seedSoftDevice; other events are debug-logged.
  • observed — Modified behavior in src/platform/nrf54/main-nrf54.cpp: checkSDEvents now delegates each polled SoftDevice event to handleSDEvent instead of containing its own event switch; the event-specific handling is unchanged.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_2; direct_dependents_2
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the nRF54 fix and the routing of SoC events through the SoftDevice event handler.
Description check ✅ Passed The description explains the problem, implementation, compatibility with the core change, testing performed, and hardware limitations. The required attestations are completed, and the untested devices…
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

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.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Note

Building this pull request… the flash button, badges and supported-board
list will appear here automatically once CI finishes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant