From a7f14e3cc008e2ef927dd2b3bc41f37cf1c21add Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Mon, 16 Jan 2012 22:54:37 -0800 Subject: Changed the unique id generation to be 8 characters long. This is so Mac OS X uses the the unique id for naming the device file instead of the location. --- src/stm32/cdcacm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/stm32/cdcacm.c b/src/stm32/cdcacm.c index 7107b93..099b20e 100644 --- a/src/stm32/cdcacm.c +++ b/src/stm32/cdcacm.c @@ -350,7 +350,7 @@ static const struct usb_config_descriptor config = { .interface = ifaces, }; -static char serial_no[25]; +static char serial_no[9]; static const char *usb_strings[] = { "x", @@ -532,17 +532,20 @@ void usb_lp_can_rx0_isr(void) static char *get_dev_unique_id(char *s) { - volatile uint8_t *unique_id = (volatile uint8_t *)0x1FFFF7E8; + volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; + uint32_t unique_id = *unique_id_p + + *(unique_id_p + 1) + + *(unique_id_p + 2); int i; /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 24; i+=2) { - s[i] = ((*unique_id >> 4) & 0xF) + '0'; - s[i+1] = (*unique_id++ & 0xF) + '0'; + for(i = 0; i < 8; i++) { + s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; } - for(i = 0; i < 24; i++) + for(i = 0; i < 8; i++) if(s[i] > '9') s[i] += 'A' - '9' - 1; + s[8] = 0; return s; } -- cgit v1.2.3