Several of our products use (one or more) NXP LPC4357 microcontrollers. Some of them have a USB host implementation on USB0 to allow the user to store and retrieve data on a USB Mass Storage Class device (Flash drive , USB key, external drive, etc). For the majority of drives this works fine, but there are a number of Sandisk products that enumerate correctly, but fail on the first attempt to write to the drive.
The issue can be reproduced using the following system:
- MCB4300 development board
- LPCOpen v2.20 LPCXxpresso and Keil IAR MCB4357 (Using the Mass Storage Host example application).
- Keil uVision 4
- Sandisk Ultra 16 GB, or Cruzer Switch 16 GB
I know that the libraries and IDE are old, but they are closest to the setup that we have in most of our products, and reflect the development environment that we use in house. I know that the devices are USB 3.0, but they do work with USB 2.0 hosts on other platforms.
The drives complete the LPC open enumeration without error, but the first time the MS_Host_WriteDeviceBlocks() function is called, the device STALLs the IN endpoint during the Status Transaction stage of the Write command following hundreds or thousands of IN/NAKs. I've made some changes in EHCI.c to disable the periodic scheduler and limit the NakCount in the Queue head structure for non-interrupt endpoints to four, but this does not change the STALL behaviour.
The version of the LPCOpen library above (the is the most recent one that I could find that actually includes a Host MSC example) does not have an implementation of the HcdClearEndpointHalt() function, so the endpoint remains in a halted state and the Reset Recovery procedure is repeated indefinately. (I have coded a simplistic implementation for this function, which clears the TD list, terminates the Queue Head TD list and clears the overlay TD's halted flag. This works, but appears to leave an IN transaction in the Host controller's asynchronous schedule, which I can't figure out how to remove.)
I have contacted Sandisk technical support, but they cannot provide engineering support because "these drives are not qualified to work with development platforms".
Is there a version of the LPCOpen library that has the STALL recovery mechanism implemented?
Is there a more recent version of the library that works with these drives on a bare-metal implementation?
Any help would be greatly appreciated.