From 7e6ff473631c84a1b5f717bea7d807a54d90b245 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 20 Apr 2021 13:48:34 +0200 Subject: [PATCH] Examples: Add basic ethernet example of using ksz8851 --- examples/ethernet/basic/main/Kconfig.projbuild | 8 ++++++++ .../ethernet/basic/main/ethernet_example_main.c | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/ethernet/basic/main/Kconfig.projbuild b/examples/ethernet/basic/main/Kconfig.projbuild index ead8588090..2d01147086 100644 --- a/examples/ethernet/basic/main/Kconfig.projbuild +++ b/examples/ethernet/basic/main/Kconfig.projbuild @@ -32,6 +32,14 @@ menu "Example Configuration" select ETH_SPI_ETHERNET_W5500 help Select external SPI-Ethernet module (W5500). + + config EXAMPLE_USE_KSZ8851SNL + bool "KSZ8851SNL Module" + select EXAMPLE_USE_SPI_ETHERNET + select ETH_USE_SPI_ETHERNET + select ETH_SPI_ETHERNET_KSZ8851SNL + help + Select external SPI-Ethernet module (KSZ8851SNL). endchoice # EXAMPLE_ETHERNET_TYPE if EXAMPLE_USE_INTERNAL_ETHERNET diff --git a/examples/ethernet/basic/main/ethernet_example_main.c b/examples/ethernet/basic/main/ethernet_example_main.c index e448797d14..edcbc6bec5 100644 --- a/examples/ethernet/basic/main/ethernet_example_main.c +++ b/examples/ethernet/basic/main/ethernet_example_main.c @@ -112,7 +112,21 @@ void app_main(void) .quadhd_io_num = -1, }; ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1)); -#if CONFIG_EXAMPLE_USE_DM9051 + +#if CONFIG_EXAMPLE_USE_KSZ8851SNL + spi_device_interface_config_t devcfg = { + .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)); + /* KSZ8851SNL ethernet driver is based on spi driver */ + eth_ksz8851snl_config_t ksz8851snl_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(spi_handle); + ksz8851snl_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config); + esp_eth_phy_t *phy = esp_eth_phy_new_ksz8851snl(&phy_config); +#elif CONFIG_EXAMPLE_USE_DM9051 spi_device_interface_config_t devcfg = { .command_bits = 1, .address_bits = 7,