Skip to content

Commit 363c041

Browse files
authored
Merge pull request #2743 from jeromecoutant/PR_STM32_MAC
[STM32 NUCLEO] Init MAC address
2 parents e0bf415 + f05e620 commit 363c041

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
@@ -431,3 +431,31 @@ 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+
void mbed_mac_address(char *mac) {
440+
unsigned char ST_mac_addr[3] = {0x00, 0x80, 0xe1}; // default STMicro mac address
441+
442+
// Read unic id
443+
#if defined (TARGET_STM32F2)
444+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
445+
#elif defined (TARGET_STM32F4)
446+
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
447+
#elif defined (TARGET_STM32F7)
448+
uint32_t word0 = *(uint32_t *)0x1FF0F420;
449+
#else
450+
#error MAC address can not be derived from target unique Id
451+
#endif
452+
453+
mac[0] = ST_mac_addr[0];
454+
mac[1] = ST_mac_addr[1];
455+
mac[2] = ST_mac_addr[2];
456+
mac[3] = (word0 & 0x00ff0000) >> 16;
457+
mac[4] = (word0 & 0x0000ff00) >> 8;
458+
mac[5] = (word0 & 0x000000ff);
459+
460+
return;
461+
}

0 commit comments

Comments
 (0)