Skip to main content
rmccarthy
Associate
December 10, 2013
Question

Unique device ID address in STM32F2xx

  • December 10, 2013
  • 2 replies
  • 724 views
Posted on December 10, 2013 at 12:32

Hi,

I have been looking for some time and I cannot find an answer.

In a previous project I found the UID for the STM32F107 using the following function. Can someone tell me what the equivalent for STM32F2 is?

void GetDeviceID(void)

{

u8 HexTmp, H_HexTmp,L_HexTmp,i;

u32 Dev_Serial0, Dev_Serial1, Dev_Serial2;

u8 HEX[6] ={'A','B','C','D','E','F'};

Unique_Device_ID[24] = '\0';

    

Dev_Serial0 = *(vu32*)(0x1FFFF7E8);

Dev_Serial1 = *(vu32*)(0x1FFFF7EC);

Dev_Serial2 = *(vu32*)(0x1FFFF7F0);

for(i=0;i<24;)

{

    if( 0==i ) HexTmp = (u8)Dev_Serial0; 

    else if( 2==i ) HexTmp = (u8)( Dev_Serial0 >> 8 );

    else if( 4==i ) HexTmp = (u8)( Dev_Serial0 >> 16 );

else if( 6==i ) HexTmp = (u8)( Dev_Serial0 >> 24 );

else if( 8==i ) HexTmp = (u8)Dev_Serial1; 

else if( 10==i ) HexTmp = (u8)( Dev_Serial1 >> 8 ); 

else if( 12==i ) HexTmp = (u8)( Dev_Serial1 >> 16 );

else if( 14==i ) HexTmp = (u8)( Dev_Serial1 >> 24 );

else if( 16==i ) HexTmp = (u8)Dev_Serial2;

else if( 18==i ) HexTmp = (u8)( Dev_Serial2 >> 8 );

else if( 20==i ) HexTmp = (u8)( Dev_Serial2 >> 16 );

else if( 22==i ) HexTmp = (u8)( Dev_Serial2 >> 24 );

      

H_HexTmp = HexTmp >> 4;

L_HexTmp = HexTmp & 0x0F;

   

   

if( L_HexTmp > 9 )

Unique_Device_ID[i+1] = HEX[ L_HexTmp - 10 ];

else

Unique_Device_ID[i+1] = L_HexTmp + '0';

if( H_HexTmp > 9 )

Unique_Device_ID[i+0] = HEX[ H_HexTmp - 10 ];  

else

    Unique_Device_ID[i+0] = H_HexTmp + '0';

    i += 2;

    }  

}

I see from some earlier posts that the start address is 

0x1FFF7A10 but do I increment in 4 Bytes?

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    December 10, 2013
    Posted on December 10, 2013 at 13:45

    I have been looking for some time and I cannot find an answer. In a previous project I found the UID for the STM32F107 using the following function. Can someone tell me what the equivalent for STM32F2 is?

    Like the

    http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/CD00225773.pdf

    ?

    Here from Rev5

    0690X00000604uiQAA.png

    0x1FFF7A10/0x1FFF7A14/0x1FFF7A18

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    December 10, 2013
    Posted on December 10, 2013 at 14:53

    The conversion code looks a bit clunky; how about:

    Unique_Device_ID[25] = 0; // Don't forget the NUL terminator!
    itoa( Dev_Serial2 , &Unique_Device_ID[ 0], 16 );
    itoa( Dev_Serial1 , &Unique_Device_ID[ 8], 16 );
    itoa( Dev_Serial0 , &Unique_Device_ID[16], 16 );

    ?
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.