From d5566971fb4f825160730fd8f6e6f1ddb6291f77 Mon Sep 17 00:00:00 2001 From: morris Date: Fri, 6 Nov 2020 16:06:20 +0800 Subject: [PATCH] eth: support W5500 in network examples * Original commit: espressif/esp-idf@aea901f014ac05c41664dd1e3ba9bbd2301a0aba --- .../Kconfig.projbuild | 42 ++++++----- .../protocol_examples_common/connect.c | 72 +++++++++++++------ 2 files changed, 74 insertions(+), 40 deletions(-) diff --git a/examples/common_components/protocol_examples_common/Kconfig.projbuild b/examples/common_components/protocol_examples_common/Kconfig.projbuild index ed7f51c59..56a6f9c95 100644 --- a/examples/common_components/protocol_examples_common/Kconfig.projbuild +++ b/examples/common_components/protocol_examples_common/Kconfig.projbuild @@ -33,7 +33,7 @@ menu "Example Connection Configuration" choice EXAMPLE_USE_ETHERNET prompt "Ethernet Type" default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32 - default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32 + default EXAMPLE_USE_W5500 help Select which kind of Ethernet will be used in the example. @@ -51,6 +51,13 @@ menu "Example Connection Configuration" help Select external SPI-Ethernet module. + config EXAMPLE_USE_W5500 + bool "W5500 Module" + select ETH_USE_SPI_ETHERNET + select ETH_SPI_ETHERNET_W5500 + help + Select external SPI-Ethernet module (W5500). + config EXAMPLE_USE_OPENETH bool "OpenCores Ethernet MAC (EXPERIMENTAL)" select ETH_USE_OPENETH @@ -108,55 +115,55 @@ menu "Example Connection Configuration" Set the GPIO number used by SMI MDIO. endif - if EXAMPLE_USE_DM9051 - config EXAMPLE_DM9051_SPI_HOST + if ETH_USE_SPI_ETHERNET + config EXAMPLE_ETH_SPI_HOST int "SPI Host Number" range 0 2 default 1 help - Set the SPI host used to communicate with DM9051. + Set the SPI host used to communicate with the SPI Ethernet Controller. - config EXAMPLE_DM9051_SCLK_GPIO + config EXAMPLE_ETH_SPI_SCLK_GPIO int "SPI SCLK GPIO number" range 0 33 - default 19 + default 20 help Set the GPIO number used by SPI SCLK. - config EXAMPLE_DM9051_MOSI_GPIO + config EXAMPLE_ETH_SPI_MOSI_GPIO int "SPI MOSI GPIO number" range 0 33 - default 23 + default 19 help Set the GPIO number used by SPI MOSI. - config EXAMPLE_DM9051_MISO_GPIO + config EXAMPLE_ETH_SPI_MISO_GPIO int "SPI MISO GPIO number" range 0 33 - default 25 + default 18 help Set the GPIO number used by SPI MISO. - config EXAMPLE_DM9051_CS_GPIO + config EXAMPLE_ETH_SPI_CS_GPIO int "SPI CS GPIO number" range 0 33 - default 22 + default 21 help Set the GPIO number used by SPI CS. - config EXAMPLE_DM9051_SPI_CLOCK_MHZ + config EXAMPLE_ETH_SPI_CLOCK_MHZ int "SPI clock speed (MHz)" range 20 80 - default 20 + default 36 help Set the clock speed (MHz) of SPI interface. - config EXAMPLE_DM9051_INT_GPIO + config EXAMPLE_ETH_SPI_INT_GPIO int "Interrupt GPIO number" default 4 help - Set the GPIO number used by DM9051 interrupt. - endif + Set the GPIO number used by the SPI Ethernet module interrupt line. + endif # ETH_USE_SPI_ETHERNET config EXAMPLE_ETH_PHY_RST_GPIO int "PHY Reset GPIO number" @@ -168,7 +175,6 @@ menu "Example Connection Configuration" config EXAMPLE_ETH_PHY_ADDR int "PHY Address" range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET - range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET default 1 help Set PHY address according your board schematic. diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index 6ef826f42..2449ab940 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -15,7 +15,10 @@ #include "esp_wifi_default.h" #if CONFIG_EXAMPLE_CONNECT_ETHERNET #include "esp_eth.h" -#endif +#if CONFIG_ETH_USE_SPI_ETHERNET +#include "driver/spi_master.h" +#endif // CONFIG_ETH_USE_SPI_ETHERNET +#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET #include "esp_log.h" #include "esp_netif.h" #include "driver/gpio.h" @@ -60,17 +63,17 @@ static const char *s_ipv6_addr_types[] = { "ESP_IP6_ADDR_IS_SITE_LOCAL", "ESP_IP6_ADDR_IS_UNIQUE_LOCAL", "ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6" - }; +}; #endif static const char *TAG = "example_connect"; #if CONFIG_EXAMPLE_CONNECT_WIFI -static esp_netif_t* wifi_start(void); +static esp_netif_t *wifi_start(void); static void wifi_stop(void); #endif #if CONFIG_EXAMPLE_CONNECT_ETHERNET -static esp_netif_t* eth_start(void); +static esp_netif_t *eth_start(void); static void eth_stop(void); #endif @@ -81,7 +84,7 @@ static void eth_stop(void); */ static bool is_our_netif(const char *prefix, esp_netif_t *netif) { - return strncmp(prefix, esp_netif_get_desc(netif), strlen(prefix)-1) == 0; + return strncmp(prefix, esp_netif_get_desc(netif), strlen(prefix) - 1) == 0; } /* set up connection, Wi-Fi and/or Ethernet */ @@ -153,7 +156,7 @@ static void on_got_ipv6(void *arg, esp_event_base_t event_base, } esp_ip6_addr_type_t ipv6_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip); ESP_LOGI(TAG, "Got IPv6 event: Interface \"%s\" address: " IPV6STR ", type: %s", esp_netif_get_desc(event->esp_netif), - IPV62STR(event->ip6_info.ip), s_ipv6_addr_types[ipv6_type]); + IPV62STR(event->ip6_info.ip), s_ipv6_addr_types[ipv6_type]); if (ipv6_type == EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE) { memcpy(&s_ipv6_addr, &event->ip6_info.ip, sizeof(s_ipv6_addr)); xSemaphoreGive(s_semph_get_ip_addrs); @@ -172,13 +175,13 @@ esp_err_t example_connect(void) start(); ESP_ERROR_CHECK(esp_register_shutdown_handler(&stop)); ESP_LOGI(TAG, "Waiting for IP(s)"); - for (int i=0; i