fix: Reorder Ethernet initialization in VLAN example

- Moved `ethernet_init_all` to after default event loop creation
  to ensure the event loop exists before Ethernet driver initialization.
This commit is contained in:
Abhik Roy
2025-11-20 21:24:10 +11:00
parent 925b3775a7
commit 758ba6ab40
2 changed files with 27 additions and 19 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -128,16 +128,8 @@ void app_main(void)
s_vlan_event_group = xEventGroupCreate();
static esp_vlan_netifs vlan_netif_list;
// Initialize Ethernet driver
uint8_t eth_port_cnt = 0;
esp_eth_handle_t *eth_handle;
ESP_ERROR_CHECK(ethernet_init_all(&eth_handle, &eth_port_cnt));
// Check or multiple ethernet interface
if (1 < eth_port_cnt) {
ESP_LOGW(TAG, "Multiple Ethernet Interface detected: Only the first initialized interface is going to be used.");
}
// Initialize TCP/IP network interface (should be called only once in application)
ESP_ERROR_CHECK(esp_netif_init());
@@ -145,6 +137,14 @@ void app_main(void)
// Create default event loop that running in background
ESP_ERROR_CHECK(esp_event_loop_create_default());
// Initialize Ethernet driver
ESP_ERROR_CHECK(ethernet_init_all(&eth_handle, &eth_port_cnt));
// Check or multiple ethernet interface
if (1 < eth_port_cnt) {
ESP_LOGW(TAG, "Multiple Ethernet Interface detected: Only the first initialized interface is going to be used.");
}
// 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));