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.1.4 (+ companion PR #10964 for MSC buffer) 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 was fine before and is still fine.

test code

import board
  import busio
  import sdcardio
  import storage
  import time

  # Adalogger SD card on dedicated SPI (not board.SPI())
  spi = busio.SPI(clock=board.SD_CLK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
  sd = sdcardio.SDCard(spi, board.SD_CS, baudrate=8000000)
  storage.mount(storage.VfsFat(sd), "/sd")
  print("mounted /sd,", sd.count() * 512 // 1024 // 1024, "MB")

  while True:
      time.sleep(1)

Related

@mikeysklar mikeysklar marked this pull request as ready for review April 21, 2026 19:45
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 30b3221 to 518db8a Compare April 21, 2026 21:36
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