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

henrysshunt
Posts: 12
Joined: Thu Jun 22, 2023 10:30 am

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

Postby henrysshunt » Fri Apr 25, 2025 3:08 pm

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.

henrysshunt
Posts: 12
Joined: Thu Jun 22, 2023 10:30 am

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

Postby henrysshunt » Tue Apr 29, 2025 11:25 am

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.

wxwx_wx
Posts: 1
Joined: Wed Jan 14, 2026 10:26 am

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

Postby wxwx_wx » Wed Jan 14, 2026 10:29 am

Have you found a solution to the problem? And how did you solve it?

Who is online

Users browsing this forum: Google [Bot], Qwantbot and 8 guests