Page 1 of 1

Correct way to end TinyUSB mass storage class (MSC) and fully release the SD card

Posted: Fri Apr 25, 2025 3:08 pm
by henrysshunt
What is the correct way to safely and orderly terminate TinyUSB MSC after the drive is ejected on the host, and fully deinitialise and release the card and SDMMC peripheral for our application to then use?

After ejection, while the card is then usable by our application, removing the card from the slot, for example, causes a constant stream of TinyUSB related errors, and reinserting the card doesn’t resolve this. TinyUSB MSC doesn’t handle the SD card being removed, which would be fine since our application’s own SD card handling code already handles card removal and remounting itself.

The problem is that TinyUSB MSC maintains control of the card even after unmounting. Once the card is ejected on the host, I need TinyUSB to completely end so our application can go ahead and mount the card using its own code.

I have been playing with various combinations of calls to the following functions from within the “card mounted back to application” callback: tinyusb_msc_storage_unmount(), tinyusb_msc_storage_deinit(), sdmmc_host_deinit() and tinyusb_driver_uninstall(). None of this has resulted in the desired functionality, or has resulted in errors and crashes of the whole application or errors on the host side when ejecting.

Does anyone know what the solution to this would be? Once USB has been ejected I don’t want TinyUSB to have any further contact or link with the SD card.

Re: Correct way to end TinyUSB mass storage class (MSC) and fully release the SD card

Posted: Tue Apr 29, 2025 11:25 am
by henrysshunt
Problem was caused by trying to do all of this deinitialisation in the USB mount changed callback, which comes from the USB task. Doing it from a separate task resolved the issues and allowed me to deinitialise everything as required.

Re: Correct way to end TinyUSB mass storage class (MSC) and fully release the SD card

Posted: Wed Jan 14, 2026 10:29 am
by wxwx_wx
Have you found a solution to the problem? And how did you solve it?