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.

Code hangs in USBHCDPipeWrite() using older USB stick

When running the latest StarterWare we plugged in a older USB stick and the following sequence occurs in USBHCDPipeWrite function (usbhostenum.c):

- Entry USBHCDPipeWrite()
- ulRemainingBytes set to 0x1F.
- Enter ulRemainingBytes != 0 loop (line #928).
- USBEndpointStatus (line #1024) returns a USB_HOST_OUT_ERROR.
- g_sUSBHCD[ulIndex].USBOUTPipes[ulPipeIdx].eState = PIPE_ERROR (line #1037).
- StopTimer called (line #1053).
- g_sUSBHCD[ulIndex].USBOUTPipes[ulPipeIdx].eState == PIPE_ERROR (line #1100).
- USB_TIMEOUT_DISABLE!=g_sUSBHCD[ulIndex].USBHTimeOut.Value.slNonEP0 (line #1102).
- ulTimer is currently 0xBB8, skips over if(!ulTimer) line #1104.
- ulRemainingBytes < 64 (line #1140).
- ulByteToSend = ulRemainingBytes (0x1F), line #1142.
- Back to top of ulRemainingBytes != 0 loop (line #928).
- Repeat sequence forever.

So this particular USB stick is a problem for the USB drivers, but what is the proper fix for this?

- Should the ulTimer be cleared when the timer is stopped?

- Should there be an else statement off the if (!ulTimer) on line #1104 with a ulSize set to zero and then break;?

Thanks.

  • Hi John,

    This seems to corner case which was missed in the code. The problem as the error code indicates, is because the device is not responding to the SCSI command ( 31 bytes ).

    Usually devices respond to the SCSI command sent with an ACK but in your case the USB stick seems to have not responded  to even that. The solution to this problem is to clear the ulTimer  when it is stopped.  I prefer this approach because it would force the device to be reset and reconnected again --   if(!ulTimer) code does this. Your second suggestion would not help ,as even if  you return from the function , the OUT pipe of the device is non operational and the USB stick would be pretty much useless.

    Could you please give this a try . Please understand that this problem could keep coming and you would end up resetting and re enumerating the device as long as the device is faulty. 

    Cheers

    Vineeth

  • Vineeth,

              Just a quick clarification. I should set ulTimer to zero on line #1054 after the StopTimer() call?

    Thanks,

         John C.

  • That is  right John . That should cause the re connect logic to kick in .

  • Vineeth,

         I have tried the fix and it seems to work well. My only other question would be that the logic flow of USBHCDPipeWrite() is very similar to USBHCDPipeRead(). Is it possible that the same error could occur during a read?

    Thanks,

          John C.

  • Hello John,

    USBHCDPipeRead()  is very similar to the  USBHCDPipeWrite() . The current pipe read function checks for USB_HOST_OUT_ERROR which is wrong because we are trying to read and not send out data. Hence this error would never come for a pipe read. I will try to correct this function though.

    Once again thanks fro pointing out!!



  • Hello John ,

    Just to add please replace the check 

    else if(ulEPStatus & USB_HOST_OUT_ERROR)  //

    with

    else if(ulEPStatus & USB_HOST_IN_ERROR)

    and clear the timer value when it is being stopped ( as it was done in pipewrite function).

     



  • Hi Vineeth,

         So you want me to change line #1415 from:

                else if(ulEPStatus & USB_HOST_OUT_ERROR)
         to:

                else if(ulEPStatus & USB_HOST_IN_ERROR)

        Also on line #1434, clear the timer value with "ulTimer = 0;"

    Is this correct?

    Thanks,

         John C.