From 3235f18b22a1d27eb822d05fda7cf26662c72b5b Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 14 Dec 2019 16:57:17 +0100 Subject: [PATCH 1/5] cpu/esp32: expose eps_eth netdev for lwIP --- cpu/esp32/esp-eth/esp_eth_netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/esp32/esp-eth/esp_eth_netdev.c b/cpu/esp32/esp-eth/esp_eth_netdev.c index 3d29ae330c..4f112c540b 100644 --- a/cpu/esp32/esp-eth/esp_eth_netdev.c +++ b/cpu/esp32/esp-eth/esp_eth_netdev.c @@ -67,7 +67,7 @@ * not provide an argument that could be used as pointer to the ESP-ETH * device which triggers the interrupt. */ -static esp_eth_netdev_t _esp_eth_dev; +esp_eth_netdev_t _esp_eth_dev; /* device thread stack */ static char _esp_eth_stack[ESP_ETH_STACKSIZE]; From be688f51c6a88c486cdb5aabb47804b5387395ca Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 14 Dec 2019 16:58:35 +0100 Subject: [PATCH 2/5] cpu/esp32: expose esp_eth_setup for lwIP --- cpu/esp32/esp-eth/esp_eth_netdev.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cpu/esp32/esp-eth/esp_eth_netdev.c b/cpu/esp32/esp-eth/esp_eth_netdev.c index 4f112c540b..78a0d0070c 100644 --- a/cpu/esp32/esp-eth/esp_eth_netdev.c +++ b/cpu/esp32/esp-eth/esp_eth_netdev.c @@ -385,8 +385,10 @@ static const netdev_driver_t _esp_eth_driver = extern esp_err_t esp_system_event_add_handler (system_event_cb_t handler, void *arg); -void auto_init_esp_eth (void) +void esp_eth_setup(esp_eth_netdev_t* dev) { + (void)dev; + LOG_TAG_INFO("esp_eth", "initializing ESP32 Ethernet MAC (EMAC) device\n"); /* initialize locking */ @@ -403,11 +405,16 @@ void auto_init_esp_eth (void) _esp_eth_dev.link_up = false; _esp_eth_dev.rx_len = 0; _esp_eth_dev.tx_len = 0; +} + +void auto_init_esp_eth(void) +{ + esp_eth_setup(&_esp_eth_dev); _esp_eth_dev.netif = gnrc_netif_ethernet_create(_esp_eth_stack, - ESP_ETH_STACKSIZE, - ESP_ETH_PRIO, - "netdev-esp-eth", - (netdev_t *)&_esp_eth_dev); + ESP_ETH_STACKSIZE, + ESP_ETH_PRIO, + "esp_eth", + (netdev_t *)&_esp_eth_dev); } #endif /* MODULE_ESP_ETH */ From 2e4e3507bdad9eaa95d772e5a85ef89455936a36 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 14 Dec 2019 16:59:10 +0100 Subject: [PATCH 3/5] cpu/esp32: change netopt in esp_eth for lwIP --- cpu/esp32/esp-eth/esp_eth_netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/esp32/esp-eth/esp_eth_netdev.c b/cpu/esp32/esp-eth/esp_eth_netdev.c index 78a0d0070c..a9c81457b3 100644 --- a/cpu/esp32/esp-eth/esp_eth_netdev.c +++ b/cpu/esp32/esp-eth/esp_eth_netdev.c @@ -280,7 +280,7 @@ static int _esp_eth_get(netdev_t *netdev, netopt_t opt, void *val, size_t max_le switch (opt) { case NETOPT_ADDRESS: - assert(max_len == ETHERNET_ADDR_LEN); + assert(max_len >= ETHERNET_ADDR_LEN); esp_eth_get_mac((uint8_t *)val); return ETHERNET_ADDR_LEN; case NETOPT_LINK_CONNECTED: From 4e003b560882812fc1e37aeda7312f26b88a9471 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 14 Dec 2019 16:59:54 +0100 Subject: [PATCH 4/5] pkg/lwip: add ESP32 esp_eth netdev --- pkg/lwip/contrib/lwip.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/lwip/contrib/lwip.c b/pkg/lwip/contrib/lwip.c index ae142d4192..e0eb0eafac 100644 --- a/pkg/lwip/contrib/lwip.c +++ b/pkg/lwip/contrib/lwip.c @@ -38,6 +38,10 @@ #include "socket_zep_params.h" #endif +#ifdef MODULE_ESP_ETH +#include "esp-eth/esp_eth_netdev.h" +#endif + #ifdef MODULE_ESP_WIFI #include "esp-wifi/esp_wifi_netdev.h" #endif @@ -67,6 +71,10 @@ #define LWIP_NETIF_NUMOF ARRAY_SIZE(socket_zep_params) #endif +#ifdef MODULE_ESP_ETH /* is mutual exclusive with above ifdef */ +#define LWIP_NETIF_NUMOF (1) +#endif + #ifdef MODULE_ESP_WIFI /* is mutual exclusive with above ifdef */ #define LWIP_NETIF_NUMOF (1) #endif @@ -95,6 +103,11 @@ static mrf24j40_t mrf24j40_devs[LWIP_NETIF_NUMOF]; static socket_zep_t socket_zep_devs[LWIP_NETIF_NUMOF]; #endif +#ifdef MODULE_ESP_ETH +extern esp_eth_netdev_t _esp_eth_dev; +extern void esp_eth_setup (esp_eth_netdev_t* dev); +#endif + #ifdef MODULE_ESP_WIFI extern esp_wifi_netdev_t _esp_wifi_dev; extern void esp_wifi_setup (esp_wifi_netdev_t* dev); @@ -145,6 +158,13 @@ void lwip_bootstrap(void) return; } } +#elif defined(MODULE_ESP_ETH) + esp_eth_setup(&_esp_eth_dev); + if (netif_add(&netif[0], &_esp_eth_dev, lwip_netdev_init, + tcpip_input) == NULL) { + DEBUG("Could not add esp_wifi device\n"); + return; + } #elif defined(MODULE_ESP_WIFI) esp_wifi_setup(&_esp_wifi_dev); if (netif_add(&netif[0], &_esp_wifi_dev, lwip_netdev_init, From 91e764a5386cd8d5a245e860993ac1dc9595804e Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 15 Dec 2019 19:11:46 +0100 Subject: [PATCH 5/5] pkg/lwip: add esp_eth for lwIP and IPv4 --- pkg/lwip/contrib/lwip.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/lwip/contrib/lwip.c b/pkg/lwip/contrib/lwip.c index e0eb0eafac..0a3c025137 100644 --- a/pkg/lwip/contrib/lwip.c +++ b/pkg/lwip/contrib/lwip.c @@ -160,11 +160,19 @@ void lwip_bootstrap(void) } #elif defined(MODULE_ESP_ETH) esp_eth_setup(&_esp_eth_dev); - if (netif_add(&netif[0], &_esp_eth_dev, lwip_netdev_init, - tcpip_input) == NULL) { - DEBUG("Could not add esp_wifi device\n"); +#ifdef MODULE_LWIP_IPV4 + if (netif_add(&netif[0], IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, + &_esp_eth_dev, lwip_netdev_init, tcpip_input) == NULL) { + DEBUG("Could not add esp_eth device\n"); return; } +#else /* MODULE_LWIP_IPV4 */ + if (netif_add(&netif[0], &_esp_eth_dev, lwip_netdev_init, + tcpip_input) == NULL) { + DEBUG("Could not add esp_eth device\n"); + return; + } +#endif /* MODULE_LWIP_IPV4 */ #elif defined(MODULE_ESP_WIFI) esp_wifi_setup(&_esp_wifi_dev); if (netif_add(&netif[0], &_esp_wifi_dev, lwip_netdev_init,