Skip to content

Commit

Permalink
feat: Added support of SPI Ethernet PHY poll mode to ethernet_init co…
Browse files Browse the repository at this point in the history
…mponent
  • Loading branch information
bogdankolendovskyy committed Mar 8, 2024
1 parent e725fff commit 93368de
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ethernet_init__build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
35 changes: 33 additions & 2 deletions ethernet_init/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
23 changes: 14 additions & 9 deletions ethernet_init/ethernet_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.dp83848
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ip101
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.ksz80xx
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan867x
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.lan87xx
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ethernet_init/examples/simple-ethernet/sdkconfig.defaults.rtl8201
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions ethernet_init/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 93368de

Please sign in to comment.