Setting the USB CDC-ACM Serial Number at Runtime

If I have an application where I have implemented USB CDC-ACM, how can I set the serial number seen by the PC when I connect my device? Is it possible to set it at runtime?

Parents
  • Hi,

    Normally the serial number is set on boot, e.g.: 

    USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn); 
        err = usbd_add_descriptor(&sample_usbd, &sample_sn);
        if (err) {
            LOG_ERR("Failed to initialize SN descriptor (%d)", err);
            return NULL;
        }

    I guess it's potentially possible to manipulate it if you want to.

    Kenneth

  • I imagine I need to call this function before enabling USB, or can I call it at any time?

    Also, I noticed that your example uses the USB device stack (usbd*), while I am currently using usb*. In fact, for enabling USB, I use usb_enable instead of usbd_enable. Does that make any difference?

    While we're at it, what is the difference between using usb_enable and usbd_enable?

  • Hi,

    I have not checked when it can be called in specific, I hope the examples or api documentation explain that.

    usbd_enable() is part of the newer USB device stack in Zephyr (sometimes referred to as "USB device next" or "USB stack next"). While usb_enable() is the legacy USB driver.

    Kenneth

  • Sorry, but in the last few days, I haven't had the chance to try your suggestion. I just tried integrating your code into mine, but I'm getting an error

    error: 'sample_sn' undeclared (first use in this function)

    Additionally, I don't understand how to set the serial number at runtime using USBD_DESC_SERIAL_NUMBER_DEFINE, since the macro only defines the variable sample_sn, and I don't see where to insert the serial number string.

    I also tried setting the serial number using CONFIG_USB_DEVICE_SN, but I didn't get any results. It doesn't even set the manufacturer or the product.

    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
    CONFIG_USB_DEVICE_MANUFACTURER="Company"
    CONFIG_USB_DEVICE_PRODUCT="Product"
    CONFIG_USB_DEVICE_SN="S1234567890"
    CONFIG_USB_DEVICE_PID=0x0002
    CONFIG_USB_DEVICE_VID=0xAD5A

    Any suggestions?

  • Hello,

    Sorry, if you look at the projects using "USB stack next" you can find they are using CONFIG_USB_DEVICE_STACK_NEXT=y. So try that.

    Kenneth

Reply Children
No Data
Related