Skip to content

Commit 8471f4e

Browse files
committed
[STM32 NUCLEO] Init MAC address
1 parent f93f484 commit 8471f4e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_C029/stm32f4_eth_init.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
119119
}
120120
}
121121

122-
void mbed_mac_address(char *mac)
122+
uint8_t mbed_otp_mac_address(char *mac)
123123
{
124124
C029_OTP_Header *pFound = NULL;
125125
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
@@ -140,4 +140,6 @@ void mbed_mac_address(char *mac)
140140
}
141141
}
142142
memcpy(mac, _macAddr, 6);
143+
144+
return 1;
143145
}

features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM/stm32xx_emac.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,45 @@ void eth_arch_disable_interrupts(void)
431431
{
432432
NVIC_DisableIRQ(ETH_IRQn);
433433
}
434+
435+
/** This returns a unique 6-byte MAC address, based on the device UID
436+
* This function overrides hal/common/mbed_interface.c function
437+
* @param mac A 6-byte array to write the MAC address
438+
*/
439+
440+
void mbed_mac_address(char *mac) {
441+
if (mbed_otp_mac_address(mac)) {
442+
return;
443+
} else {
444+
mbed_default_mac_address(mac);
445+
}
446+
return;
447+
}
448+
449+
__weak uint8_t mbed_otp_mac_address(char *mac) {
450+
return 0;
451+
}
452+
453+
void mbed_default_mac_address(char *mac) {
454+
unsigned char ST_mac_addr[3] = {0x00, 0x80, 0xe1}; // default STMicro mac address
455+
456+
// Read unic id
457+
#if defined (TARGET_STM32F2)
458+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
459+
#elif defined (TARGET_STM32F4)
460+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
461+
#elif defined (TARGET_STM32F7)
462+
uint32_t word0 = *(uint32_t *)0x1FF0F420;
463+
#else
464+
#error MAC address can not be derived from target unique Id
465+
#endif
466+
467+
mac[0] = ST_mac_addr[0];
468+
mac[1] = ST_mac_addr[1];
469+
mac[2] = ST_mac_addr[2];
470+
mac[3] = (word0 & 0x00ff0000) >> 16;
471+
mac[4] = (word0 & 0x0000ff00) >> 8;
472+
mac[5] = (word0 & 0x000000ff);
473+
474+
return;
475+
}

0 commit comments

Comments
 (0)