2017-04-05 04:43 AM
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?)
2017-04-05 06:05 AM
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.