From 93368deead116d1e84156fea2c3ea127a6ff439d Mon Sep 17 00:00:00 2001 From: Bogdan Kolendovskyy Date: Wed, 6 Mar 2024 14:00:15 +0100 Subject: [PATCH] feat: Added support of SPI Ethernet PHY poll mode to ethernet_init component --- .github/workflows/ethernet_init__build.yml | 5 ++- ethernet_init/Kconfig.projbuild | 35 +++++++++++++++++-- ethernet_init/ethernet_init.c | 23 +++++++----- .../simple-ethernet/sdkconfig.defaults.dm9051 | 7 ++++ .../sdkconfig.defaults.dp83848 | 10 ++++++ .../simple-ethernet/sdkconfig.defaults.ip101 | 10 ++++++ .../sdkconfig.defaults.ksz80xx | 10 ++++++ .../sdkconfig.defaults.ksz8851snl | 7 ++++ .../sdkconfig.defaults.lan867x | 10 ++++++ .../sdkconfig.defaults.lan87xx | 10 ++++++ .../sdkconfig.defaults.rtl8201 | 10 ++++++ .../simple-ethernet/sdkconfig.defaults.w5500 | 7 ++++ ethernet_init/idf_component.yml | 4 +-- 13 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dm9051 create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dp83848 create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ip101 create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz80xx create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz8851snl create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan867x create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan87xx create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.rtl8201 create mode 100644 ethernet_init/examples/simple-ethernet/sdkconfig.defaults.w5500 diff --git a/.github/workflows/ethernet_init__build.yml b/.github/workflows/ethernet_init__build.yml index efc3eae..ece8ea7 100644 --- a/.github/workflows/ethernet_init__build.yml +++ b/.github/workflows/ethernet_init__build.yml @@ -9,6 +9,7 @@ jobs: idf_ver: ["latest"] example: ["simple-ethernet"] idf_target: ["esp32"] + eth_target: ["ip101", "lan87xx", "rtl8201", "ksz80xx", "dp83848", "lan867x", "ksz8851snl", "w5500", "dm9051"] runs-on: ubuntu-20.04 container: espressif/idf:${{ matrix.idf_ver }} @@ -17,11 +18,13 @@ jobs: uses: actions/checkout@master with: path: esp_eth_drivers - - name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }} + - name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }} with ${{ matrix.eth_target }} env: IDF_TARGET: ${{ matrix.idf_target }} shell: bash run: | . ${IDF_PATH}/export.sh cd $GITHUB_WORKSPACE/esp_eth_drivers/ethernet_init/examples/${{ matrix.example }} + mv sdkconfig.defaults.${{ matrix.eth_target }} sdkconfig.defaults + idf.py reconfigure idf.py build diff --git a/ethernet_init/Kconfig.projbuild b/ethernet_init/Kconfig.projbuild index 6a12a21..b06102e 100644 --- a/ethernet_init/Kconfig.projbuild +++ b/ethernet_init/Kconfig.projbuild @@ -197,12 +197,13 @@ menu "Ethernet Configuration" config ETHERNET_SPI_INT0_GPIO int "Interrupt GPIO number SPI Ethernet module #1" - range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX + range -1 ENV_GPIO_IN_RANGE_MAX default 4 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 default 4 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6 default 10 if IDF_TARGET_ESP32H2 help Set the GPIO number used by the first SPI Ethernet module interrupt line. + Set -1 to use SPI Ethernet module in polling mode. config ETHERNET_SPI_PHY_RST0_GPIO int "PHY Reset GPIO number of SPI Ethernet Module #1" @@ -247,13 +248,14 @@ menu "Ethernet Configuration" config ETHERNET_SPI_INT1_GPIO depends on ETHERNET_SPI_NUMBER > 1 int "Interrupt GPIO number SPI Ethernet module #2" - range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX + range -1 ENV_GPIO_IN_RANGE_MAX default 33 if IDF_TARGET_ESP32 default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2 default 5 if IDF_TARGET_ESP32C6 default 9 if IDF_TARGET_ESP32H2 help Set the GPIO number used by the second SPI Ethernet module interrupt line. + Set -1 to use SPI Ethernet module in polling mode. config ETHERNET_SPI_PHY_RST1_GPIO depends on ETHERNET_SPI_NUMBER > 1 @@ -284,5 +286,34 @@ menu "Ethernet Configuration" default "5a:bf:25:e0:41:01" depends on (!ETHERNET_SPI_AUTOCONFIG_MAC_ADDR1) && (ETHERNET_SPI_NUMBER > 1) + config ETHERNET_SPI_POLLING0_MS_VAL + depends on ETHERNET_SPI_INT0_GPIO < 0 + int "Polling period in msec of SPI Ethernet Module #1" + default 10 + help + Set SPI Ethernet module polling period. + + config ETHERNET_SPI_POLLING1_MS_VAL + depends on ETHERNET_SPI_NUMBER > 1 && ETHERNET_SPI_INT1_GPIO < 0 + int "Polling period in msec of SPI Ethernet Module #2" + default 10 + help + Set SPI Ethernet module polling period. + + # Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and + # it is set to known value (0) when interrupt is enabled at the same time. + config ETHERNET_SPI_POLLING0_MS + int + default ETHERNET_SPI_POLLING0_MS_VAL if ETHERNET_SPI_POLLING0_MS_VAL > 0 + default 0 + + # Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and + # it is set to known value (0) when interrupt is enabled at the same time. + config ETHERNET_SPI_POLLING1_MS + depends on ETHERNET_SPI_NUMBER > 1 + int + default ETHERNET_SPI_POLLING1_MS_VAL if ETHERNET_SPI_POLLING1_MS_VAL > 0 + default 0 + endif # ETHERNET_SPI_SUPPORT endmenu diff --git a/ethernet_init/ethernet_init.c b/ethernet_init/ethernet_init.c index b013a87..c9f5a66 100644 --- a/ethernet_init/ethernet_init.c +++ b/ethernet_init/ethernet_init.c @@ -32,10 +32,11 @@ #define INTERNAL_ETHERNETS_NUM 0 #endif -#define INIT_SPI_ETH_MODULE_CONFIG(eth_module_config, num) \ - do { \ +#define INIT_SPI_ETH_MODULE_CONFIG(eth_module_config, num) \ + do { \ eth_module_config[num].spi_cs_gpio = CONFIG_ETHERNET_SPI_CS ##num## _GPIO; \ eth_module_config[num].int_gpio = CONFIG_ETHERNET_SPI_INT ##num## _GPIO; \ + eth_module_config[num].poll_period_ms = CONFIG_ETHERNET_SPI_POLLING ##num## _MS; \ eth_module_config[num].phy_reset_gpio = CONFIG_ETHERNET_SPI_PHY_RST ##num## _GPIO; \ eth_module_config[num].phy_addr = CONFIG_ETHERNET_SPI_PHY_ADDR ##num; \ } while(0) @@ -50,7 +51,8 @@ typedef struct { uint8_t spi_cs_gpio; - uint8_t int_gpio; + int8_t int_gpio; + uint32_t poll_period_ms; int8_t phy_reset_gpio; uint8_t phy_addr; uint8_t *mac_addr; @@ -277,18 +279,21 @@ static esp_eth_handle_t eth_init_spi(spi_eth_module_config_t *spi_eth_module_con #if CONFIG_ETHERNET_USE_KSZ8851SNL eth_ksz8851snl_config_t ksz8851snl_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(CONFIG_ETHERNET_SPI_HOST, &spi_devcfg); ksz8851snl_config.int_gpio_num = spi_eth_module_config->int_gpio; - dev->mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config); - dev->phy = esp_eth_phy_new_ksz8851snl(&phy_config); - sprintf(dev->dev_info.name, "KSZ8851SNL"); + ksz8851snl_config.poll_period_ms = spi_eth_module_config->poll_period_ms; + dev_out->mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config); + dev_out->phy = esp_eth_phy_new_ksz8851snl(&phy_config); + sprintf(dev_out->dev_info.name, "KSZ8851SNL"); #elif CONFIG_ETHERNET_USE_DM9051 eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(CONFIG_ETHERNET_SPI_HOST, &spi_devcfg); dm9051_config.int_gpio_num = spi_eth_module_config->int_gpio; - dev->mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); - dev->phy = esp_eth_phy_new_dm9051(&phy_config); - sprintf(dev->dev_info.name, "DM9051"); + dm9051_config.poll_period_ms = spi_eth_module_config->poll_period_ms; + dev_out->mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); + dev_out->phy = esp_eth_phy_new_dm9051(&phy_config); + sprintf(dev_out->dev_info.name, "DM9051"); #elif CONFIG_ETHERNET_USE_W5500 eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_ETHERNET_SPI_HOST, &spi_devcfg); w5500_config.int_gpio_num = spi_eth_module_config->int_gpio; + w5500_config.poll_period_ms = spi_eth_module_config->poll_period_ms; dev_out->mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config); dev_out->phy = esp_eth_phy_new_w5500(&phy_config); sprintf(dev_out->dev_info.name, "W5500"); diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dm9051 b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dm9051 new file mode 100644 index 0000000..0802634 --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dm9051 @@ -0,0 +1,7 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=n + +CONFIG_ETHERNET_SPI_SUPPORT=y +CONFIG_ETHERNET_SPI_NUMBER=1 +CONFIG_ETHERNET_USE_DM9051=y +CONFIG_ETHERNET_USE_KSZ8851SNL=n +CONFIG_ETHERNET_USE_W5500=n diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dp83848 b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dp83848 new file mode 100644 index 0000000..97478b6 --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dp83848 @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=n +CONFIG_ETHERNET_PHY_RTL8201=n +CONFIG_ETHERNET_PHY_LAN87XX=n +CONFIG_ETHERNET_PHY_DP83848=y +CONFIG_ETHERNET_PHY_KSZ80XX=n +CONFIG_ETHERNET_PHY_LAN867X=n + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ip101 b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ip101 new file mode 100644 index 0000000..b070501 --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ip101 @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=y +CONFIG_ETHERNET_PHY_RTL8201=n +CONFIG_ETHERNET_PHY_LAN87XX=n +CONFIG_ETHERNET_PHY_DP83848=n +CONFIG_ETHERNET_PHY_KSZ80XX=n +CONFIG_ETHERNET_PHY_LAN867X=n + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz80xx b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz80xx new file mode 100644 index 0000000..0d5fdbc --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz80xx @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=n +CONFIG_ETHERNET_PHY_RTL8201=n +CONFIG_ETHERNET_PHY_LAN87XX=n +CONFIG_ETHERNET_PHY_DP83848=n +CONFIG_ETHERNET_PHY_KSZ80XX=y +CONFIG_ETHERNET_PHY_LAN867X=n + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz8851snl b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz8851snl new file mode 100644 index 0000000..3951b08 --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz8851snl @@ -0,0 +1,7 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=n + +CONFIG_ETHERNET_SPI_SUPPORT=y +CONFIG_ETHERNET_SPI_NUMBER=1 +CONFIG_ETHERNET_USE_DM9051=n +CONFIG_ETHERNET_USE_KSZ8851SNL=y +CONFIG_ETHERNET_USE_W5500=n diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan867x b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan867x new file mode 100644 index 0000000..905ceff --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan867x @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=n +CONFIG_ETHERNET_PHY_RTL8201=n +CONFIG_ETHERNET_PHY_LAN87XX=n +CONFIG_ETHERNET_PHY_DP83848=n +CONFIG_ETHERNET_PHY_KSZ80XX=n +CONFIG_ETHERNET_PHY_LAN867X=y + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan87xx b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan87xx new file mode 100644 index 0000000..d91800f --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan87xx @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=n +CONFIG_ETHERNET_PHY_RTL8201=n +CONFIG_ETHERNET_PHY_LAN87XX=y +CONFIG_ETHERNET_PHY_DP83848=n +CONFIG_ETHERNET_PHY_KSZ80XX=n +CONFIG_ETHERNET_PHY_LAN867X=n + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.rtl8201 b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.rtl8201 new file mode 100644 index 0000000..6f59d8c --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.rtl8201 @@ -0,0 +1,10 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=y + +CONFIG_ETHERNET_PHY_IP101=n +CONFIG_ETHERNET_PHY_RTL8201=y +CONFIG_ETHERNET_PHY_LAN87XX=n +CONFIG_ETHERNET_PHY_DP83848=n +CONFIG_ETHERNET_PHY_KSZ80XX=n +CONFIG_ETHERNET_PHY_LAN867X=n + +CONFIG_ETHERNET_SPI_SUPPORT=n \ No newline at end of file diff --git a/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.w5500 b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.w5500 new file mode 100644 index 0000000..328743e --- /dev/null +++ b/ethernet_init/examples/simple-ethernet/sdkconfig.defaults.w5500 @@ -0,0 +1,7 @@ +CONFIG_ETHERNET_INTERNAL_SUPPORT=n + +CONFIG_ETHERNET_SPI_SUPPORT=y +CONFIG_ETHERNET_SPI_NUMBER=1 +CONFIG_ETHERNET_USE_DM9051=n +CONFIG_ETHERNET_USE_KSZ8851SNL=n +CONFIG_ETHERNET_USE_W5500=y diff --git a/ethernet_init/idf_component.yml b/ethernet_init/idf_component.yml index b439dee..32771d0 100644 --- a/ethernet_init/idf_component.yml +++ b/ethernet_init/idf_component.yml @@ -1,8 +1,8 @@ dependencies: idf: - version: '>=5.0' + version: '>=5.1' lan867x: override_path: "../lan867x" description: This component initializes Ethernet driver based on Espressif IoT Development Framework Configuration. url: https://github.com/espressif/esp-eth-drivers/tree/master/ethernet_init -version: 0.1.0 +version: 0.1.1