From 957750395f178ddd6e66eeacc96399ed3abdc2bd Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Tue, 21 Jul 2026 16:02:10 +0300 Subject: [PATCH 1/8] build: expose ESP-IDF Ethernet configuration Add esp_eth as an unconditional private component requirement so ESP-IDF loads its Kconfig before evaluating Willow's Ethernet option. Without it, ETH_SPI_ETHERNET_W5500 is undefined and CONFIG_WILLOW_ETHERNET cannot be enabled. ESP-IDF expands component dependencies before loading configuration. The esp_eth component remains configuration-only when CONFIG_ETH_ENABLED is disabled, so Wi-Fi builds do not compile the Ethernet driver. --- main/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2954fdc8..f86681d1 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -17,6 +17,7 @@ idf_component_register( audio_recorder audio_sal audio_stream + esp_eth esp_http_client esp_peripherals esp_websocket_client From 244717c0e2aaac2a9ceeb9cbeb96c9d7498bd775 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Tue, 21 Jul 2026 14:24:51 +0300 Subject: [PATCH 2/8] ethernet: reuse the default event loop init_system() creates the default ESP-IDF event loop before network initialization. Creating it again in init_ethernet() returns ESP_ERR_INVALID_STATE and makes ESP_ERROR_CHECK abort Ethernet startup. Reuse the system-owned event loop, matching the Wi-Fi path and keeping Ethernet initialization focused on its driver and event handlers. --- main/net/ethernet.c | 1 - 1 file changed, 1 deletion(-) diff --git a/main/net/ethernet.c b/main/net/ethernet.c index 4a9d3349..c3ac154b 100644 --- a/main/net/ethernet.c +++ b/main/net/ethernet.c @@ -80,7 +80,6 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t esp_err_t init_ethernet(void) { esp_err_t ret = ESP_OK; - ESP_ERROR_CHECK(esp_event_loop_create_default()); // Start Ethernet if (lvgl_port_lock(lvgl_lock_timeout)) { From 8378cd3d664a1a32400f6f3deeac7777a66aaa78 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 09:08:35 +0300 Subject: [PATCH 3/8] main: always declare hdl_nvs Always declare hdl_nvs regardless of Ethernet or Wi-Fi, as we need it to read the WAS URL if we use Ethernet. Fixes the following error when CONFIG_WILLOW_ETHERNET is enabled: /willow/main/main.c: In function 'app_main': /willow/main/main.c:125:42: error: 'hdl_nvs' undeclared (first use in this function) 125 | err = nvs_open("WAS", NVS_READONLY, &hdl_nvs); | ^~~~~~~ --- main/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 351d2622..b409eb93 100644 --- a/main/main.c +++ b/main/main.c @@ -94,10 +94,11 @@ void app_main(void) ESP_ERROR_CHECK(nvs_flash_init()); } + nvs_handle_t hdl_nvs; + #ifdef CONFIG_WILLOW_ETHERNET init_ethernet(); #else - nvs_handle_t hdl_nvs; err = nvs_open("WIFI", NVS_READONLY, &hdl_nvs); if (err != ESP_OK) { ESP_LOGE(TAG, "failed to open NVS namespace WIFI: %s", esp_err_to_name(err)); From 617a4218fb9094ae8630e6acd17ea4cb33b814ff Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 09:12:08 +0300 Subject: [PATCH 4/8] main: always declare sz Similar to the previous commit, we need to always declare the sz variable, as we need it to get the WAS URL from NVS. --- main/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index b409eb93..82efcc70 100644 --- a/main/main.c +++ b/main/main.c @@ -95,6 +95,7 @@ void app_main(void) } nvs_handle_t hdl_nvs; + size_t sz; #ifdef CONFIG_WILLOW_ETHERNET init_ethernet(); @@ -106,7 +107,7 @@ void app_main(void) } char psk[64]; - size_t sz = sizeof(psk); + sz = sizeof(psk); err = nvs_get_str(hdl_nvs, "PSK", psk, &sz); if (err != ESP_OK) { ESP_LOGE(TAG, "failed to get PSK from NVS namespace WIFI: %s", esp_err_to_name(err)); From cb9072e8f4eeab5dba9cfad7f774b80c44fb2bb0 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 09:31:10 +0300 Subject: [PATCH 5/8] ethernet: adapt W5500 setup to the current ESP-IDF API ESP-IDF changed ETH_W5500_DEFAULT_CONFIG() to accept the SPI host and device configuration. The W5500 driver now allocates the SPI device internally. Stop creating the SPI device explicitly and pass the host and device configuration directly to the W5500 configuration macro. This fixes the Ethernet build with the current ESP-IDF version. --- main/net/ethernet.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main/net/ethernet.c b/main/net/ethernet.c index c3ac154b..e06e7974 100644 --- a/main/net/ethernet.c +++ b/main/net/ethernet.c @@ -111,7 +111,6 @@ esp_err_t init_ethernet(void) eth_phy_config_t phy_config_spi = ETH_PHY_DEFAULT_CONFIG(); // Init SPI bus - spi_device_handle_t spi_handle[1] = {NULL}; spi_bus_config_t buscfg = { .miso_io_num = WILLOW_ETHERNET_MISO, .mosi_io_num = WILLOW_ETHERNET_MOSI, @@ -141,9 +140,8 @@ esp_err_t init_ethernet(void) // Set SPI module Chip Select GPIO devcfg.spics_io_num = spi_eth_module_config[i].spi_cs_gpio; - ESP_ERROR_CHECK(spi_bus_add_device(WILLOW_ETHERNET_SPI_BUS, &devcfg, &spi_handle[i])); // w5500 ethernet driver is based on spi driver - eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle[i]); + eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(WILLOW_ETHERNET_SPI_BUS, &devcfg); // Set remaining GPIO numbers and configuration used by the SPI module w5500_config.int_gpio_num = spi_eth_module_config[i].int_gpio; From 9ab97598391185e545a28170669fae9ea1942458 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 09:50:18 +0300 Subject: [PATCH 6/8] ethernet: derive MAC address from ESP The W5500 has no burned factory MAC address, so assigning a fixed test address makes every Willow Ethernet interface collide on the same LAN. Read ESP_MAC_ETH from ESP-IDF and assign that derived address to the W5500 driver. Remove the unused fake address left in network.c. --- main/net/ethernet.c | 12 ++++++------ main/network.c | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/main/net/ethernet.c b/main/net/ethernet.c index e06e7974..06bef86d 100644 --- a/main/net/ethernet.c +++ b/main/net/ethernet.c @@ -7,6 +7,7 @@ #include "driver/spi_master.h" #include "esp_eth.h" +#include "esp_mac.h" #include "shared.h" @@ -128,6 +129,8 @@ esp_err_t init_ethernet(void) esp_eth_mac_t *mac_spi[1]; esp_eth_phy_t *phy_spi[1]; esp_eth_handle_t eth_handle_spi[1] = {NULL}; + uint8_t eth_mac[6]; + ESP_ERROR_CHECK(esp_read_mac(eth_mac, ESP_MAC_ETH)); // W5500 spi_device_interface_config_t devcfg = {.command_bits = 16, // Actually it's the address phase in W5500 SPI frame @@ -156,12 +159,9 @@ esp_err_t init_ethernet(void) esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac_spi[i], phy_spi[i]); ESP_ERROR_CHECK(esp_eth_driver_install(ð_config_spi, ð_handle_spi[i])); - /* The SPI Ethernet module might not have a burned factory MAC address, we cat to set it manually. - 02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your - control. - */ - ESP_ERROR_CHECK( - esp_eth_ioctl(eth_handle_spi[i], ETH_CMD_S_MAC_ADDR, (uint8_t[]){0x02, 0x00, 0x00, 0x12, 0x34, 0x56 + i})); + // The W5500 has no burned factory address. Use the Ethernet address + // derived from the ESP's base MAC instead. + ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle_spi[i], ETH_CMD_S_MAC_ADDR, eth_mac)); // attach Ethernet driver to TCP/IP stack ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi[i], esp_eth_new_netif_glue(eth_handle_spi[i]))); diff --git a/main/network.c b/main/network.c index afca8be9..49b58c2b 100644 --- a/main/network.c +++ b/main/network.c @@ -30,7 +30,6 @@ static EventGroupHandle_t hdl_evg; static const char *TAG = "WILLOW/NETWORK"; -uint8_t mac_address[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; void cb_sntp(struct timeval *tv) { From c4afcccc2060cd2fdd7db080d1897f1a88e803c7 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 10:00:31 +0300 Subject: [PATCH 7/8] ethernet: set MAC-derived hostname Pass the concrete esp-netif handle to the shared hostname helper instead of selecting the first registered interface. This preserves Wi-Fi behavior and lets Ethernet set its MAC-derived hostname before DHCP starts. Store the Ethernet interface in hdl_netif so the remaining WAS code can read the configured hostname. --- main/net/ethernet.c | 3 +++ main/network.c | 14 +++++--------- main/network.h | 4 ++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/main/net/ethernet.c b/main/net/ethernet.c index 06bef86d..9ae02ae3 100644 --- a/main/net/ethernet.c +++ b/main/net/ethernet.c @@ -9,6 +9,7 @@ #include "esp_eth.h" #include "esp_mac.h" +#include "network.h" #include "shared.h" #define WILLOW_ETHERNET_CS 10 @@ -167,6 +168,8 @@ esp_err_t init_ethernet(void) ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi[i], esp_eth_new_netif_glue(eth_handle_spi[i]))); } + set_hostname(eth_netif_spi[0], ESP_MAC_ETH); + // Register user defined event handers ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL)); diff --git a/main/network.c b/main/network.c index 49b58c2b..264c0ff4 100644 --- a/main/network.c +++ b/main/network.c @@ -48,28 +48,24 @@ void cb_sntp(struct timeval *tv) } } -void set_hostname(esp_mac_type_t emt) +void set_hostname(esp_netif_t *netif, esp_mac_type_t mac_type) { esp_err_t ret = ESP_OK; uint8_t mac[MAC_ADDR_SIZE]; - ret = esp_read_mac(mac, emt); + ret = esp_read_mac(mac, mac_type); if (ret != ESP_OK) { ESP_LOGE(TAG, "failed to read MAC address, using default hostname (%s)", CONFIG_LWIP_LOCAL_HOSTNAME); return; } - while (esp_netif_get_nr_of_ifs() == 0) { - vTaskDelay(100 / portTICK_PERIOD_MS); - } - char hostname[HOSTNAME_SIZE]; - hdl_netif = esp_netif_next_unsafe(NULL); + hdl_netif = netif; snprintf(hostname, HOSTNAME_SIZE, "willow-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - ret = esp_netif_set_hostname(hdl_netif, hostname); + ret = esp_netif_set_hostname(netif, hostname); if (ret != ESP_OK) { ESP_LOGE(TAG, "failed to set hostname (%s): %s", hostname, esp_err_to_name(ret)); } @@ -218,7 +214,7 @@ esp_err_t init_wifi(const char *psk, const char *ssid) strlcpy((char *)cfg_wifi.sta.password, psk, sizeof(cfg_wifi.sta.password)); strlcpy((char *)cfg_wifi.sta.ssid, ssid, sizeof(cfg_wifi.sta.ssid)); - set_hostname(ESP_MAC_WIFI_STA); + set_hostname(netif_wifi, ESP_MAC_WIFI_STA); ret = esp_wifi_set_config(ESP_IF_WIFI_STA, &cfg_wifi); if (ret != ESP_OK) { diff --git a/main/network.h b/main/network.h index 7984b62f..cf52df48 100644 --- a/main/network.h +++ b/main/network.h @@ -1,5 +1,9 @@ +#include "esp_mac.h" +#include "esp_netif.h" + extern esp_netif_t *hdl_netif; esp_err_t init_wifi(const char *psk, const char *ssid); esp_err_t init_ethernet(void); void get_mac_address(void); +void set_hostname(esp_netif_t *netif, esp_mac_type_t mac_type); From 5447068e3de786ddc413abe55b97bb44c3da6d47 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 23 Jul 2026 11:23:46 +0300 Subject: [PATCH 8/8] ethernet: enable SNTP and timezone The Ethernet path skipped the shared SNTP lifecycle, so it neither applied the configured timezone nor synchronized the system clock. Expose the helpers and initialize SNTP before bringing up the W5500 interface. Start it after the existing connection wait. The shared configuration already selects the Ethernet IP event. --- main/net/ethernet.c | 4 ++++ main/network.c | 4 ++-- main/network.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main/net/ethernet.c b/main/net/ethernet.c index 9ae02ae3..d77b3675 100644 --- a/main/net/ethernet.c +++ b/main/net/ethernet.c @@ -83,6 +83,8 @@ esp_err_t init_ethernet(void) { esp_err_t ret = ESP_OK; + init_sntp(); + // Start Ethernet if (lvgl_port_lock(lvgl_lock_timeout)) { lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); @@ -188,5 +190,7 @@ esp_err_t init_ethernet(void) // HACK vTaskDelay(5000 / portTICK_PERIOD_MS); + start_sntp(); + return ret; } diff --git a/main/network.c b/main/network.c index 264c0ff4..c63318f5 100644 --- a/main/network.c +++ b/main/network.c @@ -71,7 +71,7 @@ void set_hostname(esp_netif_t *netif, esp_mac_type_t mac_type) } } -static esp_err_t init_sntp(void) +esp_err_t init_sntp(void) { ESP_LOGI(TAG, "initializing SNTP client"); esp_err_t ret = ESP_OK; @@ -95,7 +95,7 @@ static esp_err_t init_sntp(void) return ret; } -static esp_err_t start_sntp(void) +esp_err_t start_sntp(void) { char *ntp_config = config_get_char("ntp_config", DEFAULT_NTP_CONFIG); if (strcmp(ntp_config, "DHCP") == 0) { diff --git a/main/network.h b/main/network.h index cf52df48..3dd371b3 100644 --- a/main/network.h +++ b/main/network.h @@ -5,5 +5,7 @@ extern esp_netif_t *hdl_netif; esp_err_t init_wifi(const char *psk, const char *ssid); esp_err_t init_ethernet(void); +esp_err_t init_sntp(void); +esp_err_t start_sntp(void); void get_mac_address(void); void set_hostname(esp_netif_t *netif, esp_mac_type_t mac_type);