Skip to content

Commit 293b2d9

Browse files
committed
fix: use default MAC address only if no MAC_ADDRx defined
Anyway the MAC address get by the application is always 0 while the real address is correct. Will be fixed by latter commit. Signed-off-by: Frederic Pillon <[email protected]>
1 parent cc099cf commit 293b2d9

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/STM32Ethernet.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ int EthernetClass::begin(unsigned long timeout, unsigned long responseTimeout)
55
{
66
static DhcpClass s_dhcp;
77
_dhcp = &s_dhcp;
8-
stm32_eth_init(MACAddressDefault(), NULL, NULL, NULL);
8+
stm32_eth_init(NULL, NULL, NULL, NULL);
99

1010
// Now try to get our config info from a DHCP server
1111
int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
@@ -39,7 +39,7 @@ void EthernetClass::begin(IPAddress local_ip, IPAddress subnet, IPAddress gatewa
3939

4040
void EthernetClass::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server)
4141
{
42-
stm32_eth_init(MACAddressDefault(), local_ip.raw_address(), gateway.raw_address(), subnet.raw_address());
42+
stm32_eth_init(NULL, local_ip.raw_address(), gateway.raw_address(), subnet.raw_address());
4343
/* If there is a local DHCP informs it of our manual IP configuration to
4444
prevent IP conflict */
4545
stm32_DHCP_manual_config();
@@ -133,20 +133,6 @@ void EthernetClass::schedule(void)
133133
stm32_eth_scheduler();
134134
}
135135

136-
uint8_t *EthernetClass::MACAddressDefault(void)
137-
{
138-
if ((mac_address[0] + mac_address[1] + mac_address[2] + mac_address[3] + mac_address[4] + mac_address[5]) == 0) {
139-
uint32_t baseUID = *(uint32_t *)UID_BASE;
140-
mac_address[0] = 0x00;
141-
mac_address[1] = 0x80;
142-
mac_address[2] = 0xE1;
143-
mac_address[3] = (baseUID & 0x00FF0000) >> 16;
144-
mac_address[4] = (baseUID & 0x0000FF00) >> 8;
145-
mac_address[5] = (baseUID & 0x000000FF);
146-
}
147-
return mac_address;
148-
}
149-
150136
void EthernetClass::MACAddress(uint8_t *mac)
151137
{
152138
mac_address[0] = mac[0];

src/STM32Ethernet.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class EthernetClass {
1818
IPAddress _dnsServerAddress;
1919
DhcpClass *_dhcp;
2020
uint8_t mac_address[6];
21-
uint8_t *MACAddressDefault(void);
2221

2322
public:
2423
// Initialise the Ethernet with the internal provided MAC address and gain the rest of the

src/utility/ethernetif.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ __ALIGN_BEGIN uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __ALIGN_END; /* Ethe
9696

9797
static ETH_HandleTypeDef EthHandle;
9898

99+
/* If default MAC fields is not defined use default values based on UID */
100+
#if !defined(MAC_ADDR0)
101+
#define MAC_ADDR0 0x00
102+
#endif
103+
#if !defined(MAC_ADDR1)
104+
#define MAC_ADDR1 0x80
105+
#endif
106+
#if !defined(MAC_ADDR2)
107+
#define MAC_ADDR2 0xE1
108+
#endif
109+
#if !defined(MAC_ADDR3)
110+
#define MAC_ADDR3 ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x00FF0000) >> 16))
111+
#endif
112+
#if !defined(MAC_ADDR4)
113+
#define MAC_ADDR4 ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x0000FF00) >> 8))
114+
#endif
115+
#if !defined(MAC_ADDR5)
116+
#define MAC_ADDR5 ((uint8_t)((*(uint32_t *)UID_BASE) & 0x000000FF))
117+
#endif
99118
static uint8_t macaddress[6] = { MAC_ADDR0, MAC_ADDR1, MAC_ADDR2, MAC_ADDR3, MAC_ADDR4, MAC_ADDR5 };
100119

101120
#if LWIP_IGMP

0 commit comments

Comments
 (0)