usb_cdcacm: add serial in USB strings

This commit is contained in:
King Kévin 2019-12-06 17:10:24 +01:00
parent dd9f10c406
commit b0700538e3
1 changed files with 10 additions and 3 deletions

View File

@ -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