From b0700538e3102734f3899cec9da44f2c414ea54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 6 Dec 2019 17:10:24 +0100 Subject: [PATCH] usb_cdcacm: add serial in USB strings --- lib/usb_cdcacm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/usb_cdcacm.c b/lib/usb_cdcacm.c index 060aa05..2f9a3dc 100644 --- a/lib/usb_cdcacm.c +++ b/lib/usb_cdcacm.c @@ -35,6 +35,7 @@ /* own libraries */ #include "global.h" // global utilities #include "usb_cdcacm.h" // USB CDC ACM header and definitions +#include "print.h" // strings utilities (large library, but the main application has space) /** maximum packet size for USB data transfer */ #define USB_DATA_TRANSFER_SIZE 64 // 64 is the maximum for full speed devices @@ -67,7 +68,7 @@ static const struct usb_device_descriptor usb_cdcacm_device_descriptor = { .bcdDevice = 0x0000, /**< Device Release Number: board version number */ .iManufacturer = 1, /**< the index of the string in the string table that represents the name of the manufacturer of this device */ .iProduct = 2, /**< the index of the string in the string table that represents the name of the product */ - .iSerialNumber = 0, /**< the index of the string in the string table that represents the serial number of this item in string form */ + .iSerialNumber = 3, /**< the index of the string in the string table that represents the serial number of this item in string form */ .bNumConfigurations = 1, /**< the number of possible configurations this device has */ }; @@ -201,7 +202,7 @@ static const struct usb_interface_descriptor usb_dfu_interface = { .bInterfaceClass = 0xFE, /**< DFU interface class (not defined in libopencm3 dfu lib) */ .bInterfaceSubClass = 1, /**< DFU interface subclass (not defined in libopencm3 dfu lib) */ .bInterfaceProtocol = 1, /**< runtime protocol (not defined in libopencm3 dfu lib) */ - .iInterface = 3, /**< the index of the string in the string table that represents interface description */ + .iInterface = 4, /**< the index of the string in the string table that represents interface description */ .extra = &usb_dfu_functional, /**< point to functional descriptor */ .extralen = sizeof(usb_dfu_functional), /**< size of functional descriptor */ @@ -233,12 +234,16 @@ static const struct usb_config_descriptor usb_cdcacm_configuration_descriptor = .interface = usb_cdcacm_interfaces, /**< pointer to an array of interfaces */ }; +/**< device ID used as serial number */ +static char usb_serial[] = "00112233445566778899aabb"; + /** USB string table * @note starting with index 1 */ -static const char *usb_strings[] = { +static const char* usb_strings[] = { "CuVoodoo", /**< manufacturer string */ "CuVoodoo STM32F1xx firmware", /**< product string */ + (const char*)usb_serial, /**< device ID used as serial number */ "DFU bootloader (runtime mode)", /**< DFU interface string */ }; @@ -430,6 +435,8 @@ static void usb_cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue) void usb_cdcacm_setup(void) { + snprintf(usb_serial, LENGTH(usb_serial), "%08x%08x%08x", DESIG_UNIQUE_ID0, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID2); // set actual device ID as serial + // initialize USB rcc_periph_reset_pulse(RST_USB); // reset USB peripheral usb_disconnect(); // disconnect to force re-enumeration