STM32: Generate same serial number as internal DFU bootloader.

This commit is contained in:
Uwe Bonnes 2017-04-15 15:24:53 +02:00
parent 98a4f8e318
commit f5dd3006fb
2 changed files with 14 additions and 3 deletions

View File

@ -390,7 +390,11 @@ static const struct usb_config_descriptor config = {
.interface = ifaces,
};
#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
char serial_no[13];
#else
char serial_no[9];
#endif
static const char *usb_strings[] = {
"Black Sphere Technologies",

View File

@ -21,11 +21,17 @@
char *serialno_read(char *s)
{
#if defined(STM32F4)
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10;
#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
volatile uint16_t *uid = (volatile uint16_t *)DESIG_UNIQUE_ID_BASE;
# if defined(STM32F4)
int offset = 3;
# elif defined(STM32L0) || defined(STM32F4)
int offset = 5;
#endif
sprintf(s, "%04X%04X%04X",
uid[1] + uid[5], uid[0] + uid[4], uid[offset]);
#else
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8;
#endif
uint32_t unique_id = *unique_id_p +
*(unique_id_p + 1) +
*(unique_id_p + 2);
@ -40,6 +46,7 @@ char *serialno_read(char *s)
s[i] += 'A' - '9' - 1;
s[8] = 0;
#endif
return s;
}