I'm getting stuck trying to figure out how to recover from a USB mass storage "error". This is for "bulk only" protocol. The root problem is that the RTOS we use is returning errors when they don't really exist and terminating transfers in the middle. I think I can fix that problem, but in the meantime I was trying to add some error checking and recovery to their mass storage driver. I'd also like to be able to recover from real errors if they ever happen.
What happens is that the CBW command bytes are sent successfully, then the data phase is interrupted mid-stream. When the host ignores the error and tries to read the CSW status it hangs forever.
My first approach was to detect the error and return from the transfer routine without reading the CSW. But the very next I/O operation will fail. I then tried doing doing a "bulk-only mass storage reset" operation, but that I/O also hangs. I then tried first clearing stalled endpoints out of desparation, and then doing the reset, but that didn't help.
So now I'm baffled. What I think is happening is that the mass storage devices are still waiting to read bytes from the data phase, and can not leave that state even if they see bytes on the control endpoint.
Is there anything I can do to clear this stuck state?
-- Darin Johnson