diff --git a/include/libopencm3/stm32/desig.h b/include/libopencm3/stm32/desig.h index 7b2eef7b..c7f3f65e 100644 --- a/include/libopencm3/stm32/desig.h +++ b/include/libopencm3/stm32/desig.h @@ -28,14 +28,6 @@ /* Flash size register */ #define DESIG_FLASH_SIZE MMIO16(DESIG_FLASH_SIZE_BASE + 0x00) -/* Unique ID register (96 bits) */ -/* Note: ST says these may be accessed in any width if you choose */ -#define DESIG_UID_15_0 MMIO16(DESIG_UNIQUE_ID_BASE + 0x00) -/* Listed as "This field value is also reserved for a future feature" WTH?! */ -#define DESIG_UID_31_16 MMIO16(DESIG_UNIQUE_ID_BASE + 0x02) -#define DESIG_UID_63_32 MMIO32(DESIG_UNIQUE_ID_BASE + 0x04) -#define DESIG_UID_95_64 MMIO32(DESIG_UNIQUE_ID_BASE + 0x08) - BEGIN_DECLS /** diff --git a/include/libopencm3/stm32/f0/memorymap.h b/include/libopencm3/stm32/f0/memorymap.h index 5122a23c..6bc74ed6 100644 --- a/include/libopencm3/stm32/f0/memorymap.h +++ b/include/libopencm3/stm32/f0/memorymap.h @@ -92,10 +92,11 @@ #define GPIO_PORT_F_BASE (PERIPH_BASE_AHB2 + 0x1400) - /* Device Electronic Signature */ -/* ??? -#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x7e0) -#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x7e8) -*/ +#define DESIG_FLASH_SIZE_BASE (0x1FFFF7CC) +#define DESIG_UNIQUE_ID_BASE (0x1FFFF7AC) +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 8) + #endif diff --git a/include/libopencm3/stm32/f1/memorymap.h b/include/libopencm3/stm32/f1/memorymap.h index f909f6ed..29050c03 100644 --- a/include/libopencm3/stm32/f1/memorymap.h +++ b/include/libopencm3/stm32/f1/memorymap.h @@ -113,7 +113,12 @@ #define FSMC_BASE (PERIPH_BASE + 0x60000000) /* Device Electronic Signature */ -#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x7e0) -#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x7e8) +#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x7e0) +#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x7e8) +/* Ignore the "reserved for future use" half of the first word */ +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 8) + #endif diff --git a/include/libopencm3/stm32/f2/memorymap.h b/include/libopencm3/stm32/f2/memorymap.h index fd40b457..6aec2379 100644 --- a/include/libopencm3/stm32/f2/memorymap.h +++ b/include/libopencm3/stm32/f2/memorymap.h @@ -130,4 +130,12 @@ /* PPIB */ #define DBGMCU_BASE (PPBI_BASE + 0x00042000) +/* Device Electronic Signature */ +#define DESIG_FLASH_SIZE_BASE (0x1FFF7A22) +#define DESIG_UNIQUE_ID_BASE (0x1FFF7A10) +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 8) + + #endif diff --git a/include/libopencm3/stm32/f3/memorymap.h b/include/libopencm3/stm32/f3/memorymap.h index 1b579f47..98aaee4e 100644 --- a/include/libopencm3/stm32/f3/memorymap.h +++ b/include/libopencm3/stm32/f3/memorymap.h @@ -114,4 +114,11 @@ /* PPIB */ #define DBGMCU_BASE (PPBI_BASE + 0x00042000) +/* Device Electronic Signature */ +#define DESIG_FLASH_SIZE_BASE (0x1FFFF7CC) +#define DESIG_UNIQUE_ID_BASE (0x1FFFF7AC) +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 8) + #endif diff --git a/include/libopencm3/stm32/f4/memorymap.h b/include/libopencm3/stm32/f4/memorymap.h index 5b1e6dbc..7065ce11 100644 --- a/include/libopencm3/stm32/f4/memorymap.h +++ b/include/libopencm3/stm32/f4/memorymap.h @@ -132,4 +132,11 @@ /* PPIB */ #define DBGMCU_BASE (PPBI_BASE + 0x00042000) +/* Device Electronic Signature */ +#define DESIG_FLASH_SIZE_BASE (0x1FFF7A22) +#define DESIG_UNIQUE_ID_BASE (0x1FFF7A10) +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 8) + #endif diff --git a/include/libopencm3/stm32/l1/memorymap.h b/include/libopencm3/stm32/l1/memorymap.h index 76a92738..8f0bc239 100644 --- a/include/libopencm3/stm32/l1/memorymap.h +++ b/include/libopencm3/stm32/l1/memorymap.h @@ -105,8 +105,11 @@ #define AES_BASE (PERIPH_BASE + 0x10000000) /* Device Electronic Signature */ -#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x8004C) -#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x80050) +#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x8004C) +#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x80050) +#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) +#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) +#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 0x14) /* Make the map names match those for other families to allow commonality */ #define SPI1_I2S_BASE SPI1_BASE diff --git a/lib/stm32/desig.c b/lib/stm32/desig.c index 89fb9294..b610e665 100644 --- a/lib/stm32/desig.c +++ b/lib/stm32/desig.c @@ -26,15 +26,9 @@ uint16_t desig_get_flash_size(void) void desig_get_unique_id(uint32_t result[]) { - /* Could also just return a pointer to the start? read it as they wish? - */ - uint16_t bits15_0 = DESIG_UID_15_0; - uint32_t bits31_16 = DESIG_UID_31_16; - uint32_t bits63_32 = DESIG_UID_63_32; - uint32_t bits95_64 = DESIG_UID_95_64; - result[0] = bits95_64; - result[1] = bits63_32; - result[2] = bits31_16 << 16 | bits15_0; + result[0] = DESIG_UNIQUE_ID2; + result[1] = DESIG_UNIQUE_ID1; + result[2] = DESIG_UNIQUE_ID0; } void desig_get_unique_id_as_string(char *string,