mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #2812 from jeromecoutant/PR_Add_MAC
[STM32 NUCLEO] Init MAC addresspull/2859/head
commit
d8e484d091
|
@ -119,7 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
|
|||
}
|
||||
}
|
||||
|
||||
void mbed_mac_address(char *mac)
|
||||
uint8_t mbed_otp_mac_address(char *mac)
|
||||
{
|
||||
C029_OTP_Header *pFound = NULL;
|
||||
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
|
||||
|
@ -140,4 +140,6 @@ void mbed_mac_address(char *mac)
|
|||
}
|
||||
}
|
||||
memcpy(mac, _macAddr, 6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ static err_t _eth_arch_netif_output_ipv6(struct netif *netif, struct pbuf *q, co
|
|||
|
||||
static err_t _eth_arch_low_level_output(struct netif *netif, struct pbuf *p);
|
||||
static struct pbuf * _eth_arch_low_level_input(struct netif *netif);
|
||||
__weak uint8_t mbed_otp_mac_address(char *mac);
|
||||
void mbed_default_mac_address(char *mac);
|
||||
|
||||
/**
|
||||
* Ethernet Rx Transfer completed callback
|
||||
|
@ -468,3 +470,45 @@ void eth_arch_disable_interrupts(void)
|
|||
{
|
||||
NVIC_DisableIRQ(ETH_IRQn);
|
||||
}
|
||||
|
||||
/** This returns a unique 6-byte MAC address, based on the device UID
|
||||
* This function overrides hal/common/mbed_interface.c function
|
||||
* @param mac A 6-byte array to write the MAC address
|
||||
*/
|
||||
|
||||
void mbed_mac_address(char *mac) {
|
||||
if (mbed_otp_mac_address(mac)) {
|
||||
return;
|
||||
} else {
|
||||
mbed_default_mac_address(mac);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
__weak uint8_t mbed_otp_mac_address(char *mac) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbed_default_mac_address(char *mac) {
|
||||
unsigned char ST_mac_addr[3] = {0x00, 0x80, 0xe1}; // default STMicro mac address
|
||||
|
||||
// Read unic id
|
||||
#if defined (TARGET_STM32F2)
|
||||
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
|
||||
#elif defined (TARGET_STM32F4)
|
||||
uint32_t word0 = *(uint32_t *)0x1FFF7A10;
|
||||
#elif defined (TARGET_STM32F7)
|
||||
uint32_t word0 = *(uint32_t *)0x1FF0F420;
|
||||
#else
|
||||
#error MAC address can not be derived from target unique Id
|
||||
#endif
|
||||
|
||||
mac[0] = ST_mac_addr[0];
|
||||
mac[1] = ST_mac_addr[1];
|
||||
mac[2] = ST_mac_addr[2];
|
||||
mac[3] = (word0 & 0x00ff0000) >> 16;
|
||||
mac[4] = (word0 & 0x0000ff00) >> 8;
|
||||
mac[5] = (word0 & 0x000000ff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue