Skip to main content
Associate
August 27, 2024
Question

Unique Id stm32H7

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

This topic has been closed for replies.

11 replies

Peter BENSCH
ST Technical Moderator
August 27, 2024

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Andrew Neil
Super User
August 27, 2024

Please see the Posting Tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

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 that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
OsabilityAuthor
Associate
August 27, 2024

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.

Tesla DeLorean
Guru
August 27, 2024

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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..