← index #9100PR #4515
Duplicate · high · value 4.090
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 · PULL REQUEST

Add support clock mode for ESP32 ethernet module

closedby petrkropened 2019-02-17updated 2019-02-21
port-esp32

I've added optional parameter support for network.LAN clock_mode and implemented new enum string for network module class to support Clock mode for ESP32.

Can be used for some cases when especially LAN8720 modules uses clock source from ESP's pin GPIO17.

usage:

import machine
import network

lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=None, phy_type = network.PHY_LAN8720, phy_addr=1, clock_mode=network.ETH_CLOCK_GPIO17_OUT)
lan.active(1)

new enum at network module:

>>> for i in dir(network): print(i)
... 
ETH_CLOCK_GPIO0_IN
ETH_CLOCK_GPIO16_OUT
ETH_CLOCK_GPIO17_OUT
...

Also added catch events for ethernet module:

I (44868) ethernet: start
True
>>> I (48868) ethernet: LAN cable connected
I (49798) event: eth ip: 10.0.0.137, mask: 255.255.255.0, gw: 10.0.0.1
I (49798) ethernet: Got IP
I (64868) ethernet: LAN cable disconnected
I (72868) ethernet: LAN cable connected
I (73798) event: eth ip: 10.0.0.137, mask: 255.255.255.0, gw: 10.0.0.1
I (73798) ethernet: Got IP

should fix #4502

Later I think about do some events like wifi has. But for fix work with different clock modes should be this enough.

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