Added variable serial number (via UID of the device)

This commit is contained in:
Alex Taradov 2017-05-09 21:27:55 -07:00
parent 3e9c9ce8db
commit e35692e86a
2 changed files with 17 additions and 3 deletions

View File

@ -62,8 +62,9 @@
#endif #endif
/*- Variables ---------------------------------------------------------------*/ /*- Variables ---------------------------------------------------------------*/
alignas(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE]; static 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_response_buffer[DAP_CONFIG_PACKET_SIZE];
extern char usb_serial_number[16];
/*- Implementations ---------------------------------------------------------*/ /*- Implementations ---------------------------------------------------------*/
@ -71,6 +72,7 @@ alignas(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE];
static void sys_init(void) static void sys_init(void)
{ {
uint32_t coarse, fine; uint32_t coarse, fine;
uint32_t sn = 0;
SYSCTRL->OSC8M.bit.PRESC = 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.reg = GCLK_GENCTRL_ID(0) | GCLK_GENCTRL_SRC(GCLK_SOURCE_DFLL48M) |
GCLK_GENCTRL_RUNSTDBY | GCLK_GENCTRL_GENEN; GCLK_GENCTRL_RUNSTDBY | GCLK_GENCTRL_GENEN;
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -137,11 +137,13 @@ const alignas(4) usb_string_descriptor_zero_t usb_string_descriptor_zero =
.wLANGID = 0x0409, // English (United States) .wLANGID = 0x0409, // English (United States)
}; };
char usb_serial_number[16];
char *usb_strings[] = char *usb_strings[] =
{ {
[USB_STR_MANUFACTURER] = "Alex Taradov", [USB_STR_MANUFACTURER] = "Alex Taradov",
[USB_STR_PRODUCT] = "Generic CMSIS-DAP Adapter", [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_CONFIGURATION] = "Main Configuration",
[USB_STR_INTERFACE] = "Main Interface", [USB_STR_INTERFACE] = "Main Interface",
}; };