cancel
Showing results for 
Search instead for 
Did you mean: 

Can you access a SD card through USB MSC and FATFs at the same time?

anonymous.8
Senior II
Posted on June 02, 2017 at 21:28

I have a STM32F746NG Discovery board on which I have implemented a USB Composite device with MSC and custom HID classes. I also want to run Elm-Chan's FATFS to read and write files locally on the micro-SD card whilst the USB is still connected.

I have read that you can't have two file systems accessing the SD card at the same time. Superficially this does make sense. However I have successfully implemented exactly this scheme on a PIC32 device which has successfully been in production for the last five years. However the PIC32 USB device stack is completely different from the STM32 one and is implemented totally differently so the two are not comparable.

I tried adding a low level lock to the SDcard ReadBlocks and WriteBlocks functions to make sure they could not be accessed from the FATFs and USB MSC at the same time, but the application just locks up.

If I don't have the locks in place the SD card gets corrupted and I have to reformat it each time.

Has anyone successfully done this and if so, how?

Thanks.

#usb #msc #fatfs
3 REPLIES 3
Posted on June 02, 2017 at 22:46

The problem on windows systems is that the MSC can be cached and have a lazy-writer, so there are coherency issues about what you have on the card vs what the PC thinks it has, and what it might subsequently flush to the media.

Sending media changed notifications can be disruptive (think auto-run, speed-test or AV)

Issues therefore run the gamut from annoying user experience, to corruption of data and file system. Not the kind of tech support calls I wish on friends...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 03, 2017 at 00:48

Clive, thanks for that. I looked again at my old PIC32 USB MSC code that is working in production to see how I made it work. Basically I temporarily disabled the MSC portion of the USB Composite Device whenever I wanted to to use the local FATFS so the two were never actually active at the same time.

Microchip had a non-interrupt driven USB Device stack (at the time) and you had to place a function call to a USB driver in your main application loop. So I simply chose to not call that function when I needed to access the SD card locally.

STM's USB Device driver works completely differently so I have to figure out at what level I should disable the MSC interface, but that's for another day.

Hi David,

I am attempting to develop a similar project on the STM32F407 using FatFS and the HAL USB drivers.

Did you manage to work out the issue?

Cheers

Allan