From 0fdb9e17640aaa5d96b83f9d97857db7f705d1dc Mon Sep 17 00:00:00 2001 From: zinkett <96108358+zinkett@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:41:11 +0200 Subject: [PATCH] feat(examples): improved example for Ethernet SPI polling mode without interrupt Update example for polling mode, without interrupt pin --- .../protocol_examples_common/Kconfig.projbuild | 10 +++++++++- .../protocol_examples_common/eth_connect.c | 14 ++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/common_components/protocol_examples_common/Kconfig.projbuild b/examples/common_components/protocol_examples_common/Kconfig.projbuild index f9ccbfb569..98d541f34d 100644 --- a/examples/common_components/protocol_examples_common/Kconfig.projbuild +++ b/examples/common_components/protocol_examples_common/Kconfig.projbuild @@ -295,10 +295,18 @@ menu "Example Connection Configuration" config EXAMPLE_ETH_SPI_INT_GPIO int "Interrupt GPIO number" - range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX + range -1 ENV_GPIO_IN_RANGE_MAX default 4 help Set the GPIO number used by the SPI Ethernet module interrupt line. + Set -1 to use SPI Ethernet module in polling mode. + + config EXAMPLE_ETH_SPI_POLLING_MS_VAL + depends on EXAMPLE_ETH_SPI_INT_GPIO < 0 + int "Polling period in msec of SPI Ethernet Module" + default 10 + help + Set SPI Ethernet module polling period. endif # EXAMPLE_USE_SPI_ETHERNET config EXAMPLE_ETH_PHY_RST_GPIO diff --git a/examples/common_components/protocol_examples_common/eth_connect.c b/examples/common_components/protocol_examples_common/eth_connect.c index ad48069021..a69a0bd217 100644 --- a/examples/common_components/protocol_examples_common/eth_connect.c +++ b/examples/common_components/protocol_examples_common/eth_connect.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -115,7 +115,7 @@ static esp_netif_t *eth_start(void) s_phy = esp_eth_phy_new_dp83848(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_KSZ80XX s_phy = esp_eth_phy_new_ksz80xx(&phy_config); -#endif +#endif // CONFIG_EXAMPLE_ETH_PHY_GENERIC #elif CONFIG_EXAMPLE_USE_SPI_ETHERNET gpio_install_isr_service(0); spi_bus_config_t buscfg = { @@ -136,20 +136,26 @@ static esp_netif_t *eth_start(void) /* dm9051 ethernet driver is based on spi driver */ eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg); dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; +#if CONFIG_EXAMPLE_ETH_SPI_INT_GPIO < 0 + dm9051_config.poll_period_ms = CONFIG_EXAMPLE_ETH_SPI_POLLING_MS_VAL; +#endif // CONFIG_EXAMPLE_ETH_SPI_INT_GPIO s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); s_phy = esp_eth_phy_new_dm9051(&phy_config); #elif CONFIG_EXAMPLE_USE_W5500 /* w5500 ethernet driver is based on spi driver */ eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg); w5500_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; +#if CONFIG_EXAMPLE_ETH_SPI_INT_GPIO < 0 + w5500_config.poll_period_ms = CONFIG_EXAMPLE_ETH_SPI_POLLING_MS_VAL; +#endif // CONFIG_EXAMPLE_ETH_SPI_INT_GPIO s_mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config); s_phy = esp_eth_phy_new_w5500(&phy_config); -#endif +#endif // CONFIG_EXAMPLE_USE_DM9051 #elif CONFIG_EXAMPLE_USE_OPENETH phy_config.autonego_timeout_ms = 100; s_mac = esp_eth_mac_new_openeth(&mac_config); s_phy = esp_eth_phy_new_dp83848(&phy_config); -#endif +#endif // CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET // Install Ethernet driver esp_eth_config_t config = ETH_DEFAULT_CONFIG(s_mac, s_phy);