Unique Id stm32H7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 1:59 AM
Hello Everyone,
I am working on stm32h723zg, and I want to obtaind the serial of the micro controller for the unique id:
uint32_t unique_id[3];
void read_serial_number(void) {
// Unique ID registers
unique_id[0] = HAL_GetUIDw0(); // Unique ID Register 1
unique_id[1] = HAL_GetUIDw1(); // Unique ID Register 2
unique_id[2] = HAL_GetUIDw2();
}
How can I combine this id to obtain the proper serial number
- Labels:
-
STM32H7 series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 2:10 AM
Welcome @Osability, to the community!
The Unique ID is a globally unique number consisting of 96 bits. As STM32 are based on Cortex-M, which in turn work on 32 bits, the individual 32-bit segments are read and can then be combined to form a 96-bit number. You can use this as a serial number.
Unfortunately, it is not possible to derive a (unique) serial number with a different length from these 96 bits, so in such a case you would have to define your own serial number and store it in the flash.
Hope that helps?
Regards
/Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 2:13 AM
Please see the Posting Tips for how to properly post source code:
it should look like this:
uint32_t unique_id[3];
void read_serial_number(void) {
// Unique ID registers
unique_id[0] = HAL_GetUIDw0(); // Unique ID Register 1
unique_id[1] = HAL_GetUIDw1(); // Unique ID Register 2
unique_id[2] = HAL_GetUIDw2();
}
@Osability wrote:How can I combine this id to obtain the proper serial number
What do you mean by, "proper serial number" ?
That code does give you the full 96 bits of the Unique ID in your unique_id array - what more do you want?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 3:00 AM
If you the microcontroller to a computer an open stm32cubeprogrammer , the serial number of the microcontroller shows, and this same number can be obtain using some python code. So I am asking if the serial number is a combination of the unique id of the microcontroller.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 4:23 AM - edited ‎2024-08-27 7:13 AM
Do the hex digits look to match?
There's a different algorithm used for USB Serial Number, which I think creates a 64-bit 16-digit ASCII hex number. Look at the USB Device examples for that code to generate that descriptor.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 5:40 AM
The Serial Number in STM32CubeProgrammer is the serial number of the ST-Link chip, not the chip you are programming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 6:12 AM
I have a custom board board ,not a development board, and I am not using a ST-Link. I am programming through dfu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 7:16 AM
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 7:32 AM - edited ‎2024-08-27 7:46 AM
That code appears to ignore DEVICE_ID1 - it only uses DEVICE_ID0 and DEVICE_ID2.
Correction: all three are used - see later replies.
@Peter BENSCH said, "it is not possible to derive a (unique) serial number with a different length from these 96 bits" - so that code's not going to give a (guaranteed) unique serial number...
:thinking_face:
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 7:38 AM - edited ‎2024-08-27 7:39 AM
>>That code appears to ignore DEVICE_ID1 - it only uses DEVICE_ID0 and DEVICE_ID2
It mixes it up with the addition
So it gets to 64-bit, but all 96-bit factor in, just not "uniquely", but chance of picking up two units randomly and them clashing is exceedingly low. Really just sufficient to determine the PC has enumerated this device before, and which COM port or Drive Letter was associated with it.
Up vote any posts that you find helpful, it shows what's working..
