forked from espressif/esp-idf
eth: support W5500 in network examples
This commit is contained in:
@@ -33,7 +33,7 @@ menu "Example Connection Configuration"
|
|||||||
choice EXAMPLE_USE_ETHERNET
|
choice EXAMPLE_USE_ETHERNET
|
||||||
prompt "Ethernet Type"
|
prompt "Ethernet Type"
|
||||||
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
||||||
default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32
|
default EXAMPLE_USE_W5500
|
||||||
help
|
help
|
||||||
Select which kind of Ethernet will be used in the example.
|
Select which kind of Ethernet will be used in the example.
|
||||||
|
|
||||||
@@ -51,6 +51,13 @@ menu "Example Connection Configuration"
|
|||||||
help
|
help
|
||||||
Select external SPI-Ethernet module.
|
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
|
config EXAMPLE_USE_OPENETH
|
||||||
bool "OpenCores Ethernet MAC (EXPERIMENTAL)"
|
bool "OpenCores Ethernet MAC (EXPERIMENTAL)"
|
||||||
select ETH_USE_OPENETH
|
select ETH_USE_OPENETH
|
||||||
@@ -108,55 +115,55 @@ menu "Example Connection Configuration"
|
|||||||
Set the GPIO number used by SMI MDIO.
|
Set the GPIO number used by SMI MDIO.
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if EXAMPLE_USE_DM9051
|
if ETH_USE_SPI_ETHERNET
|
||||||
config EXAMPLE_DM9051_SPI_HOST
|
config EXAMPLE_ETH_SPI_HOST
|
||||||
int "SPI Host Number"
|
int "SPI Host Number"
|
||||||
range 0 2
|
range 0 2
|
||||||
default 1
|
default 1
|
||||||
help
|
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"
|
int "SPI SCLK GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 19
|
default 20
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI SCLK.
|
Set the GPIO number used by SPI SCLK.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MOSI_GPIO
|
config EXAMPLE_ETH_SPI_MOSI_GPIO
|
||||||
int "SPI MOSI GPIO number"
|
int "SPI MOSI GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 23
|
default 19
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MOSI.
|
Set the GPIO number used by SPI MOSI.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MISO_GPIO
|
config EXAMPLE_ETH_SPI_MISO_GPIO
|
||||||
int "SPI MISO GPIO number"
|
int "SPI MISO GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 25
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MISO.
|
Set the GPIO number used by SPI MISO.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_CS_GPIO
|
config EXAMPLE_ETH_SPI_CS_GPIO
|
||||||
int "SPI CS GPIO number"
|
int "SPI CS GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 22
|
default 21
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI CS.
|
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)"
|
int "SPI clock speed (MHz)"
|
||||||
range 20 80
|
range 20 80
|
||||||
default 20
|
default 36
|
||||||
help
|
help
|
||||||
Set the clock speed (MHz) of SPI interface.
|
Set the clock speed (MHz) of SPI interface.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_INT_GPIO
|
config EXAMPLE_ETH_SPI_INT_GPIO
|
||||||
int "Interrupt GPIO number"
|
int "Interrupt GPIO number"
|
||||||
default 4
|
default 4
|
||||||
help
|
help
|
||||||
Set the GPIO number used by DM9051 interrupt.
|
Set the GPIO number used by the SPI Ethernet module interrupt line.
|
||||||
endif
|
endif # ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
config EXAMPLE_ETH_PHY_RST_GPIO
|
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||||
int "PHY Reset GPIO number"
|
int "PHY Reset GPIO number"
|
||||||
@@ -168,7 +175,6 @@ menu "Example Connection Configuration"
|
|||||||
config EXAMPLE_ETH_PHY_ADDR
|
config EXAMPLE_ETH_PHY_ADDR
|
||||||
int "PHY Address"
|
int "PHY Address"
|
||||||
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET
|
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set PHY address according your board schematic.
|
Set PHY address according your board schematic.
|
||||||
|
@@ -15,7 +15,10 @@
|
|||||||
#include "esp_wifi_default.h"
|
#include "esp_wifi_default.h"
|
||||||
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
|
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||||
#include "esp_eth.h"
|
#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_log.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
@@ -359,31 +362,48 @@ static esp_netif_t* eth_start(void)
|
|||||||
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
||||||
s_phy = esp_eth_phy_new_dp83848(&phy_config);
|
s_phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
#elif CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
gpio_install_isr_service(0);
|
gpio_install_isr_service(0);
|
||||||
spi_device_handle_t spi_handle = NULL;
|
spi_device_handle_t spi_handle = NULL;
|
||||||
spi_bus_config_t buscfg = {
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = CONFIG_EXAMPLE_DM9051_MISO_GPIO,
|
.miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
|
||||||
.mosi_io_num = CONFIG_EXAMPLE_DM9051_MOSI_GPIO,
|
.mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
|
||||||
.sclk_io_num = CONFIG_EXAMPLE_DM9051_SCLK_GPIO,
|
.sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_DM9051_SPI_HOST, &buscfg, 1));
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
|
||||||
|
#if CONFIG_EXAMPLE_USE_DM9051
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.clock_speed_hz = CONFIG_EXAMPLE_DM9051_SPI_CLOCK_MHZ * 1000 * 1000,
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
.spics_io_num = CONFIG_EXAMPLE_DM9051_CS_GPIO,
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
.queue_size = 20
|
.queue_size = 20
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_DM9051_SPI_HOST, &devcfg, &spi_handle));
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
/* dm9051 ethernet driver is based on spi driver */
|
/* dm9051 ethernet driver is based on spi driver */
|
||||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_DM9051_INT_GPIO;
|
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
s_phy = esp_eth_phy_new_dm9051(&phy_config);
|
s_phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_USE_W5500
|
||||||
|
spi_device_interface_config_t devcfg = {
|
||||||
|
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
||||||
|
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
||||||
|
.mode = 0,
|
||||||
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
|
.queue_size = 20
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
|
/* w5500 ethernet driver is based on spi driver */
|
||||||
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
|
w5500_config.int_gpio_num = 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
|
||||||
#elif CONFIG_EXAMPLE_USE_OPENETH
|
#elif CONFIG_EXAMPLE_USE_OPENETH
|
||||||
phy_config.autonego_timeout_ms = 100;
|
phy_config.autonego_timeout_ms = 100;
|
||||||
s_mac = esp_eth_mac_new_openeth(&mac_config);
|
s_mac = esp_eth_mac_new_openeth(&mac_config);
|
||||||
@@ -393,6 +413,14 @@ static esp_netif_t* eth_start(void)
|
|||||||
// Install Ethernet driver
|
// Install Ethernet driver
|
||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(s_mac, s_phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(s_mac, s_phy);
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle));
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle));
|
||||||
|
#if !CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we cat to set it manually.
|
||||||
|
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
|
||||||
|
*/
|
||||||
|
ESP_ERROR_CHECK(esp_eth_ioctl(s_eth_handle, ETH_CMD_S_MAC_ADDR, (uint8_t[]) {
|
||||||
|
0x02, 0x00, 0x00, 0x12, 0x34, 0x56
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
// combine driver with netif
|
// combine driver with netif
|
||||||
s_eth_glue = esp_eth_new_netif_glue(s_eth_handle);
|
s_eth_glue = esp_eth_new_netif_glue(s_eth_handle);
|
||||||
esp_netif_attach(netif, s_eth_glue);
|
esp_netif_attach(netif, s_eth_glue);
|
||||||
|
@@ -2,7 +2,7 @@ menu "Example Configuration"
|
|||||||
choice EXAMPLE_USE_ETHERNET
|
choice EXAMPLE_USE_ETHERNET
|
||||||
prompt "Ethernet Type"
|
prompt "Ethernet Type"
|
||||||
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
||||||
default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32
|
default EXAMPLE_USE_W5500
|
||||||
help
|
help
|
||||||
Select which kind of Ethernet will be used in the example.
|
Select which kind of Ethernet will be used in the example.
|
||||||
|
|
||||||
@@ -20,7 +20,13 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
Select external SPI-Ethernet module (DM9051).
|
Select external SPI-Ethernet module (DM9051).
|
||||||
|
|
||||||
endchoice
|
config EXAMPLE_USE_W5500
|
||||||
|
bool "W5500 Module"
|
||||||
|
select ETH_USE_SPI_ETHERNET
|
||||||
|
select ETH_SPI_ETHERNET_W5500
|
||||||
|
help
|
||||||
|
Select external SPI-Ethernet module (W5500).
|
||||||
|
endchoice # EXAMPLE_USE_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_INTERNAL_ETHERNET
|
if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
choice EXAMPLE_ETH_PHY_MODEL
|
choice EXAMPLE_ETH_PHY_MODEL
|
||||||
@@ -58,7 +64,7 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver.
|
The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver.
|
||||||
Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it.
|
Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it.
|
||||||
endchoice
|
endchoice # EXAMPLE_ETH_PHY_MODEL
|
||||||
|
|
||||||
config EXAMPLE_ETH_MDC_GPIO
|
config EXAMPLE_ETH_MDC_GPIO
|
||||||
int "SMI MDC GPIO number"
|
int "SMI MDC GPIO number"
|
||||||
@@ -71,57 +77,57 @@ menu "Example Configuration"
|
|||||||
default 18
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SMI MDIO.
|
Set the GPIO number used by SMI MDIO.
|
||||||
endif
|
endif # EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_DM9051
|
if ETH_USE_SPI_ETHERNET
|
||||||
config EXAMPLE_DM9051_SPI_HOST
|
config EXAMPLE_ETH_SPI_HOST
|
||||||
int "SPI Host Number"
|
int "SPI Host Number"
|
||||||
range 0 2
|
range 0 2
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set the SPI host used to communicate with the SPI Ethernet Controller.
|
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"
|
int "SPI SCLK GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 19
|
default 20
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI SCLK.
|
Set the GPIO number used by SPI SCLK.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MOSI_GPIO
|
config EXAMPLE_ETH_SPI_MOSI_GPIO
|
||||||
int "SPI MOSI GPIO number"
|
int "SPI MOSI GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 23
|
default 19
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MOSI.
|
Set the GPIO number used by SPI MOSI.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MISO_GPIO
|
config EXAMPLE_ETH_SPI_MISO_GPIO
|
||||||
int "SPI MISO GPIO number"
|
int "SPI MISO GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 25
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MISO.
|
Set the GPIO number used by SPI MISO.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_CS_GPIO
|
config EXAMPLE_ETH_SPI_CS_GPIO
|
||||||
int "SPI CS GPIO number"
|
int "SPI CS GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 22
|
default 21
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI CS.
|
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)"
|
int "SPI clock speed (MHz)"
|
||||||
range 5 80
|
range 5 80
|
||||||
default 20
|
default 36
|
||||||
help
|
help
|
||||||
Set the clock speed (MHz) of SPI interface.
|
Set the clock speed (MHz) of SPI interface.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_INT_GPIO
|
config EXAMPLE_ETH_SPI_INT_GPIO
|
||||||
int "Interrupt GPIO number"
|
int "Interrupt GPIO number"
|
||||||
default 4
|
default 4
|
||||||
help
|
help
|
||||||
Set the GPIO number used by DM9051 interrupt.
|
Set the GPIO number used by the SPI Ethernet module interrupt line.
|
||||||
endif
|
endif # ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
config EXAMPLE_ETH_PHY_RST_GPIO
|
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||||
int "PHY Reset GPIO number"
|
int "PHY Reset GPIO number"
|
||||||
@@ -132,8 +138,7 @@ menu "Example Configuration"
|
|||||||
|
|
||||||
config EXAMPLE_ETH_PHY_ADDR
|
config EXAMPLE_ETH_PHY_ADDR
|
||||||
int "PHY Address"
|
int "PHY Address"
|
||||||
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
range 0 31
|
||||||
range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET
|
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set PHY address according your board schematic.
|
Set PHY address according your board schematic.
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
static const char *TAG = "eth_example";
|
static const char *TAG = "eth_example";
|
||||||
|
|
||||||
@@ -96,35 +99,60 @@ void app_main(void)
|
|||||||
#elif CONFIG_EXAMPLE_ETH_PHY_KSZ8041
|
#elif CONFIG_EXAMPLE_ETH_PHY_KSZ8041
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
#elif CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
gpio_install_isr_service(0);
|
gpio_install_isr_service(0);
|
||||||
spi_device_handle_t spi_handle = NULL;
|
spi_device_handle_t spi_handle = NULL;
|
||||||
spi_bus_config_t buscfg = {
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = CONFIG_EXAMPLE_DM9051_MISO_GPIO,
|
.miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
|
||||||
.mosi_io_num = CONFIG_EXAMPLE_DM9051_MOSI_GPIO,
|
.mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
|
||||||
.sclk_io_num = CONFIG_EXAMPLE_DM9051_SCLK_GPIO,
|
.sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_DM9051_SPI_HOST, &buscfg, 1));
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
|
||||||
|
#if CONFIG_EXAMPLE_USE_DM9051
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.clock_speed_hz = CONFIG_EXAMPLE_DM9051_SPI_CLOCK_MHZ * 1000 * 1000,
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
.spics_io_num = CONFIG_EXAMPLE_DM9051_CS_GPIO,
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
.queue_size = 20
|
.queue_size = 20
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_DM9051_SPI_HOST, &devcfg, &spi_handle));
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
/* dm9051 ethernet driver is based on spi driver */
|
/* dm9051 ethernet driver is based on spi driver */
|
||||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_DM9051_INT_GPIO;
|
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_USE_W5500
|
||||||
|
spi_device_interface_config_t devcfg = {
|
||||||
|
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
||||||
|
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
||||||
|
.mode = 0,
|
||||||
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
|
.queue_size = 20
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
|
/* w5500 ethernet driver is based on spi driver */
|
||||||
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
|
w5500_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
|
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||||
|
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||||
esp_eth_handle_t eth_handle = NULL;
|
esp_eth_handle_t eth_handle = NULL;
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||||
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we cat to set it manually.
|
||||||
|
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
|
||||||
|
*/
|
||||||
|
ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, (uint8_t[]) {
|
||||||
|
0x02, 0x00, 0x00, 0x12, 0x34, 0x56
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
/* attach Ethernet driver to TCP/IP stack */
|
/* attach Ethernet driver to TCP/IP stack */
|
||||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
||||||
/* start Ethernet driver state machine */
|
/* start Ethernet driver state machine */
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "enc28j60.h"
|
#include "enc28j60.h"
|
||||||
#include "sdkconfig.h"
|
#include "driver/spi_master.h"
|
||||||
|
|
||||||
static const char *TAG = "eth_example";
|
static const char *TAG = "eth_example";
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ menu "Example Configuration"
|
|||||||
choice EXAMPLE_USE_ETHERNET
|
choice EXAMPLE_USE_ETHERNET
|
||||||
prompt "Ethernet Type"
|
prompt "Ethernet Type"
|
||||||
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
||||||
default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32
|
default EXAMPLE_USE_W5500
|
||||||
help
|
help
|
||||||
Select which kind of Ethernet will be used in the example.
|
Select which kind of Ethernet will be used in the example.
|
||||||
|
|
||||||
@@ -18,8 +18,15 @@ menu "Example Configuration"
|
|||||||
select ETH_USE_SPI_ETHERNET
|
select ETH_USE_SPI_ETHERNET
|
||||||
select ETH_SPI_ETHERNET_DM9051
|
select ETH_SPI_ETHERNET_DM9051
|
||||||
help
|
help
|
||||||
Select external SPI-Ethernet module.
|
Select external SPI-Ethernet module (DM9051).
|
||||||
endchoice
|
|
||||||
|
config EXAMPLE_USE_W5500
|
||||||
|
bool "W5500 Module"
|
||||||
|
select ETH_USE_SPI_ETHERNET
|
||||||
|
select ETH_SPI_ETHERNET_W5500
|
||||||
|
help
|
||||||
|
Select external SPI-Ethernet module (W5500).
|
||||||
|
endchoice # EXAMPLE_USE_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_INTERNAL_ETHERNET
|
if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
choice EXAMPLE_ETH_PHY_MODEL
|
choice EXAMPLE_ETH_PHY_MODEL
|
||||||
@@ -51,7 +58,13 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
||||||
Goto http://www.ti.com/product/DP83848J for more information about it.
|
Goto http://www.ti.com/product/DP83848J for more information about it.
|
||||||
endchoice
|
|
||||||
|
config EXAMPLE_ETH_PHY_KSZ8041
|
||||||
|
bool "KSZ8041"
|
||||||
|
help
|
||||||
|
The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver.
|
||||||
|
Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it.
|
||||||
|
endchoice # EXAMPLE_ETH_PHY_MODEL
|
||||||
|
|
||||||
config EXAMPLE_ETH_MDC_GPIO
|
config EXAMPLE_ETH_MDC_GPIO
|
||||||
int "SMI MDC GPIO number"
|
int "SMI MDC GPIO number"
|
||||||
@@ -64,57 +77,57 @@ menu "Example Configuration"
|
|||||||
default 18
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SMI MDIO.
|
Set the GPIO number used by SMI MDIO.
|
||||||
endif
|
endif # EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_DM9051
|
if ETH_USE_SPI_ETHERNET
|
||||||
config EXAMPLE_DM9051_SPI_HOST
|
config EXAMPLE_ETH_SPI_HOST
|
||||||
int "SPI Host Number"
|
int "SPI Host Number"
|
||||||
range 0 2
|
range 0 2
|
||||||
default 1
|
default 1
|
||||||
help
|
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"
|
int "SPI SCLK GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 19
|
default 20
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI SCLK.
|
Set the GPIO number used by SPI SCLK.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MOSI_GPIO
|
config EXAMPLE_ETH_SPI_MOSI_GPIO
|
||||||
int "SPI MOSI GPIO number"
|
int "SPI MOSI GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 23
|
default 19
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MOSI.
|
Set the GPIO number used by SPI MOSI.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MISO_GPIO
|
config EXAMPLE_ETH_SPI_MISO_GPIO
|
||||||
int "SPI MISO GPIO number"
|
int "SPI MISO GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 25
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MISO.
|
Set the GPIO number used by SPI MISO.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_CS_GPIO
|
config EXAMPLE_ETH_SPI_CS_GPIO
|
||||||
int "SPI CS GPIO number"
|
int "SPI CS GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 22
|
default 21
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI CS.
|
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)"
|
int "SPI clock speed (MHz)"
|
||||||
range 20 80
|
range 5 80
|
||||||
default 20
|
default 36
|
||||||
help
|
help
|
||||||
Set the clock speed (MHz) of SPI interface.
|
Set the clock speed (MHz) of SPI interface.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_INT_GPIO
|
config EXAMPLE_ETH_SPI_INT_GPIO
|
||||||
int "Interrupt GPIO number"
|
int "Interrupt GPIO number"
|
||||||
default 4
|
default 4
|
||||||
help
|
help
|
||||||
Set the GPIO number used by DM9051 interrupt.
|
Set the GPIO number used by the SPI Ethernet module interrupt line.
|
||||||
endif
|
endif # ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
config EXAMPLE_ETH_PHY_RST_GPIO
|
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||||
int "PHY Reset GPIO number"
|
int "PHY Reset GPIO number"
|
||||||
@@ -125,8 +138,7 @@ menu "Example Configuration"
|
|||||||
|
|
||||||
config EXAMPLE_ETH_PHY_ADDR
|
config EXAMPLE_ETH_PHY_ADDR
|
||||||
int "PHY Address"
|
int "PHY Address"
|
||||||
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
range 0 31
|
||||||
range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET
|
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set PHY address according your board schematic.
|
Set PHY address according your board schematic.
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
@@ -18,7 +19,9 @@
|
|||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "esp_private/wifi.h"
|
#include "esp_private/wifi.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "sdkconfig.h"
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char *TAG = "eth_example";
|
static const char *TAG = "eth_example";
|
||||||
static esp_eth_handle_t s_eth_handle = NULL;
|
static esp_eth_handle_t s_eth_handle = NULL;
|
||||||
@@ -166,36 +169,63 @@ static void initialize_ethernet(void)
|
|||||||
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
||||||
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_ETH_PHY_KSZ8041
|
||||||
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
#elif CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
gpio_install_isr_service(0);
|
gpio_install_isr_service(0);
|
||||||
spi_device_handle_t spi_handle = NULL;
|
spi_device_handle_t spi_handle = NULL;
|
||||||
spi_bus_config_t buscfg = {
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = CONFIG_EXAMPLE_DM9051_MISO_GPIO,
|
.miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
|
||||||
.mosi_io_num = CONFIG_EXAMPLE_DM9051_MOSI_GPIO,
|
.mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
|
||||||
.sclk_io_num = CONFIG_EXAMPLE_DM9051_SCLK_GPIO,
|
.sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_DM9051_SPI_HOST, &buscfg, 1));
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
|
||||||
|
#if CONFIG_EXAMPLE_USE_DM9051
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.clock_speed_hz = CONFIG_EXAMPLE_DM9051_SPI_CLOCK_MHZ * 1000 * 1000,
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
.spics_io_num = CONFIG_EXAMPLE_DM9051_CS_GPIO,
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
.queue_size = 20
|
.queue_size = 20
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_DM9051_SPI_HOST, &devcfg, &spi_handle));
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
/* dm9051 ethernet driver is based on spi driver */
|
/* dm9051 ethernet driver is based on spi driver */
|
||||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_DM9051_INT_GPIO;
|
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_USE_W5500
|
||||||
|
spi_device_interface_config_t devcfg = {
|
||||||
|
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
||||||
|
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
||||||
|
.mode = 0,
|
||||||
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
|
.queue_size = 20
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
|
/* w5500 ethernet driver is based on spi driver */
|
||||||
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
|
w5500_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
|
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||||
|
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||||
config.stack_input = pkt_eth2wifi;
|
config.stack_input = pkt_eth2wifi;
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle));
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle));
|
||||||
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we cat to set it manually.
|
||||||
|
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
|
||||||
|
*/
|
||||||
|
ESP_ERROR_CHECK(esp_eth_ioctl(s_eth_handle, ETH_CMD_S_MAC_ADDR, (uint8_t[]) {
|
||||||
|
0x02, 0x00, 0x00, 0x12, 0x34, 0x56
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
esp_eth_ioctl(s_eth_handle, ETH_CMD_S_PROMISCUOUS, (void *)true);
|
esp_eth_ioctl(s_eth_handle, ETH_CMD_S_PROMISCUOUS, (void *)true);
|
||||||
esp_eth_start(s_eth_handle);
|
esp_eth_start(s_eth_handle);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ menu "Example Configuration"
|
|||||||
choice EXAMPLE_USE_ETHERNET
|
choice EXAMPLE_USE_ETHERNET
|
||||||
prompt "Ethernet Type"
|
prompt "Ethernet Type"
|
||||||
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
||||||
default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32
|
default EXAMPLE_USE_W5500
|
||||||
help
|
help
|
||||||
Select which kind of Ethernet will be used in the example.
|
Select which kind of Ethernet will be used in the example.
|
||||||
|
|
||||||
@@ -26,8 +26,15 @@ menu "Example Configuration"
|
|||||||
select ETH_USE_SPI_ETHERNET
|
select ETH_USE_SPI_ETHERNET
|
||||||
select ETH_SPI_ETHERNET_DM9051
|
select ETH_SPI_ETHERNET_DM9051
|
||||||
help
|
help
|
||||||
Select external SPI-Ethernet module.
|
Select external SPI-Ethernet module (DM9051).
|
||||||
endchoice
|
|
||||||
|
config EXAMPLE_USE_W5500
|
||||||
|
bool "W5500 Module"
|
||||||
|
select ETH_USE_SPI_ETHERNET
|
||||||
|
select ETH_SPI_ETHERNET_W5500
|
||||||
|
help
|
||||||
|
Select external SPI-Ethernet module (W5500).
|
||||||
|
endchoice # EXAMPLE_USE_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_INTERNAL_ETHERNET
|
if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
choice EXAMPLE_ETH_PHY_MODEL
|
choice EXAMPLE_ETH_PHY_MODEL
|
||||||
@@ -59,7 +66,13 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
||||||
Goto http://www.ti.com/product/DP83848J for more information about it.
|
Goto http://www.ti.com/product/DP83848J for more information about it.
|
||||||
endchoice
|
|
||||||
|
config EXAMPLE_ETH_PHY_KSZ8041
|
||||||
|
bool "KSZ8041"
|
||||||
|
help
|
||||||
|
The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver.
|
||||||
|
Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it.
|
||||||
|
endchoice # EXAMPLE_ETH_PHY_MODEL
|
||||||
|
|
||||||
config EXAMPLE_ETH_MDC_GPIO
|
config EXAMPLE_ETH_MDC_GPIO
|
||||||
int "SMI MDC GPIO number"
|
int "SMI MDC GPIO number"
|
||||||
@@ -72,57 +85,57 @@ menu "Example Configuration"
|
|||||||
default 18
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SMI MDIO.
|
Set the GPIO number used by SMI MDIO.
|
||||||
endif
|
endif # EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
|
||||||
if EXAMPLE_USE_DM9051
|
if ETH_USE_SPI_ETHERNET
|
||||||
config EXAMPLE_DM9051_SPI_HOST
|
config EXAMPLE_ETH_SPI_HOST
|
||||||
int "SPI Host Number"
|
int "SPI Host Number"
|
||||||
range 0 2
|
range 0 2
|
||||||
default 1
|
default 1
|
||||||
help
|
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"
|
int "SPI SCLK GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 19
|
default 20
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI SCLK.
|
Set the GPIO number used by SPI SCLK.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MOSI_GPIO
|
config EXAMPLE_ETH_SPI_MOSI_GPIO
|
||||||
int "SPI MOSI GPIO number"
|
int "SPI MOSI GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 23
|
default 19
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MOSI.
|
Set the GPIO number used by SPI MOSI.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_MISO_GPIO
|
config EXAMPLE_ETH_SPI_MISO_GPIO
|
||||||
int "SPI MISO GPIO number"
|
int "SPI MISO GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 25
|
default 18
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MISO.
|
Set the GPIO number used by SPI MISO.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_CS_GPIO
|
config EXAMPLE_ETH_SPI_CS_GPIO
|
||||||
int "SPI CS GPIO number"
|
int "SPI CS GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 22
|
default 21
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI CS.
|
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)"
|
int "SPI clock speed (MHz)"
|
||||||
range 20 80
|
range 5 80
|
||||||
default 20
|
default 36
|
||||||
help
|
help
|
||||||
Set the clock speed (MHz) of SPI interface.
|
Set the clock speed (MHz) of SPI interface.
|
||||||
|
|
||||||
config EXAMPLE_DM9051_INT_GPIO
|
config EXAMPLE_ETH_SPI_INT_GPIO
|
||||||
int "Interrupt GPIO number"
|
int "Interrupt GPIO number"
|
||||||
default 4
|
default 4
|
||||||
help
|
help
|
||||||
Set the GPIO number used by DM9051 interrupt.
|
Set the GPIO number used by the SPI Ethernet module interrupt line.
|
||||||
endif
|
endif # ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
config EXAMPLE_ETH_PHY_RST_GPIO
|
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||||
int "PHY Reset GPIO number"
|
int "PHY Reset GPIO number"
|
||||||
@@ -133,8 +146,7 @@ menu "Example Configuration"
|
|||||||
|
|
||||||
config EXAMPLE_ETH_PHY_ADDR
|
config EXAMPLE_ETH_PHY_ADDR
|
||||||
int "PHY Address"
|
int "PHY Address"
|
||||||
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
range 0 31
|
||||||
range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET
|
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set PHY address according your board schematic.
|
Set PHY address according your board schematic.
|
||||||
|
@@ -19,6 +19,9 @@
|
|||||||
#include "argtable3/argtable3.h"
|
#include "argtable3/argtable3.h"
|
||||||
#include "iperf.h"
|
#include "iperf.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
|
||||||
static esp_netif_ip_info_t ip;
|
static esp_netif_ip_info_t ip;
|
||||||
static bool started = false;
|
static bool started = false;
|
||||||
@@ -202,35 +205,62 @@ void register_ethernet(void)
|
|||||||
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
||||||
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_ETH_PHY_KSZ8041
|
||||||
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
#elif CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
gpio_install_isr_service(0);
|
gpio_install_isr_service(0);
|
||||||
spi_device_handle_t spi_handle = NULL;
|
spi_device_handle_t spi_handle = NULL;
|
||||||
spi_bus_config_t buscfg = {
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = CONFIG_EXAMPLE_DM9051_MISO_GPIO,
|
.miso_io_num = CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
|
||||||
.mosi_io_num = CONFIG_EXAMPLE_DM9051_MOSI_GPIO,
|
.mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
|
||||||
.sclk_io_num = CONFIG_EXAMPLE_DM9051_SCLK_GPIO,
|
.sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_DM9051_SPI_HOST, &buscfg, 1));
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
|
||||||
|
#if CONFIG_EXAMPLE_USE_DM9051
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.clock_speed_hz = CONFIG_EXAMPLE_DM9051_SPI_CLOCK_MHZ * 1000 * 1000,
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
.spics_io_num = CONFIG_EXAMPLE_DM9051_CS_GPIO,
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
.queue_size = 20
|
.queue_size = 20
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_DM9051_SPI_HOST, &devcfg, &spi_handle));
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
/* dm9051 ethernet driver is based on spi driver */
|
/* dm9051 ethernet driver is based on spi driver */
|
||||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_DM9051_INT_GPIO;
|
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
|
#elif CONFIG_EXAMPLE_USE_W5500
|
||||||
|
spi_device_interface_config_t devcfg = {
|
||||||
|
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
||||||
|
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
||||||
|
.mode = 0,
|
||||||
|
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
|
.spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO,
|
||||||
|
.queue_size = 20
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
||||||
|
/* w5500 ethernet driver is based on spi driver */
|
||||||
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
|
w5500_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO;
|
||||||
|
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||||
|
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||||
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
||||||
|
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we cat to set it manually.
|
||||||
|
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
|
||||||
|
*/
|
||||||
|
ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, (uint8_t[]) {
|
||||||
|
0x02, 0x00, 0x00, 0x12, 0x34, 0x56
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
||||||
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user