← index #9100PR #9710
Duplicate · high · value 1.175
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

esp32/network_lan: Add clock configuration.

closedby bartek-wopened 2022-10-22updated 2023-01-18
port-esp32

Allow support for Olimex esp32-poe board family.

Testes with code snippet on esp32-poe-iso:

import network
import machine

lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=machine.Pin(12), phy_type = network.PHY_LAN8720, phy_addr=0, clock_out = machine.Pin(17))
lan.active(1)
lan.ifconfig()

Solves issue https://github.com/micropython/micropython/issues/9100

Signed-off-by: Bartek bartekwolowiec@gmail.com

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