AnsweredAssumed Answered

USB state machine hangs with some usb keys

Question asked by sullacorda on Aug 14, 2013
Latest reply on Jan 26, 2014 by moreto.miguel
I'm using the STM USB library version V2.1.0 with an host profile and I found a problem working with some usb keys: the library was going up to enumeration but after if was hanging. Debugging the problem I finally got that the problem was in usbh_core.c in function USBH_HandleControl at case CTRL_DATA_IN_WAIT.
If after sending a request in the previous case, CTRL_DATA_IN, I got a Stall irq in HCINT the library was hanging without trying again with another request.
I solved the problem adding a "phost->Control.state = CTRL_STALLED;" in the 
if  (URB_Status == URB_STALL)

    URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_in);
    /* check is DATA packet transfered successfully */
    if  (URB_Status == URB_DONE)
      phost->Control.state = CTRL_STATUS_OUT;
    /* manage error cases*/
    if  (URB_Status == URB_STALL)
      /* In stall case, return to previous machine state*/
      phost->gState =   phost->gStateBkp;
      phost->Control.state = CTRL_STALLED; ///<<<<< MY MODIFICATION
    else if (URB_Status == URB_ERROR)
      /* Device error */
      phost->Control.state = CTRL_ERROR;   
    else if ((HCD_GetCurrentFrame(pdev)- phost->Control.timer) > timeout)
      /* timeout for IN transfer */
      phost->Control.state = CTRL_ERROR;

Debugging the code I noticed in fact that it was going back to the previous state machine but not starting form its initial case but going directly in a case in the middle of the state machine.
I would like to have your feedback if my modification has any sense for you and if yes I would suggest to add it in the next release of the library.
With this modification now it works with all the usb key I found around in my collegues desks (10 different types).