ESP32 Bit Pirate home
  • USB
  • Intermediate
  • 3 min
  • Serial CLI

Recipe · Intermediate · USB

How to expose an SD card as USB storage

When an SD card is part of the setup, USB Mass Storage mode can expose it to the host as a drive.

USB mass storage connection to an SD card.
Move files through the board without removing the SD card when the hardware supports it.

Wiring View

SD card BP CSSPI CSCLKSPI CLKMISOSPI MISOMOSISPI MOSIGNDBP GND
Generated from the wiring summary: SD card to BP.
Step 1

Commands

Run the typed commands first. If the command opens an interactive shell, select the named action from the shell menu instead of treating it as another CLI command.

Result

What success looks like

The wiki notes that the storage command may take up to 30 seconds. Wait before assuming enumeration failed.

Troubleshooting

  • Using wrong SPI pins for the SD card.
  • Removing power while the host is writing.
  • Expecting instant enumeration.
  • Using a board without native USB device support.

Next steps

  • Confirm the SPI pins during the mode setup before starting storage.
  • Unmount/eject from the host before power cycling.
  • Use the SPI SD shell if you only need CLI file inspection.

USB mass storage SD card FAQ

What changes when SD is exposed as USB mass storage?

The host computer sees the Bit Pirate SD card like a removable drive. During that session, treat the card as shared storage and avoid simultaneous conflicting access paths.

What is the safest way to disconnect?

Unmount or eject the drive from the host first, then reset or unplug the board. Removing power during a host write can corrupt the filesystem.

When should I use the SPI SD shell instead?

Use the SPI SD shell for quick CLI inspection, small file checks or bench debugging. Use USB mass storage when the host needs direct file access or bulk copying.

Go deeper