diff --git a/platform/samd11/main.c b/platform/samd11/main.c index 47e0d42..fe7cd07 100644 --- a/platform/samd11/main.c +++ b/platform/samd11/main.c @@ -62,8 +62,9 @@ #endif /*- Variables ---------------------------------------------------------------*/ -alignas(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE]; -alignas(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE]; +static alignas(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE]; +static alignas(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE]; +extern char usb_serial_number[16]; /*- Implementations ---------------------------------------------------------*/ @@ -71,6 +72,7 @@ alignas(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE]; static void sys_init(void) { uint32_t coarse, fine; + uint32_t sn = 0; SYSCTRL->OSC8M.bit.PRESC = 0; @@ -97,6 +99,16 @@ static void sys_init(void) GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(0) | GCLK_GENCTRL_SRC(GCLK_SOURCE_DFLL48M) | GCLK_GENCTRL_RUNSTDBY | GCLK_GENCTRL_GENEN; while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); + + sn ^= *(volatile uint32_t *)0x0080a00c; + sn ^= *(volatile uint32_t *)0x0080a040; + sn ^= *(volatile uint32_t *)0x0080a044; + sn ^= *(volatile uint32_t *)0x0080a048; + + for (int i = 0; i < 8; i++) + usb_serial_number[i] = "0123456789ABCDEF"[(sn >> (i * 4)) & 0xf]; + + usb_serial_number[9] = 0; } //----------------------------------------------------------------------------- diff --git a/platform/samd11/usb_descriptors.c b/platform/samd11/usb_descriptors.c index 5aaa925..c534e1b 100644 --- a/platform/samd11/usb_descriptors.c +++ b/platform/samd11/usb_descriptors.c @@ -137,11 +137,13 @@ const alignas(4) usb_string_descriptor_zero_t usb_string_descriptor_zero = .wLANGID = 0x0409, // English (United States) }; +char usb_serial_number[16]; + char *usb_strings[] = { [USB_STR_MANUFACTURER] = "Alex Taradov", [USB_STR_PRODUCT] = "Generic CMSIS-DAP Adapter", - [USB_STR_SERIAL_NUMBER] = "123456", + [USB_STR_SERIAL_NUMBER] = usb_serial_number, [USB_STR_CONFIGURATION] = "Main Configuration", [USB_STR_INTERFACE] = "Main Interface", };