Using UID_BASE to obtain the STM32 96-bit UID
Originally a comment on the How to obtain and use the STM32 96-bit UID Knowledge Base article;
Moved for better discussion
Hello,
@MCU Support TD Can I query the following please (correct me if i'm wrong):
"If you are not using HAL, then the CMSIS device header provides a definition for the address of the UID. Even without HAL, you have a uniform way to obtain the UID."
uint32_t uid[3];
uid[0] = *(uint32_t *)UID_BASE;
uid[1] = *(uint32_t *)(UID_BASE + 4);
uid[2] = *(uint32_t *)(UID_BASE + 8);I believe this references the 0x04 and 0x08 offset from a reference manual, however this is an offset in bytes, and uid in this example is a 32bit variable.
In this example are you not then offsetting by 4 times as much each time and actually missing most of the unique ID?
I believe the actual code should offset by 1 32 bit object, i.e:
uint32_t uid[3];
uid[0] = *(uint32_t *)UID_BASE;
uid[1] = *(uint32_t *)(UID_BASE + 1);
uid[2] = *(uint32_t *)(UID_BASE + 2);
