STMicroelectronics / stm32-mw-usb-host

Provides the USB Host library part of the STM32Cube MCU Component "middleware" for all STM32xx series.
Other
32 stars 15 forks source link

USBH_ParseCfgDesc hanging in the while #11

Closed NimaAgm closed 7 months ago

NimaAgm commented 1 year ago

Describe the set-up

Describe the bug

  1. I just have activated mass storage class for stm32 host in stm32f730
  2. Connect an android phone using usb cable
  3. Select Input MIDI in USB settings of a android phone
  4. Code would hang in USBH_ParseCfgDesc

In this state

`

    while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength))
    {
      pdesc = USBH_GetNextDesc((uint8_t *)(void *)pdesc, &ptr);

      **if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT)** // next iteration condition is false pdesc->bDescriptorType =0
      {
        /* Check if the endpoint is appartening to an audio streaming interface */
        if ((pif->bInterfaceClass == 0x01U) && (pif->bInterfaceSubClass == 0x02U)) // Input midi results in bInterfaceSubClass=0x03
        {
          /* Check if it is supporting the USB AUDIO 01 class specification */
          **if ((pif->bInterfaceProtocol == 0x00U) && (pdesc->bLength != 0x09U))** 
          {
            pdesc->bLength = 0x09U;
          }
        }
        /* Make sure that the endpoint descriptor's bLength is equal to
           USB_ENDPOINT_DESC_SIZE for all other endpoints types */
        else
        {
          **pdesc->bLength = USB_ENDPOINT_DESC_SIZE;** // This part results in zeroing pdesc in the next iteration 
        }

        pep = &cfg_desc->Itf_Desc[if_ix].Ep_Desc[ep_ix];

        status = USBH_ParseEPDesc(phost, pep, (uint8_t *)(void *)pdesc);

        ep_ix++;
      }
    }

` I Have disabled this part of the code which made my application to work in this state:

if 0

        /* Check if the endpoint is appartening to an audio streaming interface */
        if ((pif->bInterfaceClass == 0x01U) && (pif->bInterfaceSubClass == 0x02U))
        {
          /* Check if it is supporting the USB AUDIO 01 class specification */
          if ((pif->bInterfaceProtocol == 0x00U) && (pdesc->bLength != 0x09U))
          {
            pdesc->bLength = 0x09U;
          }
        }
        /* Make sure that the endpoint descriptor's bLength is equal to
           USB_ENDPOINT_DESC_SIZE for all other endpoints types */
        else
        {
          pdesc->bLength = USB_ENDPOINT_DESC_SIZE;
        }

endif

Thanks a lot

danngreen commented 1 year ago

I can confirm this. I came here to report this bug, and also a simple fix:

Change line 492:

            /* Check if the endpoint is appartening to an audio streaming interface */
            if ((pif->bInterfaceClass == 0x01U) && (pif->bInterfaceSubClass == 0x02U))

to this:

            /* Check if the endpoint is appartening to an audio streaming interface */
            if ((pif->bInterfaceClass == 0x01U) && ((pif->bInterfaceSubClass == 0x02U) || (pif->bInterfaceSubClass == 0x03U)))

The bug is that v3.5.0 sets the descriptor length to 7 (USB_ENDPOINT_DESC_SIZE) if the device is a streaming MIDI device (subclass 0x03). It should be set to 9, same as streaming audio subclass 0x02.

NimaAgm commented 1 year ago

Th

I can confirm this. I came here to report this bug, and also a simple fix:

Change line 492:

            /* Check if the endpoint is appartening to an audio streaming interface */
            if ((pif->bInterfaceClass == 0x01U) && (pif->bInterfaceSubClass == 0x02U))

to this:

            /* Check if the endpoint is appartening to an audio streaming interface */
            if ((pif->bInterfaceClass == 0x01U) && ((pif->bInterfaceSubClass == 0x02U) || (pif->bInterfaceSubClass == 0x03U)))

The bug is that v3.5.0 sets the descriptor length to 7 (USB_ENDPOINT_DESC_SIZE) if the device is a streaming MIDI device (subclass 0x03). It should be set to 9, same as streaming audio subclass 0x02.

Thanks for your replay. I am waiting for ST to confirm this issue.

NimaAgm commented 1 year ago

Still waiting for an answer

ABOUSTM commented 1 year ago

Still waiting for an answer

Proposed fix ACKed and to be part of next patch release

ALABSTM commented 7 months ago

Hi @NimaAgm and @danngreen,

Please excuse this late reply. Issue fixed in the frame of version 3.5.2 as you can see below.

https://github.com/STMicroelectronics/stm32_mw_usb_host/blob/3a524c2f185ac2f193cf3edd0b3f83ed064f3a5c/Core/Src/usbh_ctlreq.c#L491-L493

With regards,