Zephyr USB device string descriptors definition

363 Views Asked by At

the question is about USB device implementation in Zephyr OS. We need to add interface string descriptor for ineterface name. Using USBD_STRING_DESCR_DEFINE(primary) I've added that to string descriptor section, but it has index "0" - that's wrong (?) because it brakes basic string descriptor structure defined in usb_descriptor.c. How we could setup defines/linker commands to add new USB strings after that ones in usb_descriptor.c? Given example defines newly added string with index 0 (but it should be 4 - after manufacturer, product and serial num).

USBD_STRING_DESCR_DEFINE(primary) struct webusb_iface_descriptor webusb_string_descr = {
    /* webusb iface String Descriptor */
    .bLength = sizeof(struct webusb_iface_descriptor),
    .bDescriptorType = USB_DESC_STRING,
    .bString = WEBUSB_IFNAME,
};

void webusb_init() 
{
    int idx = usb_get_str_descriptor_idx(&webusb_string_descr);
    if (idx != 0) {
        webusb_desc.if0.iInterface = idx;
    }
} 
1

There are 1 best solutions below

0
William Reed On

You should use USBD_STRING_DESCR_USER_DEFINE rather than USBD_STRING_DESCR_DEFINE. ...USER_DEFINE will add to the descriptors and ...DESC_DEFINE will override the default ones that are included via usb_descriptor.c. I haven't been able to find any documentation talking about this but experimentally it works as I describe