Chapter 2. API Reference
Configure MAC and PHY
We need to setup necessary parameters for MAC and PHY respectively based on your Ethernet board design and
then combine the two together, completing the driver installation.
Configuration for MAC is described in eth_mac_config_t, including:
• sw_reset_timeout_ms: software reset timeout value, in milliseconds, typically MAC reset should be
finished within 100ms.
• rx_task_stack_size and rx_task_prio: the MAC driver creates a dedicated task to process in-
coming packets, these two parameters are used to set the stack size and priority of the task.
• flags: specifying extra features that the MAC driver should have, it could be useful in some special sit-
uations. The value of this field can be OR'd with macros prefixed with ETH_MAC_FLAG_. For ex-
ample, if the MAC driver should work when cache is disabled, then you should configure this field with
ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE.
Configuration for PHY is described in eth_phy_config_t, including:
• phy_addr: multiple PHY device can share the same SMI bus, so each PHY needs a unique address. Usually
this address is configured during hardware design by pulling up/down some PHY strapping pins. You can set
the value from 0 to 15 based on your Ethernet board. Especially, if the SMI bus is shared by only one PHY
device, setting this value to -1 can enable the driver to detect the PHY address automatically.
• reset_timeout_ms: reset timeout value, in milliseconds, typically PHY reset should be finished within
100ms.
• autonego_timeout_ms: auto-negotiation timeout value, in milliseconds. Ethernet driver will start nego-
tiation with the peer Ethernet node automatically, to determine to duplex and speed mode. This value usually
depends on the ability of the PHY device on your board.
• reset_gpio_num: if your board also connect the PHY reset pin to one of the GPIO, then set it here.
Otherwise, set this field to -1.
ESP-IDF provides a default configuration for MAC and PHY in macro
ETH_PHY_DEFAULT_CONFIG.
Create MAC and PHY Instance
MAC and PHY should be based on the instance of them two.
SPI-Ethernet Module
eth_mac_config_t mac_config
configuration
→
eth_phy_config_t phy_config
configuration
→
phy_config.phy_addr
address according to your board design
→
phy_config.reset_gpio_num
used for PHY reset
→
// Install GPIO interrupt service (as the SPI-Ethernet module is interrupt driven)
gpio_install_isr_service(0);
// SPI bus configuration
spi_device_handle_t spi_handle
spi_bus_config_t buscfg
.miso_io_num
=
CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO,
.mosi_io_num
=
CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO,
.sclk_io_num
=
CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO,
.quadwp_io_num
=
.quadhd_io_num
=
};
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
// Allocate SPI device from the bus
spi_device_interface_config_t devcfg
.command_bits
=
.address_bits
=
Espressif Systems
Ethernet driver is composed of two parts: MAC and PHY.
Ethernet driver is implemented in an Object-Oriented style. Any operation on
=
ETH_MAC_DEFAULT_CONFIG();
=
ETH_PHY_DEFAULT_CONFIG();
=
CONFIG_EXAMPLE_ETH_PHY_ADDR;
=
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO;
=
NULL;
=
{
-1,
-1,
=
{
1,
7,
Submit Document Feedback
ETH_MAC_DEFAULT_CONFIG
172
// apply default
MAC␣
// apply default
PHY␣
// alter the
PHY␣
// alter the
GPIO␣
(continues on next page)
Release v4.4
and
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers