@@ -50,6 +50,8 @@ static err_t _eth_arch_netif_output_ipv6(struct netif *netif, struct pbuf *q, co
5050
5151static err_t _eth_arch_low_level_output (struct netif * netif , struct pbuf * p );
5252static struct pbuf * _eth_arch_low_level_input (struct netif * netif );
53+ __weak uint8_t mbed_otp_mac_address (char * mac );
54+ void mbed_default_mac_address (char * mac );
5355
5456/**
5557 * Ethernet Rx Transfer completed callback
@@ -468,3 +470,45 @@ void eth_arch_disable_interrupts(void)
468470{
469471 NVIC_DisableIRQ (ETH_IRQn );
470472}
473+
474+ /** This returns a unique 6-byte MAC address, based on the device UID
475+ * This function overrides hal/common/mbed_interface.c function
476+ * @param mac A 6-byte array to write the MAC address
477+ */
478+
479+ void mbed_mac_address (char * mac ) {
480+ if (mbed_otp_mac_address (mac )) {
481+ return ;
482+ } else {
483+ mbed_default_mac_address (mac );
484+ }
485+ return ;
486+ }
487+
488+ __weak uint8_t mbed_otp_mac_address (char * mac ) {
489+ return 0 ;
490+ }
491+
492+ void mbed_default_mac_address (char * mac ) {
493+ unsigned char ST_mac_addr [3 ] = {0x00 , 0x80 , 0xe1 }; // default STMicro mac address
494+
495+ // Read unic id
496+ #if defined (TARGET_STM32F2 )
497+ uint32_t word0 = * (uint32_t * )0x1FFF7A10 ;
498+ #elif defined (TARGET_STM32F4 )
499+ uint32_t word0 = * (uint32_t * )0x1FFF7A10 ;
500+ #elif defined (TARGET_STM32F7 )
501+ uint32_t word0 = * (uint32_t * )0x1FF0F420 ;
502+ #else
503+ #error MAC address can not be derived from target unique Id
504+ #endif
505+
506+ mac [0 ] = ST_mac_addr [0 ];
507+ mac [1 ] = ST_mac_addr [1 ];
508+ mac [2 ] = ST_mac_addr [2 ];
509+ mac [3 ] = (word0 & 0x00ff0000 ) >> 16 ;
510+ mac [4 ] = (word0 & 0x0000ff00 ) >> 8 ;
511+ mac [5 ] = (word0 & 0x000000ff );
512+
513+ return ;
514+ }
0 commit comments