I assume that you are using FX3 device.
Under such cases, the 'Reset Pipe' option in the USB Control Center can be used to flush the endpoint and reset the buffers in the device. Please refer to the CyFxBulkLpApplnUSBSetupCB() function in FX3 SDK examples.
Yes, I am using FX3 device. And the Reset Pipe works.
But My questions are: 1. Why will this happen? Is it a bug?
2. How could I recover this like Reset Pipe in the USB Control Center? I can not find the functions in CyAPI. And I think the CyFxBulkLpApplnUSBSetupCB() funtion is in a firmware example, not SDK examples.
1. FX3 commits data in buffers (buffer size is 32 bytes in your case). When the host requests for data that is less than this size, say 16 bytes, the device sends the entire buffer data to the host which will cause mismatch in the requested data length and the transferred data length. This will cause the endpoint to stall and the XferData fails.
To recover from this, the endpoint stall has to be removed. This is done by the 'Reset Pipe' option in the Control Center.
2. When the 'Reset Pipe' option in the Control Center is clicked, it calls the CyUSBEndPoint.Reset() API which in turn calls the IOCTL_ADAPT_RESET_PIPE in the CYUSB3 driver. This clears the stall condition in the endpoint and enables it for further data communication. When the host driver issues this command, the FX3 firmware must handle the request. This is what I mentioned that it is handled in the CyFxBulkLpApplnUSBSetupCB() function.
Thank you very much!
For question 2, I had tested CyUSBEnpoint.Reset() yesterday, but it did not work. I will verify it later. If it still doesn't work, I will ask you for help again.