emUSB-Device FAQ

From SEGGER Wiki
Jump to: navigation, search

I want to use MSD and I want to write new files from the firmware so that they appear on the PC / I want to be notified when the PC copied new files onto the MSD volume and read them, how to do this?

This is not possible. Any modern operating system will read the file system information from the connected medium and will cache it. Meaning that if the firmware writes new files onto the storage the PC will not see them until the device has been re-connected. At worst the PC might overwrite the new files with something. A similar issue exists in the other direction, when a user copies a file from the PC onto the storage medium the PC might cache the write operation and might start to actually write the file at a later time. The order in which the PC writes data or file system information is not fixed, the PC can do whatever it wants, therefore it is not feasible to detect a new file until the device has been disconnected from the PC.

When a MSC device is connected to a USB host the host is the sole master of the storage medium. It can write or read at any point in time. Should the application try to access the storage medium at the same time as the host the results are unpredictable. To resolve this issue the device needs to detach the storage medium from the host, see USBD_MSD_RequestDisconnect(), USBD_MSD_Disconnect() and USBD_MSD_WaitForDisconnection() in the emUSB-Device documentation. Alternatively a different protocol, which supports simultaneous handling from both sides can be used - MTP