How can I make a fully custom USB device descriptor, or at least modify more than the macros allow?

Good evening. 

I am working on a USB HID joystick. The USB documentation on nordic, while better than the woefully inadequate zephyr mainline docs, only covers the surface cases.

I want the bDeviceClass of 0 and a custom bcdDevice.

I can't seem to figure out how to do this without completely deconstructing the macro magic and breaking things. For example, I tried turning 

USBD_DEVICE_DEFINE(test_usbd, DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), CONFIG_VID, CONFIG_PID);

into 

const struct usb_device_descriptor fs_desc_joy_usbd = {
.bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = USB_DESCRIPTOR_DEVICE,
.bcdUSB = sys_cpu_to_le16(0x0200),
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5710,
.bcdDevice = sys_cpu_to_le16(0x0100),
.iManufacturer = 0,
.iProduct = 0,
.iSerialNumber = 2,
.bNumConfigurations = 1,
};
static STRUCT_SECTION_ITERABLE(usbd_context, joy_usbd) = {
.name = STRINGIFY(joy_usbd),
.dev = DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)),
.fs_desc = &fs_desc_joy_usbd,
};

which has only led to a hard fault in the os with nothing else changed

Is there a safe method to modify the device descriptor outside of the given few modifiable values?

Parents Reply
  • Hello,

    I had gone through them before when I was learning how to use USBnext. With your reply, I thought I missed something.

    Indeed I missed usbd_device_set_code_triple and usbd_device_set_bcd_device 

    I also found out that the kernel will hard fault when you fill out a VID or PID that already has a manufacturer/product string field and then us 

    USBD_DESC_MANUFACTURER_DEFINE(usb_mfr, "tst");
    USBD_DESC_PRODUCT_DEFINE(usb_product, "one");

    and their associated runtime assignment functions.

Children
No Data
Related