From 7451fe4766be12776013fa11fcbc99547aac00a4 Mon Sep 17 00:00:00 2001 From: Guilherme Ferreira Date: Mon, 16 Mar 2026 19:09:38 -0300 Subject: [PATCH] ci(esp_eth): add C++ regression guard for ethernet macros --- .../esp_eth/test_apps/main/CMakeLists.txt | 1 + .../test_apps/main/esp_eth_test_emac_init.cpp | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 components/esp_eth/test_apps/main/esp_eth_test_emac_init.cpp diff --git a/components/esp_eth/test_apps/main/CMakeLists.txt b/components/esp_eth/test_apps/main/CMakeLists.txt index 762a8c213f..e59653346d 100644 --- a/components/esp_eth/test_apps/main/CMakeLists.txt +++ b/components/esp_eth/test_apps/main/CMakeLists.txt @@ -4,6 +4,7 @@ idf_component_register(SRCS "esp_eth_test_main.c" "esp_eth_test_utils.c" "esp_eth_test_esp_emac.c" "esp_eth_test_emac_sleep_retention.c" + "esp_eth_test_emac_init.cpp" INCLUDE_DIRS "." PRIV_INCLUDE_DIRS "." PRIV_REQUIRES unity esp_eth esp_netif esp_http_client esp_driver_gpio esp_driver_uart diff --git a/components/esp_eth/test_apps/main/esp_eth_test_emac_init.cpp b/components/esp_eth/test_apps/main/esp_eth_test_emac_init.cpp new file mode 100644 index 0000000000..79d429873e --- /dev/null +++ b/components/esp_eth/test_apps/main/esp_eth_test_emac_init.cpp @@ -0,0 +1,66 @@ +/* + * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +// Initialize the Ethernet stack compiling as C++ to catch possible C++ specific build issues. +#include "sdkconfig.h" +#include "esp_eth_mac.h" +#include "esp_eth_mac_esp.h" +#include "esp_eth_phy.h" +#include "esp_eth_driver.h" + +#if CONFIG_ETH_USE_ESP32_EMAC +static void cpp_eth_init_internal_emac(void) __attribute__((unused)); +static void cpp_eth_init_internal_emac(void) +{ + eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); + + eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + eth_esp32_emac_config_t esp32_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_config, &mac_config); + if (mac == nullptr) { + return; + } + esp_eth_phy_t *phy = esp_eth_phy_new_generic(&phy_config); + if (phy == nullptr) { + (void)mac->del(mac); + return; + } + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); + esp_eth_handle_t handle = nullptr; + if (esp_eth_driver_install(ð_config, &handle) != ESP_OK) { + (void)phy->del(phy); + (void)mac->del(mac); + return; + } + (void)esp_eth_driver_uninstall(handle); + (void)phy->del(phy); + (void)mac->del(mac); +} + +#endif // CONFIG_ETH_USE_ESP32_EMAC + +#if CONFIG_ETH_USE_SPI_ETHERNET +#include "ethernet_init.h" + +static void cpp_eth_spi_custom_driver_config(void) __attribute__((unused)); +static void cpp_eth_spi_custom_driver_config(void) +{ + volatile eth_spi_custom_driver_config_t cfg = ETH_DEFAULT_SPI; + (void)cfg; +} + +static void cpp_eth_init_spi(void) __attribute__((unused)); +static void cpp_eth_init_spi(void) +{ + esp_eth_handle_t *handles = nullptr; + uint8_t cnt = 0; + (void)ethernet_init_all(&handles, &cnt); + if (handles != nullptr && cnt > 0) { + (void)ethernet_deinit_all(handles); + } +} +#endif // CONFIG_ETH_USE_SPI_ETHERNET