Ethernet¶
Application Example¶
Ethernet basic example: ethernet/ethernet.
Ethernet iperf example: ethernet/iperf.
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.
- Note
This configuration is not suitable for use as-is, it will need to be modified for your particular PHY hardware setup.
-
const eth_config_t
phy_lan8720_default_ethernet_config
¶ Default LAN8720 PHY configuration.
- Note
This configuration is not suitable for use as-is, it will need to be modified for your particular PHY hardware setup.
-
const eth_config_t
phy_ip101_default_ethernet_config
¶ Default IP101 PHY configuration.
- Note
This configuration is not suitable for use as-is, it will need to be modified for your particular PHY hardware setup.
API Reference - Ethernet¶
Header File¶
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
[in] 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
[in] 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
[in] buf
: start address of packet data.[in] size
: size (byte) of packet data.
-
esp_err_t
esp_eth_enable
(void)¶ Enable ethernet interface.
- Note
Should be called after esp_eth_init
- Return
ESP_OK
ESP_FAIL
-
esp_err_t
esp_eth_disable
(void)¶ Disable ethernet interface.
- Note
Should be called after esp_eth_init
- Return
ESP_OK
ESP_FAIL
-
void
esp_eth_get_mac
(uint8_t mac[6])¶ Get mac addr.
- Note
mac addr must be a valid unicast address
- Parameters
[out] mac
: start address of mac address.
-
void
esp_eth_smi_write
(uint32_t reg_num, uint16_t value)¶ Write PHY reg with SMI interface.
- Note
PHY base addr must be right.
- Parameters
[in] reg_num
: PHY reg num.[in] value
: value which is written 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 that is read from PHY reg
- Parameters
[in] 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 numbervalue
: 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 numbervalue_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
[in] buf
: start address of received 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
[in] mac
: the Mac address.
-
eth_speed_mode_t
esp_eth_get_speed
(void)¶ Get Ethernet link speed.
- Return
eth_speed_mode_t ETH_SPEED_MODE_10M when link speed is 10Mbps ETH_SPEED_MODE_100M when link speed is 100Mbps
Structures¶
-
struct
eth_config_t
¶ ethernet configuration
Public Members
-
eth_phy_base_t
phy_addr
¶ PHY address (0~31)
-
eth_mode_t
mac_mode
¶ MAC mode: only support RMII now
-
eth_clock_mode_t
clock_mode
¶ external/internal clock mode selection
-
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
-
uint32_t
reset_timeout_ms
¶ timeout value for reset emac
-
bool
promiscuous_enable
¶ set true to enable promiscuous mode
-
eth_phy_base_t
Type Definitions¶
-
typedef bool (*
eth_phy_check_link_func
)(void)¶
-
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_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
¶ Ethernet interface mode.
Values:
-
ETH_MODE_RMII
= 0¶ RMII mode
-
ETH_MODE_MII
¶ MII mode
-
-
enum
eth_clock_mode_t
¶ Ethernet clock mode.
Values:
-
ETH_CLOCK_GPIO0_IN
= 0¶ RMII clock input to GPIO0
-
ETH_CLOCK_GPIO0_OUT
= 1¶ RMII clock output from GPIO0
-
ETH_CLOCK_GPIO16_OUT
= 2¶ RMII clock output from GPIO16
-
ETH_CLOCK_GPIO17_OUT
= 3¶ RMII clock output from GPIO17
-
-
enum
eth_speed_mode_t
¶ Ethernet Speed.
Values:
-
ETH_SPEED_MODE_10M
= 0¶ Ethernet speed: 10Mbps
-
ETH_SPEED_MODE_100M
¶ Ethernet speed: 100Mbps
-
-
enum
eth_duplex_mode_t
¶ Ethernet Duplex.
Values:
-
ETH_MODE_HALFDUPLEX
= 0¶ Ethernet half duplex
-
ETH_MODE_FULLDUPLEX
¶ Ethernet full duplex
-
-
enum
eth_phy_base_t
¶ Ethernet PHY address.
Values:
-
PHY0
= 0¶ PHY address 0
-
PHY1
¶ PHY address 1
-
PHY2
¶ PHY address 2
-
PHY3
¶ PHY address 3
-
PHY4
¶ PHY address 4
-
PHY5
¶ PHY address 5
-
PHY6
¶ PHY address 6
-
PHY7
¶ PHY address 7
-
PHY8
¶ PHY address 8
-
PHY9
¶ PHY address 9
-
PHY10
¶ PHY address 10
-
PHY11
¶ PHY address 11
-
PHY12
¶ PHY address 12
-
PHY13
¶ PHY address 13
-
PHY14
¶ PHY address 14
-
PHY15
¶ PHY address 15
-
PHY16
¶ PHY address 16
-
PHY17
¶ PHY address 17
-
PHY18
¶ PHY address 18
-
PHY19
¶ PHY address 19
-
PHY20
¶ PHY address 20
-
PHY21
¶ PHY address 21
-
PHY22
¶ PHY address 22
-
PHY23
¶ PHY address 23
-
PHY24
¶ PHY address 24
-
PHY25
¶ PHY address 25
-
PHY26
¶ PHY address 26
-
PHY27
¶ PHY address 27
-
PHY28
¶ PHY address 28
-
PHY29
¶ PHY address 29
-
PHY30
¶ PHY address 30
-
PHY31
¶ PHY address 31
-
API Reference - PHY Common¶
Header File¶
Functions¶
-
void
phy_rmii_configure_data_interface_pins
(void)¶ Common PHY-management functions.
- Note
These are not enough to drive any particular Ethernet PHY. They provide a common configuration structure and management functions. Configure fixed pins for RMII data interface.
- Note
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 ethernet functions.
- Note
Calling this function along with mii_configure_default_pins() will fully configure the GPIOs for the ethernet PHY.
- Parameters
mdc_gpio
: MDC GPIO Pin numbermdio_gpio
: MDIO GPIO Pin number
-
void
phy_mii_enable_flow_ctrl
(void)¶ Enable flow control in standard PHY MII register.
-
bool
phy_mii_check_link_status
(void)¶ Check Ethernet link status via MII interface.
- Return
true Link is on
- Return
false Link is off
-
bool
phy_mii_get_partner_pause_enable
(void)¶ Check pause frame ability of partner via MII interface.
- Return
true Partner is able to process pause frame
- Return
false Partner can not process pause frame
API Reference - PHY TLK110¶
Header File¶
Functions¶
-
void
phy_tlk110_dump_registers
()¶ Dump TLK110 PHY SMI configuration registers.
-
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.
- Return
eth_speed_mode_t Ethernet speed mode
-
eth_duplex_mode_t
phy_tlk110_get_duplex_mode
(void)¶ Default TLK110 phy_get_duplex_mode function.
- Return
eth_duplex_mode_t Ethernet duplex mode
-
void
phy_tlk110_power_enable
(bool)¶ Default TLK110 phy_power_enable function.
API Reference - PHY LAN8720¶
Header File¶
Functions¶
-
void
phy_lan8720_dump_registers
()¶ Dump LAN8720 PHY SMI configuration registers.
-
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.
- Return
eth_speed_mode_t Ethernet speed mode
-
eth_duplex_mode_t
phy_lan8720_get_duplex_mode
(void)¶ Default LAN8720 phy_get_duplex_mode function.
- Return
eth_duplex_mode_t Ethernet duplex mode
-
void
phy_lan8720_power_enable
(bool)¶ Default LAN8720 phy_power_enable function.
API Reference - PHY IP101¶
Header File¶
Functions¶
-
void
phy_ip101_dump_registers
()¶ Dump IP101 PHY SMI configuration registers.
-
void
phy_ip101_check_phy_init
(void)¶ Default IP101 phy_check_init function.
-
eth_speed_mode_t
phy_ip101_get_speed_mode
(void)¶ Default IP101 phy_get_speed_mode function.
- Return
eth_speed_mode_t Ethernet speed mode
-
eth_duplex_mode_t
phy_ip101_get_duplex_mode
(void)¶ Default IP101 phy_get_duplex_mode function.
- Return
eth_duplex_mode_t Ethernet duplex mode
-
void
phy_ip101_power_enable
(bool)¶ Default IP101 phy_power_enable function.