esp_eth_ioctl() API had the following issues:
The third parameter (which is of type
void *) would accept an
booltype arguments (i.e., not pointers) as input in some cases. However, these cases were not documented properly.
booltype argument as the third parameter, the argument had to be “unnaturally” casted to a
void *type, to prevent a compiler warning as demonstrated in the code snippet below. This casting could lead to misuse of the
esp_eth_ioctl(eth_handle, ETH_CMD_S_FLOW_CTRL, (void *)true);
Therefore, the usage of
esp_eth_ioctl() is now unified. Arguments to the third parameter must be passed as pointers to a specific data type to/from where data will be stored/read by
esp_eth_ioctl(). The code snippets below demonstrate the usage of
Usage example to set Ethernet configuration:
eth_duplex_t new_duplex_mode = ETH_DUPLEX_HALF; esp_eth_ioctl(eth_handle, ETH_CMD_S_DUPLEX_MODE, &new_duplex_mode);
Usage example to get Ethernet configuration:
eth_duplex_t duplex_mode; esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
KSZ8041/81 and LAN8720 Driver Update
The KSZ8041/81 and LAN8720 drivers are updated to support more devices (i.e., generations) from their associated product families. The drivers can recognize particular chip numbers and their potential support by the driver.
As a result, the specific “chip number” functions calls are replaced by generic ones as follows:
ESP NETIF Glue Event Handlers
esp_eth_clear_default_handlers() functions are removed. Registration of the default IP layer handlers for Ethernet is now handled automatically. If you have already followed the suggestion to fully initialize the Ethernet driver and network interface before registering their Ethernet/IP event handlers, then no action is required (except for deleting the affected functions). Otherwise, you may start the Ethernet driver right after they register the user event handler.
PHY Address Auto-detect
SPI-Ethernet Module Initialization
The SPI-Ethernet Module initialization is now simplified. Previously, you had to manually allocate an SPI device using
spi_bus_add_device() before instantiating the SPI-Ethernet MAC.
Now, you no longer need to call
spi_bus_add_device() as SPI devices are allocated internally. As a result, the
eth_ksz8851snl_config_t configuration structures are updated to include members for SPI device configuration (e.g., to allow fine tuning of SPI timing which may be dependent on PCB design). Likewise, the
ETH_KSZ8851SNL_DEFAULT_CONFIG configuration initialization macros are updated to accept new input parameters. Refer to Ethernet API Reference Guide for an example of SPI-Ethernet Module initialization.
The TCP/IP Adapter was a network interface abstraction component used in ESP-IDF prior to v4.1. This section outlines migration from tcpip_adapter API to its successor ESP-NETIF.
Updating Network Connection Code
Network Stack Initialization
You may simply replace
esp_netif_init(). However, please should note that the
esp_netif_init()function now returns standard error codes. See ESP-NETIF for more details.
esp_netif_deinit()function is provided to de-initialize the network stack.
You should also replace
Network Interface Creation
Previously, the TCP/IP Adapter defined the following network interfaces statically:
WiFi Access Point
This now changes. Network interface instance should be explicitly constructed, so that the ESP-NETIF can connect to the TCP/IP stack. For example, after the TCP/IP stack and the event loop are initialized, the initialization code for WiFi must explicitly call
Please refer to the example initialization code for these three interfaces:
WiFi Station: wifi/getting_started/station/main/station_example_main.c
WiFi Access Point: wifi/getting_started/softAP/main/softap_example_main.c
Other tcpip_adapter API Replacement
All the tcpip_adapter functions have their esp-netif counter-part. Please refer to the esp_netif.h grouped into these sections:
Default Event Handlers
Event handlers are moved from tcpip_adapter to appropriate driver code. There is no change from application code perspective, as all events should be handled in the same way. Please note that for IP-related event handlers, application code usually receives IP addresses in the form of an esp-netif specific struct instead of the LwIP structs. However, both structs are binary compatible.
This is the preferred way to print the address:
ESP_LOGI(TAG, "got ip:" IPSTR "\n", IP2STR(&event->ip_info.ip));
ESP_LOGI(TAG, "got ip:%s\n", ip4addr_ntoa(&event->ip_info.ip));
ip4addr_ntoa() is a LwIP API, the esp-netif provides
esp_ip4addr_ntoa() as a replacement. However, the above method using
IP2STR() is generally preferred.
You are advised to use esp-netif defined IP structures. Please note that with default compatibility enabled, the LwIP structs will still work.
To port an application which may fully benefit from the ESP-NETIF, you also need to disable the tcpip_adapter compatibility layer in the component configuration option. Please go to
ESP NETIF Adapter >
Enable backward compatible tcpip_adapter interface. After that, check if your project compiles.
The TCP/IP adapter includes many dependencies. Thus, disabling its compatibility might help separate the application from using specific TCP/IP stack API directly.