Skip to content

SD card mount, eject and format, with hotplug detection#4

Merged
caveman99 merged 1 commit into
mainfrom
sd-card-hotplug
Jul 15, 2026
Merged

SD card mount, eject and format, with hotplug detection#4
caveman99 merged 1 commit into
mainfrom
sd-card-hotplug

Conversation

@caveman99

Copy link
Copy Markdown
Member

What does this PR do?

Follow-up to #3. Adds SD card control to the interdevice bridge so the main firmware can mount, eject and format the card behind the co-processor, and keeps the link responsive while the card is busy.

SD control commands

SD_MOUNT, SD_EJECT and SD_FORMAT arrive over the link and are answered with sd_info. Without an eject a card is mounted on its own and kept mounted; after an eject it stays released until a mount is asked for, so it can be pulled safely.

Non-blocking card access

Card maintenance (mount, format, the free space scan and card-removal recovery) can block for seconds, so it runs on core1 behind a mutex. Core0 claims the card per request with a try-lock and reports busy instead of waiting, so GPS forwarding and other requests keep flowing while the card is tied up.

Hotplug

A card pulled while the slot sits idle is detected by periodically re-initing it on the dedicated SPI bus (SdFat otherwise answers from cache and never notices). The raw probe and the formatter both run on SPI1 explicitly so they cannot re-mux the GPIO16/17 pins that carry the interdevice UART. A card that is present but carries no mountable filesystem is reported as unformatted.

Depends on the protobufs SD command definitions merged in meshtastic/protobufs#986; the submodule is bumped to that commit and the nanopb sources regenerated.

Add the SD control commands carried over the interdevice link: SD_MOUNT,
SD_EJECT and SD_FORMAT. Card maintenance (mount, format, the free space scan,
card-removal recovery) runs on core1 behind a mutex so a multi-second
operation never stalls the link; core0 claims the card per request with a
try-lock and reports busy instead of waiting for it.

Detect a card pulled while the slot sits idle by re-initing it on the
dedicated SPI bus, and report a card that is present but carries no mountable
filesystem as unformatted.

Bump the protobufs submodule to the merged SD command definitions and
regenerate the nanopb sources.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@caveman99, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: db29475d-dde3-4493-8c76-20c029a2f784

📥 Commits

Reviewing files that changed from the base of the PR and between 9462e30 and 5c50176.

📒 Files selected for processing (6)
  • protobufs
  • src/main.cpp
  • src/meshtastic/interdevice.pb.cpp
  • src/meshtastic/interdevice.pb.h
  • src/serial_proto.cpp
  • src/serial_proto.h

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.

@caveman99
caveman99 merged commit 5472a98 into main Jul 15, 2026
3 checks passed
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.

2 participants