cancel
Showing results for 
Search instead for 
Did you mean: 

Using SDIO for both USB Mass Storage Device and FATFS

henk23
Associate II
Posted on April 05, 2017 at 13:43

Hi,

Over the past ~18 months we have made an stm32F405 based logging device. Data is gathered and stored to SD card, when USB is plugged in, the SD card is 'owned' by the Mass Storage Device implementation that we got from the Cube.

After we detect enumeration, we still have to fiddle with FATFS to finish the current log file correctly, and to prevent USB from coming in between (which it does; mass storage is completely handled from USB interrupt context) I simply disable the USB interrupt, do my thing with FATFS and enable the interrupts again. I actually consider this a poor man's solution and I am wondering if there is not a better way to do this. I have seen it lose the enumerated state while the interrupts were turned off, only to regain it immediately after interrupts are turned on again.

Does anyone know if there is a way to keep USB active, but restrict it from accessing SDIO and tell the host 'not now, try again in a few milliseconds' (possibly by sending STALL packets?)

1 REPLY 1
Posted on April 05, 2017 at 15:05

SCSI provides SENSE CODES and TEST UNIT READY to push off the host.

The bigger issue is one of coherency between the media and the file system and caching on the host. It would be very easy to trash the file system.

Throwing a MEDIA CHANGED type sense code would be the way to handle that, but I'm not sure how well the host would react/respond to that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..