Library 44- STM32F4 unique ID and flash size

STM32F4xx devices have some parts in memory, which are read only and store some information about device. You can use them to protect your program if it is stolen from memory, or to tell programmer/debugger which device is connected with and detect flash size.

This library covers 4 things you can read from device:

  • Device signature
    • Device signature is something that you probably want to know when you are working with some device. This feature returns you 16-bit length device signature value.
  • Device revision
    • Some devices are from time to time updated in features, but with same name. This register returns you a revision in which it was made.
  • Flash size
    • Flash size is 16bit value stored somewhere in MCU. Value is in kB (kilo bytes)
  • Unique ID
    • 96-bit long identification part, where bits are factory programmed. Each device has different number, which gives you an opportunity to check if program on the device is “stolen” from another device, so you can disable functionality.



  • Read device signature
  • Read device revision
  • Read device’s flash size in kB (kilo bytes)
  • Read 96-bits unique ID in different read modes:
    • 8bit mode
    • 16bit mode
    • 32bit mode


    • STM32F4xx

Values returned

  • Device signature is not something like “0x0401” for STM32F401, or “0x0407” for STM32F407, etc. You have to carefully read what you get back and connect returned value with real device. Possible values in signature register are:
    • 0x0413: STM32F405xx/07xx and STM32F415xx/17xx)
    • 0x0419: STM32F42xxx and STM32F43xxx
    • 0x0423: STM32F401xB/C
    • 0x0433: STM32F401xD/E
    • 0x0431: STM32F411xC/E
  • Device revision is next strange format. It’s possible returns are:
    • 0x1000: Revision A
    • 0x1001: Revision Z
    • 0x1003: Revision Y
    • 0x1007: Revision 1
    • 0x2001: Revision 3
  • Flash size is always returned in kB value
  • Unique ID is a little bit more complicated. You can’t read it with single call, so you have to make several calls. For that purpose I’ve made 3 different read modes.
    • 32-bit mode: Read 32-bits at a time, pass values 0 to 2 to function, corresponding to which 32-bits you want to read. Higher number means higher 32-bits.
    • 16-bit mode: Read 16-bits at a time, pass values 0 to 5 to function, corresponding to which 16-bits you want to read. Higher number means higher 16-bits.
    • 8-bit mode: Read 8-bits at a time, pass values 0 to 11 to function, corresponding to which 8-bits you want to read. Higher number means higher 8-bits



  • I’ve tested bottom example with Nucleo F401-RE board.
  • Data from STM are sent over USART2, TX: PA2, 115200 baud. On nucleo board, this is connected to USB

STM32F4 identification example result

STM32F4 identification example result

Project is available on Github, download library below.



Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Pingback: All STM32F4 libraries - STM32F4 Discovery()

  • Pingback: HAL Library 27- Identification for STM32Fxxx - STM32F4 Discovery()

  • Oleg

    Hi, Tilen,
    You are doing an excellent job, the library help me a lot to learn STM32.
    I found a small inaccuracy in tm_stm32f4.h * @version v1.0 (file date 23.06.15 08:04)

    Macro does not work
    #define TM_ID_GetRevision() (*(uint16_t *) (DBGMCU->IDCODE + 2))

    (*(uint16_t *) (ID_DBGMCU_IDCODE + 2))
    and it is written in example on the site.

    With respect, Oleg.

    • Think you are right, but what is the value for id_dbgmcu_idcode define?

      • Oleg

        in tm_stm32f4_id.h
        #define ID_DBGMCU_IDCODE 0xE0042000