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 #183 background imageLoading...
Page #183 background image
Chapter 2. API Reference
Configure MAC and PHY Ethernet driver is composed of two parts: 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 ORd 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_MAC_DEFAULT_CONFIG and
ETH_PHY_DEFAULT_CONFIG.
Create MAC and PHY Instance Ethernet driver is implemented in an Object-Oriented style. Any operation on
MAC and PHY should be based on the instance of them two.
SPI-Ethernet Module
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC
,configuration
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY
,configuration
phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; // alter the PHY
,address according to your board design
phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; // alter the GPIO
,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 = NULL;
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 = -1,
.quadhd_io_num = -1,
};
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 = 1,
.address_bits = 7,
(continues on next page)
Espressif Systems 172
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