cancel
Showing results for 
Search instead for 
Did you mean: 

read unique id from code

jparera
Associate II
Posted on May 26, 2016 at 13:44

STM32F051

I get a Hard fault when I try to read the uinque Id ''Unique device ID register (96 bits)

The 96-bit unique device identifier... provides a reference number which is unique for any device and in any context. These bits cannot be altered by the user.

Base address: 0x1FFF F7AC

Address offset: 0x00

Read only = 0xXXXXXXXX where X is factory-programmed''

https://techoverflow.net/blog/2015/02/03/reading-the-stm32-unique-device-id-in-c/

If I try to read another location I read it fine. Is the address actually out of range and the manual is wrong? or do I have to  do some operation before I try to read it ?

I also tried reading with st-link

13:36:03 : Connected via SWD.

13:36:03 : Connection mode : Normal.

13:36:03 : Debug in Low Power mode enabled.

13:36:03 : Device ID:0x440

13:36:03 : Device flash Size : 64KBytes

13:36:03 : Device family :STM32F051x4/F051x6/F051x8/F030x8

13:36:03 : Can not read memory!

Thank you very much

#stm32-f051x
4 REPLIES 4
Walid FTITI_O
Senior II
Posted on May 26, 2016 at 16:26

Hi Pares,

For IDCODE read refer to DBGMCU_IDCODE register in RM0091 ( page 921). As mentionned in page 972, you can simply do that by putting this line code:

/* Read MCU Id, 32-bit access */ 
MCU_Id = DBGMCU->IDCODE;

-Hannibal-
jparera
Associate II
Posted on May 26, 2016 at 16:53

well that works, that way  I  can read the device ID but its the same from the same family and type. I  want to read the unique Id  from ''DocID018940 Rev 8   page 933/1008'' so I can use it to differentiate devices from the same type.

Update : reading unique ID

Now it works and I  had debugged some HardFaults, on debug step into... and on runtime got the printf  I set inside HardFault_Handler. I did call

  FLASH_Unlock();

  FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR |  FLASH_FLAG_WRPERR);

now it works even if I don't call that, I am not sure of the reason, I call FLASH_lock()  and also reads fine which it was about flash lock unlock motive shouldn't.

Ok I found the reason I somehow managed to mistype the Address and not notice it 0x1ffff7a10 is actually out of range...  Sorry Hannibal and Clive

Posted on May 26, 2016 at 17:29

13:36:03 : Can not read memory!

Read a more constrained block of memory, ie0x1FFFF700[0x100]

printf(''STM32 %d KB FLASH, %08X-%08X-%08X UNIQUE

'',
*((unsigned short *)0x1FFFF7CC),
*((unsigned long *)0x1FFFF7AC),
*((unsigned long *)0x1FFFF7B0),
*((unsigned long *)0x1FFFF7B4) );

If it Hard Faults, then you need to evaluate what exactly is faulting, the processor provides specific details, review them, understand the cause. There are some F0 family parts that do not support the Unique ID, your's is documented too unless it has been remarked.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on May 26, 2016 at 18:17

Hi Pares,

I have made a quick test using ST-Link utility to read the address on STM32F053B-DISCO and it is successful.

0690X000006035OQAQ.jpg

-Hannibal-