@@ -100,36 +100,40 @@ struct ethernetif {
100100// Override mbed_mac_address of mbed_interface.c to provide ethernet devices with a semi-unique MAC address
101101void mbed_mac_address (char * mac )
102102{
103- unsigned char my_mac_addr [6 ] = {0x02 , 0x00 , 0xac , 0x55 , 0x66 , 0x77 }; // default mac adderss
104103 // Fetch word 0
105- uint32_t word0 = * (uint32_t * )0x7FFFC ;
104+ uint32_t word0 = * (uint32_t * )0x7F804 ; // 2KB Data Flash at 0x7F800
106105 // Fetch word 1
107106 // we only want bottom 16 bits of word1 (MAC bits 32-47)
108107 // and bit 9 forced to 1, bit 8 forced to 0
109108 // Locally administered MAC, reduced conflicts
110109 // http://en.wikipedia.org/wiki/MAC_address
111- uint32_t word1 = * (uint32_t * )0x7FFF8 ;
112- if ( word0 == 0xFFFFFFFF ) // Not burn any mac address at the last 2 words of flash
110+ uint32_t word1 = * (uint32_t * )0x7F800 ; // 2KB Data Flash at 0x7F800
111+
112+ if ( word0 == 0xFFFFFFFF ) // Not burn any mac address at 1st 2 words of Data Flash
113113 {
114- mac [0 ] = my_mac_addr [0 ];
115- mac [1 ] = my_mac_addr [1 ];
116- mac [2 ] = my_mac_addr [2 ];
117- mac [3 ] = my_mac_addr [3 ];
118- mac [4 ] = my_mac_addr [4 ];
119- mac [5 ] = my_mac_addr [5 ];
120- return ;
114+ // with a semi-unique MAC address from the UUID
115+ /* Enable FMC ISP function */
116+ SYS_UnlockReg ();
117+ FMC_Open ();
118+ // = FMC_ReadUID(0);
119+ word1 = FMC_ReadUID (1 ) >> 8 ;
120+ word0 = ((FMC_ReadUID (0 ) >> 4 ) << 20 ) | (FMC_ReadUID (2 ) & 0xFFFFF );
121+ /* Disable FMC ISP function */
122+ FMC_Close ();
123+ /* Lock protected registers */
124+ SYS_LockReg ();
121125 }
122126
123127 word1 |= 0x00000200 ;
124128 word1 &= 0x0000FEFF ;
125-
126- mac [0 ] = (word1 & 0x000000ff );
127- mac [1 ] = (word1 & 0x0000ff00 ) >> 8 ;
129+
130+ mac [0 ] = (word1 & 0x0000ff00 ) >> 8 ;
131+ mac [1 ] = (word1 & 0x000000ff ) ;
128132 mac [2 ] = (word0 & 0xff000000 ) >> 24 ;
129133 mac [3 ] = (word0 & 0x00ff0000 ) >> 16 ;
130134 mac [4 ] = (word0 & 0x0000ff00 ) >> 8 ;
131135 mac [5 ] = (word0 & 0x000000ff );
132-
136+ // printf("mac address %02x-%02x-%02x-%02x-%02x-%02x \r\n", mac[0], mac[1],mac[2],mac[3],mac[4],mac[5]);
133137}
134138
135139/**
0 commit comments