← index #6503Issue #9100
Related · high · value 4.427
QUERY · ISSUE

ESP32 LAN8720 MDC/MDIO control only

openby emardopened 2020-10-01updated 2024-10-01
port-esp32needs-info

HI

Are ESP32 libraries that control ETH RMII PHY available
for direct use, I need to control LAN8720 MD interface
with 2 pins called MDC/MDIO, and I'd like some suggestion
how to do it from micropython.

I'd like to control only the PHY using this 2 pins and
II don't want to initialize ESP32 complete wired ethernet
with all of RMII pins, because those RMII pins are not
connected to ESP32.

CANDIDATE · 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

'''

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