Skip to content

Commit 7c9b837

Browse files
smuellenerSuGliderme-no-dev
authored
Fix Reading MAC from efuse for ESP32 Arduino 2.x.x (#6458) (#6459)
Also support ESP_IDF_VERSION_MAJOR > 3 Fixes #6458 Co-authored-by: Rodrigo Garcia <[email protected]> Co-authored-by: Me No Dev <[email protected]>
1 parent 5c5a112 commit 7c9b837

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

libraries/Ethernet/src/ETH.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,19 @@ ETHClass::ETHClass()
226226
ETHClass::~ETHClass()
227227
{}
228228

229-
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode)
229+
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode, bool use_mac_from_efuse)
230230
{
231231
#if ESP_IDF_VERSION_MAJOR > 3
232232
eth_clock_mode = clock_mode;
233233
tcpipInit();
234234

235+
if (use_mac_from_efuse)
236+
{
237+
uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
238+
esp_efuse_mac_get_custom(p);
239+
esp_base_mac_addr_set(p);
240+
}
241+
235242
tcpip_adapter_set_default_eth_handlers();
236243

237244
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
@@ -363,6 +370,14 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
363370
}
364371

365372
tcpipInit();
373+
374+
if (use_mac_from_efuse)
375+
{
376+
uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
377+
esp_efuse_mac_get_custom(p);
378+
esp_base_mac_addr_set(p);
379+
}
380+
366381
err = esp_eth_init(&eth_config);
367382
if(!err){
368383
initialized = true;

libraries/Ethernet/src/ETH.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ETHClass {
7575
ETHClass();
7676
~ETHClass();
7777

78-
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
78+
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE, bool use_mac_from_efuse=false);
7979

8080
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
8181

0 commit comments

Comments
 (0)