OpenNuvoton / M031BSP

BSP for M031 Series MCU
Apache License 2.0
15 stars 16 forks source link

USB Strings descriptors #11

Open jeromeDms opened 2 years ago

jeromeDms commented 2 years ago

Hi I'm trying to add interface strings index in my USB descriptors. It works fine, but all strings above 4 are not handled. Looking at the USB driver usbd.c I indeed see :

/* Get String Descriptor */
    case DESC_STRING:
    {
        /* Get String Descriptor */
        if(g_usbd_SetupPacket[2] < **4ul**)
        {
            u32Len = USBD_Minimum(u32Len, g_usbd_sInfo->gu8StringDesc[g_usbd_SetupPacket[2]][0]);
            USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8StringDesc[g_usbd_SetupPacket[2]], u32Len);
            break;
        }
        else
        {
            /* Not support. Reply STALL. */
            USBD_SET_EP_STALL(EP0);
            USBD_SET_EP_STALL(EP1);
            break;
        }
    }

So my strings table defined as follow, fails :

uint8_t *gpu8UsbString[5] =
{
    gu8StringLang,  // idx 0
    gu8VendorStringDesc, // idx 1
    gu8ProductStringDesc, // idx 2
   gu8MidiInInterfaceStringDesc, // idx 3
  gu8MidiOutInterfaceStringDesc // idx 4
};

The last string pointer gu8MidiOutInterfaceStringDesc is NOT handled correctly

Why this limitation of 4 strings ? Is this something I can change ? Thanks

kchuang1 commented 2 years ago

Hi,

The string is pointer by device descriptor's iManufacture, iProduct and iSerialNumber. It must follow the USB spec.