arch/arm/src/stm32f7/stm32_ethernet.c: Autogenerate Ethernet MAC address from device unique ID.

This commit is contained in:
Valmantas Paliksa 2019-04-12 08:31:57 -06:00 committed by Gregory Nutt
parent 17176480df
commit c574e71c89

View File

@ -56,6 +56,7 @@
#include <nuttx/net/mii.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/netdev.h>
#include <crc64.h>
#if defined(CONFIG_NET_PKT)
# include <nuttx/net/pkt.h>
@ -69,6 +70,7 @@
#include "stm32_gpio.h"
#include "stm32_rcc.h"
#include "stm32_ethernet.h"
#include "stm32_uid.h"
#include <arch/board/board.h>
@ -4081,6 +4083,8 @@ static inline
int stm32_ethinitialize(int intf)
{
struct stm32_ethmac_s *priv;
uint8_t uid[12];
uint64_t crc;
ninfo("intf: %d\n", intf);
@ -4110,6 +4114,20 @@ int stm32_ethinitialize(int intf)
priv->txpoll = wd_create(); /* Create periodic poll timer */
priv->txtimeout = wd_create(); /* Create TX timeout timer */
stm32_get_uniqueid(uid);
crc = crc64(uid, 12);
/* Specify as localy administrated address */
priv->dev.d_mac.ether.ether_addr_octet[0] = (crc >> 0) | 0x02;
priv->dev.d_mac.ether.ether_addr_octet[0] &= ~0x1;
priv->dev.d_mac.ether.ether_addr_octet[1] = crc >> 8;
priv->dev.d_mac.ether.ether_addr_octet[2] = crc >> 16;
priv->dev.d_mac.ether.ether_addr_octet[3] = crc >> 24;
priv->dev.d_mac.ether.ether_addr_octet[4] = crc >> 32;
priv->dev.d_mac.ether.ether_addr_octet[5] = crc >> 40;
/* Configure GPIO pins to support Ethernet */
stm32_ethgpioconfig(priv);