← index #9100Issue #9025
Related · high · value 3.943
QUERY · ISSUE

LAN8720 Can't work on esp32 with ETH_CLOCK_GPIO17_OUT

openby coinightopened 2022-08-25updated 2026-03-19
bugport-esp32proposed-close

I read the source code from network_lan.c from ports/esp32
in line 143

eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.smi_mdc_gpio_num = self->mdc_pin;
mac_config.smi_mdio_gpio_num = self->mdio_pin;
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);

it use default config but many boards' lan8720 are setted with other clock
like my board is GPIO17

In Arduino the code is write like this(https://github.com/espressif/arduino-esp32/blob/ba6e82c30d31a2ddc1276a045e0c42a29b38869f/libraries/Ethernet/src/ETH.cpp Line:257)

eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.clock_config.rmii.clock_mode = (eth_clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
mac_config.clock_config.rmii.clock_gpio = (1 == eth_clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == eth_clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == eth_clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO;
mac_config.smi_mdc_gpio_num = mdc;
mac_config.smi_mdio_gpio_num = mdio;
mac_config.sw_reset_timeout_ms = 1000;
eth_mac = esp_eth_mac_new_esp32(&mac_config);

It enabled clock config with {gpio0:EMAC_TX_CLK,gpio0:CLK_OUT1,gpio16:EMAC_CLK_OUT,gpio17:EMAC_CLK_180}
without clock set lan8720 return OSError: esp_eth_driver_install failed,which can't work
Could micropython support clock config ? It really help a lot.Thanks

my mpy code is below:

import network
nic = network.LAN(0,mdc= Pin(23),mdio=Pin(18),
                  phy_addr=0,phy_type=network.PHY_LAN8720
                  )
'''
#define ETH_ADDR        0
#define ETH_POWER_PIN  -1
#define ETH_MDC_PIN    23
#define ETH_MDIO_PIN   18
#define LED             2
#define ETH_TYPE       ETH_PHY_LAN8720
#define ETH_CLK_MODE   ETH_CLOCK_GPIO17_OUT
#define ETH_RESET      5

'''
CANDIDATE · ISSUE

LAN8720 ESP32 throwing error on new firmware

openby hetvishah08opened 2022-08-06updated 2022-08-06
bug

I have made a custom board and I referred to the documentation and tried to connect the LAN8720 with ESP32 and it gives an error as extra keywords given. Also, I feel the documentation of LAN network is incomplete.

It mentions phy_clock but on adding this key it provides error. The firmware used is v.19.1

phy

import network import machine import time from machine import Pin print("Initializing LAN") l = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), phy_type = network.PHY_LAN8720,phy_clock = False, phy_addr=1) P32 = Pin(32, Pin.OUT) P32(0) time.sleep_ms(500) P32(1) Initializing LAN Traceback (most recent call last): File "<stdin>", line 6, in <module> TypeError: extra keyword arguments given

If i remove the phy_clock key, I get the following error:

import network import machine import time from machine import Pin print("Initializing LAN") l = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), phy_type = network.PHY_LAN8720, phy_addr=1) P32 = Pin(32, Pin.OUT) P32(0) time.sleep_ms(500) P32(1) Initializing LAN E (210) emac_esp32: emac_esp32_init(308): reset timeout E (210) esp_eth: esp_eth_driver_install(198): init mac failed Traceback (most recent call last): File "<stdin>", line 6, in <module> OSError: esp_eth_driver_install failed

If I use an older firmware(v.13) version it detects lan but doesn't provide any IP Address. The older version had no field named phy_clock.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied