ETHERNET

Application Example

Ethernet example: ethernet/ethernet.

PHY Interfaces

The configured PHY model(s) are set in software by configuring the eth_config_t structure for the given PHY.

Headers include a default configuration structure. These default configurations will need some members overriden or re-set before they can be used for a particular PHY hardware configuration. Consult the Ethernet example to see how this is done.

PHY Configuration Constants

const eth_config_t phy_tlk110_default_ethernet_config

Default TLK110 PHY configuration.

This configuration is not suitable for use as-is, it will need to be modified for your particular PHY hardware setup.

Consult the Ethernet example to see how this is done.

const eth_config_t phy_lan8720_default_ethernet_config

Default LAN8720 PHY configuration.

This configuration is not suitable for use as-is, it will need to be modified for your particular PHY hardware setup.

Consult the Ethernet example to see how this is done.

API Reference - Ethernet

Functions

esp_err_t esp_eth_init(eth_config_t *config)

Init ethernet mac.

Note
config can not be NULL,and phy chip must be suitable to phy init func.
Return
  • ESP_OK
  • ESP_FAIL
Parameters
  • config: mac init data.

esp_err_t esp_eth_init_internal(eth_config_t *config)

Init Ethernet mac driver only.

For the most part, you need not call this function directly. It gets called from esp_eth_init().

This function may be called, if you only need to initialize the Ethernet driver without having to use the network stack on top.

Note
config can not be NULL,and phy chip must be suitable to phy init func.
Return
  • ESP_OK
  • ESP_FAIL
Parameters
  • config: mac init data.

esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size)

Send packet from tcp/ip to mac.

Note
buf can not be NULL,size must be less than 1580
Return
  • ESP_OK
  • ESP_FAIL
Parameters
  • buf: start address of packet data.
  • size: size (byte) of packet data.

esp_err_t esp_eth_enable(void)

Enable ethernet interface.

Note
Shout be called after esp_eth_init
Return
  • ESP_OK
  • ESP_FAIL

esp_err_t esp_eth_disable(void)

Disable ethernet interface.

Note
Shout be called after esp_eth_init
Return
  • ESP_OK
  • ESP_FAIL

void esp_eth_get_mac(uint8_t mac[6])

Get mac addr.

Get mac of ethernet interface.

Note
mac addr must be a valid unicast address
Parameters
  • mac: start address of mac address.
  • mac: store mac of the interface.

void esp_eth_smi_write(uint32_t reg_num, uint16_t value)

Read phy reg with smi interface.

Note
phy base addr must be right.
Parameters
  • reg_num: phy reg num.
  • value: value which write to phy reg.

uint16_t esp_eth_smi_read(uint32_t reg_num)

Read phy reg with smi interface.

Note
phy base addr must be right.
Return
value what read from phy reg
Parameters
  • reg_num: phy reg num.

esp_err_t esp_eth_smi_wait_value(uint32_t reg_num, uint16_t value, uint16_t value_mask, int timeout_ms)

Continuously read a PHY register over SMI interface, wait until the register has the desired value.

Note
PHY base address must be right.
Return
ESP_OK if desired value matches, ESP_ERR_TIMEOUT if timed out.
Parameters
  • reg_num: PHY register number
  • value: Value to wait for (masked with value_mask)
  • value_mask: Mask of bits to match in the register.
  • timeout_ms: Timeout to wait for this value (milliseconds). 0 means never timeout.

static esp_err_t esp_eth_smi_wait_set(uint32_t reg_num, uint16_t value_mask, int timeout_ms)

Continuously read a PHY register over SMI interface, wait until the register has all bits in a mask set.

Note
PHY base address must be right.
Return
ESP_OK if desired value matches, ESP_ERR_TIMEOUT if timed out.
Parameters
  • reg_num: PHY register number
  • value_mask: Value mask to wait for (all bits in this mask must be set)
  • timeout_ms: Timeout to wait for this value (milliseconds). 0 means never timeout.

void esp_eth_free_rx_buf(void *buf)

Free emac rx buf.

Note
buf can not be null,and it is tcpip input buf.
Parameters
  • buf: start address of recevie packet data.

esp_err_t esp_eth_set_mac(const uint8_t mac[6])

Set mac of ethernet interface.

Note
user can call this function after emac_init,and the new mac address will be enabled after emac_enable.
Return
  • ESP_OK: succeed
  • ESP_ERR_INVALID_MAC: invalid mac address
Parameters
  • mac: the Mac address.

Structures

struct eth_config_t

ethernet configuration

Public Members

eth_phy_base_t phy_addr

phy base addr (0~31)

eth_mode_t mac_mode

mac mode only support RMII now

eth_clock_mode_t clock_mode

external/internal clock mode selecton

eth_tcpip_input_func tcpip_input

tcpip input func

eth_phy_func phy_init

phy init func

eth_phy_check_link_func phy_check_link

phy check link func

eth_phy_check_init_func phy_check_init

phy check init func

eth_phy_get_speed_mode_func phy_get_speed_mode

phy check init func

eth_phy_get_duplex_mode_func phy_get_duplex_mode

phy check init func

eth_gpio_config_func gpio_config

gpio config func

bool flow_ctrl_enable

flag of flow ctrl enable

eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable

get partner pause enable

eth_phy_power_enable_func phy_power_enable

enable or disable phy power

Type Definitions

typedef void (*eth_phy_check_init_func)(void)
typedef eth_speed_mode_t (*eth_phy_get_speed_mode_func)(void)
typedef eth_duplex_mode_t (*eth_phy_get_duplex_mode_func)(void)
typedef void (*eth_phy_func)(void)
typedef esp_err_t (*eth_tcpip_input_func)(void *buffer, uint16_t len, void *eb)
typedef void (*eth_gpio_config_func)(void)
typedef bool (*eth_phy_get_partner_pause_enable_func)(void)
typedef void (*eth_phy_power_enable_func)(bool enable)

Enumerations

enum eth_mode_t

Values:

ETH_MODE_RMII = 0
ETH_MODE_MII
enum eth_clock_mode_t

Values:

ETH_CLOCK_GPIO0_IN = 0
ETH_CLOCK_GPIO0_OUT = 1
ETH_CLOCK_GPIO16_OUT = 2
ETH_CLOCK_GPIO17_OUT = 3
enum eth_speed_mode_t

Values:

ETH_SPEED_MODE_10M = 0
ETH_SPEED_MODE_100M
enum eth_duplex_mode_t

Values:

ETH_MODE_HALFDUPLEX = 0
ETH_MODE_FULLDUPLEX
enum eth_phy_base_t

Values:

PHY0 = 0
PHY1
PHY2
PHY3
PHY4
PHY5
PHY6
PHY7
PHY8
PHY9
PHY10
PHY11
PHY12
PHY13
PHY14
PHY15
PHY16
PHY17
PHY18
PHY19
PHY20
PHY21
PHY22
PHY23
PHY24
PHY25
PHY26
PHY27
PHY28
PHY29
PHY30
PHY31

API Reference - PHY Common

Functions

void phy_rmii_configure_data_interface_pins(void)

Common PHY-management functions.

These are not enough to drive any particular Ethernet PHY, but they provide a common configuration structure and management functions. Configure fixed pins for RMII data interface.

This configures GPIOs 0, 19, 22, 25, 26, 27 for use with RMII data interface. These pins cannot be changed, and must be wired to ethernet functions.

This is not sufficient to fully configure the Ethernet PHY, MDIO configuration interface pins (such as SMI MDC, MDO, MDI) must also be configured correctly in the GPIO matrix.

void phy_rmii_smi_configure_pins(uint8_t mdc_gpio, uint8_t mdio_gpio)

Configure variable pins for SMI (MDIO) ethernet functions.

Calling this function along with mii_configure_default_pins() will fully configure the GPIOs for the ethernet PHY.

void phy_mii_enable_flow_ctrl(void)

Enable flow control in standard PHY MII register.

bool phy_mii_get_partner_pause_enable(void)

API Reference - PHY TLK110

Functions

void phy_tlk110_dump_registers()

Dump all TLK110 PHY SMI configuration registers.

Note
These registers are dumped at ‘debug’ level, so output may not be visible depending on default log levels.

void phy_tlk110_check_phy_init(void)

Default TLK110 phy_check_init function.

eth_speed_mode_t phy_tlk110_get_speed_mode(void)

Default TLK110 phy_get_speed_mode function.

eth_duplex_mode_t phy_tlk110_get_duplex_mode(void)

Default TLK110 phy_get_duplex_mode function.

void phy_tlk110_power_enable(bool)

Default TLK110 phy_power_enable function.

Consult the ethernet example to see how this is done.

Note
This function may need to be replaced with a custom function if the PHY has a GPIO to enable power or start a clock.

void phy_tlk110_init(void)

Default TLK110 phy_init function.

API Reference - PHY LAN8720

Functions

void phy_lan8720_dump_registers()

Dump all LAN8720 PHY SMI configuration registers.

Note
These registers are dumped at ‘debug’ level, so output may not be visible depending on default log levels.

void phy_lan8720_check_phy_init(void)

Default LAN8720 phy_check_init function.

eth_speed_mode_t phy_lan8720_get_speed_mode(void)

Default LAN8720 phy_get_speed_mode function.

eth_duplex_mode_t phy_lan8720_get_duplex_mode(void)

Default LAN8720 phy_get_duplex_mode function.

void phy_lan8720_power_enable(bool)

Default LAN8720 phy_power_enable function.

Consult the ethernet example to see how this is done.

Note
This function may need to be replaced with a custom function if the PHY has a GPIO to enable power or start a clock.

void phy_lan8720_init(void)

Default LAN8720 phy_init function.