Skip to main content
Explorer II
April 3, 2024
Solved

STM32 IC's Unique ID

  • April 3, 2024
  • 3 replies
  • 4485 views

Hi,

I am using STM32G491RE MCU for my project. Is it true each STM32 IC has its own unique ID. For STM32G4 product has the UID facility. Is it 96-bit ID for all the stm32 families or is it different.

Which manual has to be referred for this?
If yes can I use that for serial number for the product.
Which memory location is it stored?
Can read that from IC and send it through UART?

Can anyone suggest.

Thanks

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    Correct, 0x1FFF7590 is the base address (named UID_BASE in the firmware) of the UID.

    It is also correct that the UID is factory programmed and cannot be changed.

    The UID can be determined simply by reading the three 32-bit values UID_BASE, UID_BASE+4 and UID_BASE+8. You can also use the HAL or LL library to do this:

    stm32g4xx_hal.c:

    uint32_t HAL_GetUIDw0(void)
    uint32_t HAL_GetUIDw1(void)
    uint32_t HAL_GetUIDw2(void)

    stm32g4xx_ll_utils.h:

    uint32_t LL_GetUID_Word0(void)
    uint32_t LL_GetUID_Word1(void)
    uint32_t LL_GetUID_Word2(void)

    Of course you can use this UID as a unique serial number.

    Regards
    /Peter

    3 replies

    Technical Moderator
    April 3, 2024

    If the UID feature is included, all STM32s have their own and unique - across all families of STM32s.

    The Unique device ID feature is described in the respective reference manual, for the STM32G4 in RM0440, section 48.1

    Theoretically you can use the UID for a serial number, but then it is 96bit long. As soon as you truncate it, a unique serial number is no longer given.

    The address of the serial number can be found in the section of the reference manual mentioned above.

    Of course you can read out the UID and send it as you wish.

    Does it answer your questions?

    Regards
    /Peter

    Explorer II
    April 3, 2024

    Thanks @Peter BENSCH  for the quick response.
    I referred the RM0440,As below image they mentioned base address 0x1FFF7590.Is that the address of UID number stored memory.
    If so, that address is not stored in flash/system memory/OTP/option bytes but it is factory programmed memory.
    Can you please provide the resources to read the UID number from MCU.

     

    As soon as you truncate it, a unique serial number is no longer given.

    I am not planning to reduce the UID number If I use that UID,I will use full  96-bit number then can I use that number  for serial number?



    Thanks

    sireevenkat1_0-1712134530799.png

     

     

    Technical Moderator
    April 3, 2024

    Correct, 0x1FFF7590 is the base address (named UID_BASE in the firmware) of the UID.

    It is also correct that the UID is factory programmed and cannot be changed.

    The UID can be determined simply by reading the three 32-bit values UID_BASE, UID_BASE+4 and UID_BASE+8. You can also use the HAL or LL library to do this:

    stm32g4xx_hal.c:

    uint32_t HAL_GetUIDw0(void)
    uint32_t HAL_GetUIDw1(void)
    uint32_t HAL_GetUIDw2(void)

    stm32g4xx_ll_utils.h:

    uint32_t LL_GetUID_Word0(void)
    uint32_t LL_GetUID_Word1(void)
    uint32_t LL_GetUID_Word2(void)

    Of course you can use this UID as a unique serial number.

    Regards
    /Peter

    Explorer II
    April 3, 2024

    Hi @Peter BENSCH ,

    I am trying to read the STM32 IC UID number.

     

     

    #define STM32_UUID ((uint32_t *)0x1FFF7590)
     uint32_t idPart1 = STM32_UUID[0];
     uint32_t idPart2 = STM32_UUID[1];
     uint32_t idPart3 = STM32_UUID[2];
     printf("Unique ID: %lu,%lu,%lu\n", idPart1, idPart2, idPart3);

     


    Is it correct way of getting the values??

    With below code I got undefined reference to HAL_GetUID error.

     

    uint32_t HAL_GetUIDw0(void)
    uint32_t HAL_GetUIDw1(void)
    uint32_t HAL_GetUIDw2(void)

     


    Thanks

    Super User
    April 3, 2024

    @sireevenkat1 wrote:

    With below code I got undefined reference to HAL_GetUID error.

     

     

     

     

    uint32_t HAL_GetUIDw0(void)
    uint32_t HAL_GetUIDw1(void)
    uint32_t HAL_GetUIDw2(void)

     

     

     


    Thanks


    That means you didn't include the HAL source files which define the HAL_GetUID...() functions.

     

    EDIT 

    Probably called something like stm32g4xxx_hal.c

     

    Technical Moderator
    April 3, 2024

    Yes, your code would be a possibility.