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.

Library

Features

  • 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

Dependencies

  • CMSIS
    • 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

Functions

Example

  • 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.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...