aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Esden-Tempski2012-01-16 22:54:37 -0800
committerPiotr Esden-Tempski2012-01-16 22:54:37 -0800
commita7f14e3cc008e2ef927dd2b3bc41f37cf1c21add (patch)
treed341bc9b25a76a5494bf0463bc0bdba3352101b9
parent53ebc6770e7886f568633bddec16d9f6d351c6fb (diff)
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.
-rw-r--r--src/stm32/cdcacm.c15
1 files 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;
}