Skip to content

Mount SD card at filesystem init so macOS can see it via USB MSC#10963

Open
mikeysklar wants to merge 1 commit intoadafruit:mainfrom
mikeysklar:pr-sd-automount-timing
Open

Mount SD card at filesystem init so macOS can see it via USB MSC#10963
mikeysklar wants to merge 1 commit intoadafruit:mainfrom
mikeysklar:pr-sd-automount-timing

Conversation

@mikeysklar
Copy link
Copy Markdown

@mikeysklar mikeysklar commented Apr 21, 2026

The SD card is currently mounted lazily when macOS sends the first TEST UNIT READY. That can lose a race: macOS sees NOT_READY, gives up, and never retries. Mounting at filesystem_init (right after sdcardio_init) means the card is live before USB enumerates.

Tested

Board CP version Result
Feather RP2040 Adalogger 10.2.0-rc.0 macOS mounts SD first try
Metro RP2350 10.1.4 stable No regression, SD still mounts
Fruit Jam (3-LUN: CIRCUITPY + CPSAVES + SD) 10.1.4 stable No regression

Host OSes: macOS 26.x (Apple Silicon M2), Ubuntu 24.04 (kernel 6.17). Linux is fine.

Related

Three-line diff in filesystem.c.

@mikeysklar mikeysklar marked this pull request as ready for review April 21, 2026 19:45
@mikeysklar mikeysklar force-pushed the pr-sd-automount-timing branch from 30b3221 to 518db8a Compare April 21, 2026 21:36
@bablokb
Copy link
Copy Markdown

bablokb commented Apr 22, 2026

automount_sd_card() is protected in supervisor/shared/usb/usb_msc_flash.c: it is only called if there is a LUN for the SD-card. Which can be disabled by CIRCUITPY_SDCARD_USB.

So I suggest that you also test CIRCUITPY_SDCARD_USB in your #ifdef

The lazy automount in tud_msc_test_unit_ready_cb can lose races with
macOS's USB MSC probe timing -- the host asks whether LUN 1 is ready
before the card has finished mounting, sees NOT_READY, and may give up
before trying again. Mounting during filesystem_init ensures the SD
card is live by the time USB enumerates, so the first probe succeeds.

Affects boards that define DEFAULT_SD_CARD_DETECT; behavior on boards
without an auto-mount path is unchanged.
@mikeysklar mikeysklar force-pushed the pr-sd-automount-timing branch from 518db8a to b12c140 Compare April 22, 2026 13:55
@mikeysklar
Copy link
Copy Markdown
Author

Good catch — you're right that CIRCUITPY_SDCARD_USB is the matching precondition. The call site in usb_msc_flash.c gates on SDCARD_LUN, which only exists when CIRCUITPY_SDCARD_USB=1, so tying the new call site to the same condition keeps the two aligned.

Updated in the latest commit: #if defined(DEFAULT_SD_CARD_DETECT) && CIRCUITPY_SDCARD_USB. Verified locally on a Feather RP2040 Adalogger — SD still mounts via MSC on macOS first try. Thanks!

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Thanks!

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.

3 participants