This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB host MSC stack for TIVA- behaviour during random device removal

Hello,

How will the USBHMSCBlockWrite, USBHMSCBlockRead and USBHCDMain functions behave if the device is removed whilst a read\write  was in progress?

Regards

  • Nikhil,

    It is highly recommended that you do not remove the USB device before the MCU has closed it for exactly the reason you're hinting at here.

    If you pull the device in the middle of a BlockRead, the effects should be rather benign: it shouldn't damage the device, and USBLib has protection in place to gracefully recover from this condition.

    If you pull the device in the middle of a BlockWrite, very bad things will likely happen (ranging from minor data corruption to the entire device being trashed).  For this reason, it is highly recommended that you have the device open for as short a time period as possible.  It is also suggested that you provide some means of communication to your user that the device is busy, so they shouldn't remove it.  This can be something as obvious as text on the screen or something as simple as an LED being illuminated when the device is open, signalling the user that they should not remove it.

  • Thanks Stellaris,

    The data being corrupted or the device being trashed is a relatively minor problem here. The main issue is will the write functions block the program flow or not, since the other tasks in the main loop where USBHCDMain and the file write functions are called belong to a more critical control function.  It will be helpful if you could shed some light on this please.

    Regards

  • Nikhil Kant said:

    The data being corrupted or the device being trashed is a relatively minor problem here.

    Are you sure that is ok?  Any data you will have written is at risk to be disregarded, and the device itself will possibly become unusable.

    Regarding your question, though, error handling does exist in both the read and write methods to watch for a disconnect event.  As such, if the device is disconnected during a write transaction, the MCU will gracefully recover from that event and will not be stuck in an infinite loop waiting for a write to complete to a device that is no longer present.

    -Jordan

  • Thanks Jordan

    The data is being stored in the system in NV memory in circular fashion. USB stick is only intended to collect the data from the system periodically. Even though I am providing an LED and  warning  the user not to remove the USB stick if the LED is lit, I really have little control over what he does. In such a scenario I have to ensure that the system remains functional.

    Since the MCU will recover gracefully this solves my problem.

    Regards