EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #186 background imageLoading...
Page #186 background image
Chapter 2. API Reference
(continued from previous page)
esp_netif_init()); // Initialize TCP/IP network interface (should be called only
,once in application)
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); // apply default network
,interface configuration for Ethernet
esp_netif_t *eth_netif = esp_netif_new(&cfg); // create network interface for
,Ethernet driver
esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)); // attach
,Ethernet driver to TCP/IP stack
esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler,
,NULL); // register user defined IP event handlers
esp_eth_start(eth_handle); // start Ethernet driver state machine
Warning: It is recommended to fully initialize the Ethernet driver and network interface prior registering user
s Ethernet/IP event handlers, i.e. register the event handlers as the last thing prior starting the Ethernet driver.
Such approach ensures that Ethernet/IP events get executed first by the Ethernet driver or network interface and
so the system is in expected state when executing users handlers.
Misc control of Ethernet driver The following functions should only be invoked after the Ethernet driver has been
installed.
Stop Ethernet driver: esp_eth_stop()
Update Ethernet data input path: esp_eth_update_input_path()
Misc get/set of Ethernet driver attributes: esp_eth_ioctl()
/* get MAC address */
uint8_t mac_addr[6];
memset(mac_addr, 0, sizeof(mac_addr));
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ESP_LOGI(TAG, "Ethernet MAC Address: %02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_
,addr[5]);
/* get PHY address */
int phy_addr = -1;
esp_eth_ioctl(eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr);
ESP_LOGI(TAG, "Ethernet PHY Address: %d", phy_addr);
Flow control Ethernet on MCU usually has a limitation in the number of frames it can handle during network
congestion, because of the limitation in RAM size. A sending station might be transmitting data faster than the
peer end can accept it. Ethernet flow control mechanism allows the receiving node to signal the sender requesting
suspension of transmissions until the receiver catches up. The magic behind that is the pause frame, which was defined
in IEEE 802.3x.
Pause frame is a special Ethernet frame used to carry the pause command, whose EtherType field is 0x8808, with
the Control opcode set to 0x0001. Only stations configured for full-duplex operation may send pause frames. When
a station wishes to pause the other end of a link, it sends a pause frame to the 48-bit reserved multicast address
of 01-80-C2-00-00-01. The pause frame also includes the period of pause time being requested, in the form of a
two-byte integer, ranging from 0 to 65535.
After Ethernet driver installation, the flow control feature is disabled by default. You can enable it by invoking
esp_eth_ioctl(eth_handle, ETH_CMD_S_FLOW_CTRL, true);. One thing should be kept in mind, is that the pause
frame ability will be advertised to peer end by PHY during auto negotiation. Ethernet driver sends pause frame only
when both sides of the link support it.
Espressif Systems 175
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP32-S2 and is the answer not in the manual?

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish