Page 1 of 1

ESP32C6: W5500 never obtains IP

Posted: Thu Jun 25, 2026 8:27 pm
by spystath
Hello!
I'm trying to interface an ESP32C6 (specifically ESP32-C6-Zero → https://docs.waveshare.com/ESP32-C6-Zero) with a W5500 breakout module. This is my pin configuration

MISO → GP4 (defined as ETH_MISO)
MOSI → GP22 (defined as ETH_MOSI)
SCLK → GP21 (defined as ETH_SCLK)
CSn → GP14 (defined as ETH_CSn)
INT → GP18 (defined as ETH_INT)
RST → GP0 (defined as ETH_RST)

I've adapted the code from the ethernet basic example (from here → https://github.com/espressif/esp-idf/bl ... ple_main.c) and used the w5500 component (from here → https://components.espressif.com/compon ... ssif/w5500). I have effectively replaced the eth_init function with the following code. I'm using ESP-IDF 6.x

Code: Select all

static esp_err_t eth_init(esp_eth_handle_t *eth_handle){
    spi_bus_config_t eth_spi_buscfg = {
        .miso_io_num = ETH_MISO,
        .mosi_io_num = ETH_MOSI,
        .sclk_io_num = ETH_SCLK,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .max_transfer_sz = 4096,
    };

    spi_device_interface_config_t eth_spi_devcfg = {
        .mode = 3,
        .clock_speed_hz = 15 * 1000 * 1000,
        .queue_size = 20,
        .command_bits = 16,
        .address_bits = 8,
        .spics_io_num = ETH_CSn,
    };

    esp_err_t eth_spi_init_ret = spi_bus_initialize(SPI2_HOST, &eth_spi_buscfg, SPI_DMA_CH_AUTO);
    if (eth_spi_init_ret != ESP_OK) {
        ESP_ERROR_CHECK(eth_spi_init_ret);
    } else {
        ESP_LOGI("SPI", "SPI bus initialized");
    }

    gpio_set_pull_mode(ETH_INT, GPIO_PULLUP_ENABLE);

    eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(SPI2_HOST, &eth_spi_devcfg);
    w5500_config.base.int_gpio_num = ETH_INT;

    eth_mac_config_t w5500_mac_config = ETH_MAC_DEFAULT_CONFIG();
    w5500_mac_config.rx_task_stack_size = 4096;
    esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &w5500_mac_config);
    uint8_t mac_bytes[6] = {0x02, 0x29, 0x11, 0x52, 0x33, 0x44};
    esp_err_t set_mac_err = mac->set_addr(mac, mac_bytes);
    if (set_mac_err != ESP_OK) {
        ESP_ERROR_CHECK(set_mac_err);
    } else {
        ESP_LOGI("ETH", "W5500 MAC initialised");
    }

    eth_phy_config_t eth_phy_config = ETH_PHY_DEFAULT_CONFIG();
    esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&eth_phy_config);
    eth_phy_config.reset_gpio_num = ETH_RST;

    if (phy == NULL) {
        ESP_LOGE("ETH", "W5500 PHY could not be created");
    } else {
        ESP_LOGI("ETH", "W5500 PHY initialised");
    }

    esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);

    esp_err_t eth_install_err = esp_eth_driver_install(&eth_config, eth_handle);
    if (eth_install_err != ESP_OK) {
        ESP_ERROR_CHECK(eth_install_err);
    } else {
        ESP_LOGI("ETH", "W5500 ETH driver initialised");
    }

    return ESP_OK;
}
This is app_main

Code: Select all

void app_main(void)
{
    /* Print chip information */
    esp_chip_info_t chip_info;
    uint32_t flash_size;
    esp_chip_info(&chip_info);
    printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
           CONFIG_IDF_TARGET,
           chip_info.cores,
           (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
           (chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
           (chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
           (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");

    unsigned major_rev = chip_info.revision / 100;
    unsigned minor_rev = chip_info.revision % 100;
    printf("silicon revision v%d.%d, ", major_rev, minor_rev);
    if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
        printf("Get flash size failed");
        return;
    }

    printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
           (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());

    gpio_install_isr_service(0);

    // Initialize Ethernet driver
    esp_eth_handle_t eth_handle;
    ESP_ERROR_CHECK(eth_init(&eth_handle));

    // Initialize TCP/IP network interface aka the esp-netif (should be called only once in application)
    ESP_ERROR_CHECK(esp_netif_init());

    // Create default event loop that running in background
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    // Create instance of esp-netif for Ethernet
    // Use ESP_NETIF_DEFAULT_ETH when just one Ethernet interface is used and you don't need to modify
    // default esp-netif configuration parameters.
    esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&cfg);
    esp_eth_netif_glue_handle_t eth_netif_glue = esp_eth_new_netif_glue(eth_handle);
    // Attach Ethernet driver to TCP/IP stack
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif, eth_netif_glue));

    // Register user defined event handlers
    ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

    // Start Ethernet driver state machine
    ESP_ERROR_CHECK(esp_eth_start(eth_handle));

    while(1) {
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
 }

I can indeed see the MAC address show up in my routers log but no address is ever assigned. It looks like initialisation is OK but no address is ever assigned to the interface and the logs pretty much stop here

Code: Select all

I (286) SPI: SPI bus initialized
I (286) ETH: W5500 MAC initialised
I (286) ETH: W5500 PHY initialised
I (306) ETH: W5500 ETH driver initialised
I (306) esp_eth.netif.netif_glue: 02:29:11:52:33:44
I (306) esp_eth.netif.netif_glue: ethernet attached to netif
I (316) eth_basic_example: Ethernet Started
I (2316) eth_basic_example: Ethernet Link Up

I've tried the following without success
  • Power the W5500 module from either the board 3V3 or through a LDO voltage regulator
  • Use polling instead of the INT pin
  • Use different clock speeds from 5 to 20 MHz
  • Tried Mode 0 and Mode 3
  • Try different combination of SPI GPIOs
  • Use static IP instead of DHCP
Could you please help me debug this? It is entirely possible that I'm missing something fundamental so apologies in advance. Happy to provide more information :-)

Re: ESP32C6: W5500 never obtains IP

Posted: Fri Jun 26, 2026 11:56 pm
by nopnop2002