diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 6f983c0ab..b13ba03e2 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -177,6 +177,15 @@ uint32_t USBDeviceClass::sendConfiguration(uint32_t maxlen) return true; } +static void utox8(uint32_t val, char* s) { + for (int i = 0; i < 8; i++) { + int d = val & 0XF; + val = (val >> 4); + + s[7 - i] = d > 9 ? 'A' + d - 10 : '0' + d; + } +} + bool USBDeviceClass::sendDescriptor(USBSetup &setup) { uint8_t t = setup.wValueH; @@ -221,8 +230,19 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup) } else if (setup.wValueL == ISERIAL) { #ifdef PLUGGABLE_USB_ENABLED + // from section 9.3.3 of the datasheet + #define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C) + #define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040) + #define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044) + #define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048) + char name[ISERIAL_MAX_LEN]; - PluggableUSB().getShortName(name); + utox8(SERIAL_NUMBER_WORD_0, &name[0]); + utox8(SERIAL_NUMBER_WORD_1, &name[8]); + utox8(SERIAL_NUMBER_WORD_2, &name[16]); + utox8(SERIAL_NUMBER_WORD_3, &name[24]); + + PluggableUSB().getShortName(&name[32]); return sendStringDescriptor((uint8_t*)name, setup.wLength); #endif } diff --git a/cores/arduino/USB/USBDesc.h b/cores/arduino/USB/USBDesc.h index 6088ee089..9ea6abcc1 100644 --- a/cores/arduino/USB/USBDesc.h +++ b/cores/arduino/USB/USBDesc.h @@ -41,7 +41,7 @@ #define CDC_TX CDC_ENDPOINT_IN #endif -#define ISERIAL_MAX_LEN 33 +#define ISERIAL_MAX_LEN 65 // Defined string description #define IMANUFACTURER 1