← index #9100PR #10329
Duplicate · high · value 1.854
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: Support dynamic configuration of ETH ref-clk mode and pin.

mergedby robert-hhopened 2022-12-25updated 2023-01-19
port-esp32

Consisting of three commits:

  • Add the PHY_LAN8710 name. the LAN8710 shares the code with the LAN8720.
  • Implement the keyword options ref_clk_mode and ref_clk_pin to set the mode and Pin.
  • Add a few words of documentation, picking up #7356, which was never merged, albeit considered as appropriate.

If ref_clk_mode is not set, the default settings e.g. taken from the board's config file are used. Setting ref_clk_mode and ref_clk_pin requires at least esp-idf v4.4. It builds with

Tested with the Olimex esp32_POE and Olimex ESP32 POE ISO boards.

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