AnsweredAssumed Answered

STM32Cube_FW_F2_V1.1.0 question - bug ?

Question asked by sdt99 on Apr 22, 2014
Latest reply on May 29, 2014 by Montassar BEN ROMDHANE
STM32Cube_FW_F2_V1.1.0\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c

uint8_t  USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
{
  USBH_InterfaceDescTypeDef    *pif ;
  USBH_CfgDescTypeDef          *pcfg ;
  int8_t                        if_ix = 0;
  
  pif = (USBH_InterfaceDescTypeDef *)0;
  pcfg = &phost->device.CfgDesc;  
  
  if((pif->bInterfaceClass == 0xFF) &&(pif->bInterfaceSubClass == 0xFF) && (pif->bInterfaceProtocol == 0xFF))
  {
    return 0xFF;
  }

while (if_ix < USBH_MAX_NUM_INTERFACES)
  {
    pif = &pcfg->Itf_Desc[if_ix];
  <snipped>
  
Maybe I'm not understanding this, but it looks like the pointer pif is set to address 0 and then is immediately dereferenced in the if statement.  I can't see how this can possibly work.  

It looks to me like the if((pif->bInterfaceClass == 0xFF) might need to be inside the while() loop, right after pif is assigned the address of one of the interface descriptors.

Outcomes