STM32 USB MSD Initialize but don't mount a volume

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

mck1117
Posts: 28
Joined: Wed Nov 11, 2020 6:41 am
Has thanked: 1 time
Been thanked: 5 times

STM32 USB MSD Initialize but don't mount a volume

Postby mck1117 » Thu Feb 11, 2021 11:15 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

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

Postby Giovanni » Fri Feb 12, 2021 10:55 am

Frankly I don't know how removable devices should be handled, the answer is buried in the MSD documentation probably.

Giovanni

mck1117
Posts: 28
Joined: Wed Nov 11, 2020 6:41 am
Has thanked: 1 time
Been thanked: 5 times

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

Postby mck1117 » Sat Feb 13, 2021 11:53 pm

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 24 guests