AnsweredAssumed Answered

Known bugs in the OTG / USB library v2.1.0

Question asked by cisar.ivo.001 on Jan 21, 2014
Latest reply on Jun 20, 2016 by Bettega Stefano
Here is the list of known bugs in the USB / OTG library v2.1.0:

files - usbd_cdc_core.c / usbd_conf.h

ep descriptors should not use 

#ifdef USE_USB_OTG_HS

but use instead

#ifndef USE_EMBEDDED_PHY 

file - usb_bsp.c

function USB_OTG_BSP_Init 

For OTH-HS using Internal Phy

RCC_AHB1PeriphClockLPModeCmd( RCC_AHB1Periph_OTG_HS_ULPI, DISABLE);  

This problem was discovered some time ago, when OTG-HS is in use and device is put in sleep mode, the ULPI clocks must be switched off, otherwise the OTG functionality is broken.

Whenever GPIO_InitStructure is used, it must be properly initialized first (otherwise it is causing strange side effects):

GPIO_StructInit(&GPIO_InitStructure);

file - usb_dcd_int.c

Search for "emptyintr" occurence, where the source code is trying to clear this flag. There are two occurrences:

CLEAR_IN_EP_INTR(1, emptyintr);
CLEAR_IN_EP_INTR( epnum , emptyintr);

It is read only flag, which cannot be cleared, so this interrupt must be masked instead:

fifoemptymsk = 0x1 << epnum;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0)

This problem is causing high CPU load, but the USB is working.

file - usbd_core.c

USBD_Init function
correct order:  

/* Force Device Mode*/
USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);

/* Enable Interrupts */
USB_OTG_BSP_EnableInterrupt(pdev);

On some hosts this is blocking proper enumeration of our device.

file usbh_core.c
missing proper error handling 
USBH_HandleControl function

case CTRL_STATUS_IN_WAIT:
   

    URB_Status = HCD_GetURB_State(pdev , phost->Control.hc_num_in);
    
       
    if  ( URB_Status == URB_DONE)
    { /* Control transfers completed, Exit the State Machine */
      phost->gState =   phost->gStateBkp;
      phost->Control.state = CTRL_COMPLETE;
    }
   
    else if (URB_Status == URB_ERROR)
    {
      phost->Control.state = CTRL_ERROR; 
    }
    
    else if((HCD_GetCurrentFrame(pdev)\
      - phost->Control.timer) > timeout)
    {
      phost->Control.state = CTRL_ERROR;
    }
     else if(URB_Status == URB_STALL)
    {
      /* Control transfers completed, Exit the State Machine */
      phost->gState =   phost->gStateBkp;
      phost->Control.state = CTRL_STALL;     //added
      status = USBH_NOT_SUPPORTED;     //added
    }
    break;

Outcomes