ESP32 + LAN8720: Ethernet fails at 240 MHz CPU frequency (IDF v5.3.1)

volksvorg
Posts: 5
Joined: Mon Feb 06, 2023 8:09 pm

ESP32 + LAN8720: Ethernet fails at 240 MHz CPU frequency (IDF v5.3.1)

Postby volksvorg » Mon Sep 01, 2025 6:08 pm

Hi all,

I’m using an ESP32-WROVER Dev Board together with a LAN8720 (Wireshark module) for Ethernet over RMII. At 160 MHz CPU frequency everything works fine:

DHCP assigns an IP address

Static IP also works, ping is possible

I can send and receive packets without issues

But when I change the CPU frequency to 240 MHz (via menuconfig), Ethernet completely stops working:

No DHCP lease is obtained

Static IP cannot be pinged

No packets are transmitted

Code: Select all

RMII pin configuration
GPIO21 -> TX_EN   (EMAC_TX_EN)
GPIO19 -> TX0     (EMAC_TXD0)
GPIO22 -> TX1     (EMAC_TXD1)
GPIO25 -> RX0     (EMAC_RXD0)
GPIO26 -> RX1     (EMAC_RXD1)
GPIO27 -> CRS_DV  (EMAC_RX_DRV)

SMI (Serial Management Interface):
GPIO23 -> MDC     (Output to PHY)
GPIO18 -> MDIO    (Bidirectional)

Clock: GPIO0 as external clock input (LAN8720 provides 50 MHz ref_clk)
Ethernet init code

Code: Select all

void network_ethernet_init(network_conf_t *conf) {
    esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&cfg);

    ESP_ERROR_CHECK(esp_netif_set_hostname(eth_netif, "ESP32-ETH"));

    eth_mac_config_t mac_cfg = ETH_MAC_DEFAULT_CONFIG();
    eth_esp32_emac_config_t esp32_mac_cfg = ETH_ESP32_EMAC_DEFAULT_CONFIG();
    esp32_mac_cfg.smi_gpio.mdc_num = ETH_MDC_GPIO;
    esp32_mac_cfg.smi_gpio.mdio_num = ETH_MDIO_GPIO;
    esp32_mac_cfg.interface = EMAC_DATA_INTERFACE_RMII;
    esp32_mac_cfg.clock_config.rmii.clock_mode = EMAC_CLK_EXT_IN;
    esp32_mac_cfg.clock_config.rmii.clock_gpio = 0;   // GPIO0 as ext clock in
    esp32_mac_cfg.dma_burst_len = ETH_DMA_BURST_LEN_16;

    esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_mac_cfg, &mac_cfg);

    eth_phy_config_t phy_cfg = ETH_PHY_DEFAULT_CONFIG();
    phy_cfg.phy_addr = 1;
    phy_cfg.reset_gpio_num = -1;
    esp_eth_phy_t *phy = esp_eth_phy_new_lan87xx(&phy_cfg);

    esp_eth_config_t eth_cfg = ETH_DEFAULT_CONFIG(mac, phy);
    esp_eth_handle_t eth_handle = NULL;
    ESP_ERROR_CHECK(esp_eth_driver_install(&eth_cfg, &eth_handle));
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
    ESP_ERROR_CHECK(esp_netif_dhcpc_start(eth_netif));
    ESP_ERROR_CHECK(esp_eth_start(eth_handle));

    uint8_t mac_addr[6];
    ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr));
    ESP_LOGI(TAG, "MAC: %02x:%02x:%02x:%02x:%02x:%02x",
             mac_addr[0], mac_addr[1], mac_addr[2],
             mac_addr[3], mac_addr[4], mac_addr[5]);

    ESP_LOGI(TAG, "Ethernet started (EMAC_CLK_EXT_IN, CPU 240MHz)");
}
Setup

Board: ESP32-WROVER Dev Board

PHY: LAN8720 (RMII mode, 50 MHz crystal on the module)

Clock: external 50 MHz ref_clk on GPIO0

ESP-IDF version: v5.3.1

Question

Has anyone experienced this problem?

Is there a known issue with ESP32 Ethernet when running at 240 MHz on IDF 5.3.1?

Do I need a different clock setup for the LAN8720 at higher CPU frequency?

Any workarounds or known fixes?

Thanks a lot for any hints!

tpbedford
Posts: 42
Joined: Mon Feb 14, 2022 4:16 am

Re: ESP32 + LAN8720: Ethernet fails at 240 MHz CPU frequency (IDF v5.3.1)

Postby tpbedford » Mon Sep 01, 2025 10:51 pm

ESP32-WROVER at 240MHz with IP101GRI works just fine with ESP_IDF 5.1.2 and 5.4.1. I've never run this CPU at 160MHz (at least, not with Ethernet) and don't recall having to do anything special with clocking.

I'm not forcing to 10Mbps but perhaps you could try that, if you don't need 100Mbps

You could check esp_err_t emac_config_pll_clock(emac_esp32_t *emac) is determining sane values and not truncating some divider.

volksvorg
Posts: 5
Joined: Mon Feb 06, 2023 8:09 pm

Re: ESP32 + LAN8720: Ethernet fails at 240 MHz CPU frequency (IDF v5.3.1)

Postby volksvorg » Tue Sep 02, 2025 2:38 pm

Hi,
I did some further testing and here is what I found:

I switched to ESP-IDF v6.0 – same behavior as before:

At 240 MHz CPU frequency → no IP address via DHCP.

At 160 MHz CPU frequency → works fine.

I checked the APLL clock configuration and it seems to be correct:

I (1991) MAIN: CPU freq: 240000000 Hz
I (1991) MAIN: APB freq: 80000000 Hz

What looks suspicious:
After the Ethernet driver starts, the auto-negotiation fails.
The link comes up as 10 Mbps half-duplex instead of 100 Mbps full-duplex.
Because of that, DHCP never succeeds.

To rule things out, I wrote a minimal test application (attached below).
It shows that with 240 MHz CPU frequency the LAN8720 PHY only negotiates 10 Mbps half-duplex.
With 160 MHz CPU frequency the negotiation succeeds and I get a valid IP via DHCP.

Here’s the test code (shortened for clarity):

Code: Select all

esp_log_level_set("*", ESP_LOG_DEBUG);
esp_log_level_set("esp.emac", ESP_LOG_DEBUG);
esp_log_level_set("rtc_clk", ESP_LOG_DEBUG);

esp32_mac_cfg.clock_config.rmii.clock_mode = EMAC_CLK_EXT_IN;  // PHY provides 50 MHz
esp32_mac_cfg.clock_config.rmii.clock_gpio = 0;

phy_cfg.phy_addr = 1;
phy_cfg.autonego_timeout_ms = 0;  // disable autoneg timeout

// after driver start
esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &speed);
esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &duplex);

ESP_LOGI("MAIN", "Link up: %d Mbps, %s duplex",
         speed == ETH_SPEED_100M ? 100 : 10,
         duplex == ETH_DUPLEX_FULL ? "full" : "half");
So to summarize:

Problem only at 240 MHz CPU frequency

Auto-negotiation fails (LAN8720 ends up in 10 Mbps half-duplex)

DHCP fails because of that

At 160 MHz everything works fine

Looks to me like a timing/clocking issue in the EMAC driver when running at 240 MHz.

Has anyone else seen this with the LAN8720? Or is there maybe a known workaround (forcing 100 Mbps full-duplex, patch for the PLL divider, etc.)?

tpbedford
Posts: 42
Joined: Mon Feb 14, 2022 4:16 am

Re: ESP32 + LAN8720: Ethernet fails at 240 MHz CPU frequency (IDF v5.3.1)

Postby tpbedford » Tue Sep 02, 2025 9:14 pm

If you have a minimal project that replicates this, I'd open an issue on the esp-idf github page.

Who is online

Users browsing this forum: Bing [Bot], Bytespider, ChatGPT-User and 3 guests