Page 1 of 1

STM32 USB MSD Initialize but don't mount a volume

Posted: Thu Feb 11, 2021 11:15 pm
by mck1117
Hello all, I have an STM32 with a composite USB device configured, one CDC and one MSD. The MSD lets you mount an SD card, while also communicating over CDC. This all works great. However, if the user removes the SD card, Windows gets unhappy.

Ideally I'd like it to behave like a normal SD reader: when you plug in USB it enumerates as an MSD, but doesn't enumerate any volumes. Then, if you stick a card in, it notifies the OS that a volume is now present (which the OS then mounts/reads/writes/whatever).

My problem is that if I don't call `msdStart`, Windows in particular has trouble using the CDC until some timeout occurs and it gives up on mass storage.

Does the API exist in the MSD driver to fully initialize the interface, but not actually mount a volume? I can sort of hack it by mounting a tiny ramdisk, but that's of course not ideal since Windows still pops the notification about a drive being connected, asks you to format it (which fails), etc.

Re: STM32 USB MSD Initialize but don't mount a volume

Posted: Fri Feb 12, 2021 10:55 am
by Giovanni
Frankly I don't know how removable devices should be handled, the answer is buried in the MSD documentation probably.

Giovanni

Re: STM32 USB MSD Initialize but don't mount a volume

Posted: Sat Feb 13, 2021 11:53 pm
by mck1117
Ok, I've figured out a solution to my problem! After some comparison of usbpcap traces between a normal SD reader and my device, I figured out that it's actually a SCSI problem, not an MSD problem. My solution is to create a block device that reports "no media" and reports success for all other operations.

Here's my implementation: https://github.com/rusefi/rusefi/blob/m ... device.cpp