Skip to main content
Visitor II
August 27, 2024
Question

Unique Id stm32H7

  • August 27, 2024
  • 2 replies
  • 2461 views

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.

    2 replies

    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

    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?

     

    OsabilityAuthor
    Visitor II
    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.

    Graduate II
    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.