Skip to content

Commit f05e620

Browse files
committed
[STM32 NUCLEO] Init MAC address
1 parent ff89555 commit f05e620

File tree

1 file changed

+28
-0
lines changed
  • features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,31 @@ void eth_arch_disable_interrupts(void)
448448
{
449449
NVIC_DisableIRQ(ETH_IRQn);
450450
}
451+
452+
/** This returns a unique 6-byte MAC address, based on the device UID
453+
* This function overrides hal/common/mbed_interface.c function
454+
* @param mac A 6-byte array to write the MAC address
455+
*/
456+
void mbed_mac_address(char *mac) {
457+
unsigned char ST_mac_addr[3] = {0x00, 0x80, 0xe1}; // default STMicro mac address
458+
459+
// Read unic id
460+
#if defined (TARGET_STM32F2)
461+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
462+
#elif defined (TARGET_STM32F4)
463+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
464+
#elif defined (TARGET_STM32F7)
465+
uint32_t word0 = *(uint32_t *)0x1FF0F420;
466+
#else
467+
#error MAC address can not be derived from target unique Id
468+
#endif
469+
470+
mac[0] = ST_mac_addr[0];
471+
mac[1] = ST_mac_addr[1];
472+
mac[2] = ST_mac_addr[2];
473+
mac[3] = (word0 & 0x00ff0000) >> 16;
474+
mac[4] = (word0 & 0x0000ff00) >> 8;
475+
mac[5] = (word0 & 0x000000ff);
476+
477+
return;
478+
}

0 commit comments

Comments
 (0)