Network - Ethernet (RMII)

.

Network details

Type: Network

Name: Ethernet (RMII)

Status ESP32: NORMAL

Status ESP8266: .

GitHub: _NW003_ETH_RMII.cpp

Maintainer: TD-er

Ethernet

On nearly all ESP32 builds (exception: ESP32-C2), it is also possible to use ethernet instead of WiFi. Currently this is only present for ESP32 builds and no plans currently exist to support it for ESP82xx.

Ethernet PHY type

ESP boards can be equiped with Ethernet. This is more stable and reliable compared to WiFi and allows for better responsiveness.

Actual transfer speed (at least when using RMII) is also higher than can be achieved via WiFi, but this is less of a concern for typical use cases where ESPEasy is used.

Ethernet chips/boards for ESP32-variant boards exist with 2 types of interfaces to the ESP.

  • RMII interface - Faster actual transfer speeds possible, uses more GPIO pins, only supported on ESP32-classic and ESP32-P4.

  • SPI interface - (Added: 2024/02) Supported on all ESP32-variants (not all tested) on builds based on ESP-IDF 5.1 and later. SPI Ethernet adapters do obviously require the SPI interface to be configured.

Supported Ethernet chips:

  • RMII Interface:
    • LAN8710 (LAN8720 is also supported, but none of the newer features are supported)

    • LAN867X (since ESP32 IDF 5.5)

    • TLK110

    • RTL8201 (since ESP32 IDF 4.4)

    • JL1101 (since ESP32 IDF 4.4)

    • DP83848 (since ESP32 IDF 4.4)

    • KSZ8041 (since ESP32 IDF 4.4)

    • KSZ8081 (since ESP32 IDF 4.4)

  • SPI Interface: (since ESP32 IDF 5.1)
    • DM9051

    • W5500

    • KSZ8851

Note

The LAN8710 and LAN8720 are also available with an “A” suffix. These are the same chips, only produced after the brand SMSC was taken over by Microchip Technology.

Ethernet PHY Address

The PHY address depends on the hardware and the PHY configuration. On some chips, like the LAN8720, the board designer may set this address by pulling some pins either high or low at power on. In theory, one could use multiple PHY adapters on the same RMII/SPI bus, but this is (currently) not supported by ESPEasy.

  • Espressif’s Ethernet board with TLK110 PHY use PHY address 31.

  • Common Waveshare LAN8720 PHY breakout board (and clones) use PHY address 1.

  • Olimex ESP32 EVB REV B IoT LAN8710 PHY Board with CAN use PHY address 0.

  • Other LAN8720 breakouts often use PHY address 0.

  • ETH01-EVO (ESP32-C3 based board) uses PHY address 1.

If the PHY address is incorrect then the EMAC will initialise but all attempts to read/write configuration registers on the PHY will fail.

N.B. There is support for an auto detect of this PHY address, by setting it to -1, but at least on the LAN8720 this does not seem to work.

RMII Ethernet

As mentioned above, the RMII interface is only present on ESP32-classic and ESP32-P4.

RMII PHY SMI Wiring

Most PHY boards have documented their RMII PHY SMI Wiring pins:

  • MDC Output to PHY, usually pin 23

  • MDIO Bidirectional, usually pin 18

Clock sync

The PHY and the ESP need to keep a clock in sync. This can either be done via an external crystal, which is connected to a GPIO pin. Another option is to let the ESP provide the clock to the PHY.

  • External crystal oscillator

  • 50MHz APLL Output on GPIO0

  • 50MHz APLL Output on GPIO16

  • 50MHz APLL Inverted Output on GPIO17

Note

When using an external crystal oscillator, this is connected to GPIO-0. Make sure this crystal is not active, or connected to GPIO-0, during boot or else the ESP32 may boot into flash mode.

Power pin

On almost all PHY boards, or ESP boards equiped with an ethernet PHY, it is possible to turn the PHY on or off. Either to save energy, or to make sure the external clock is not affecting the ESP boot mode when it restarts.

For example the Olimex ESP32-EVB does have the external crystal oscillator connected to GPIO-0, which could boot the ESP32 randomly into UART flash mode. Most boards use a specific GPIO pin to control the power to the PHY. The Olimex ESP32-EVB does have a specific delay circuit to only allow power to the PHY after boot and therefore does not need to control the PHY power.

For other boards, the default is often GPIO-17, but this may change per board.

(Changed: 2022-01-20)

If the power pin is defined, ESPEasy will toggle the ethernet module off and on at boot. Some Ethernet modules, like the LAN8720, may sometimes get stuck and need to be reset to get it to work again.

RMII PHY Wiring

Apart from these GPIO pins, there is a number of other pins reserved on the ESP32 for RMII PHY Wiring.

Since these GPIO pin assignments cannot be changed, it is also not needed to configure them. However, they also cannot be used when RMII PHY is used.

The following PHY connections are required for RMII PHY data connections:

RMII PHY Wiring

GPIO

RMII Signal

ESP32 EMAC Function

Notes

0 / 16 / 17

REF_CLK

EMAC_TX_CLK

See desciption about the clock

18

MDIO

EMAC_MDIO

In theory user configurable, but almost always used as MDIO pin

23

MDC

EMAC_MDC

In theory user configurable, but almost always used as MDC pin

21

TX_EN

EMAC_TX_EN

19

TX0

EMAC_TXD0

22

TX1

EMAC_TXD1

25

RX0

EMAC_RXD0

26

RX1

EMAC_RXD1

27

CRS_DV

EMAC_RX_DRV

See ESP32 datasheet

RMII Ethernet ESP32 Boards

There is a number of ESP32 boards available with Ethernet connected via RMII.

However it is not always clear which configuration should be used.

Warning

Important notice: It is possible to actually damage the Ethernet chip when a wrong configuration is used.

RMII PHY Boards

Board

Ethernet Chip

Addr

MDC

MDIO

Power/RST

Clock

Olimex ESP32 PoE

LAN8720

0

23

18

12

50MHz Inv Output GPIO17

Olimex ESP32 EVB

LAN8720

0

23

18

(no power pin)

External clock

Olimex ESP32 Gateway

LAN8720

0

23

18

5

50MHz Inv Output GPIO17

wESP32

LAN8720

0

16

17

(no power pin)

External clock

WT32 ETH01

LAN8720

1

23

18

?

External clock

TTGO T-Internet-POE ESP32

LAN8720

0

23

18

5 (RST)

50MHz Inv Output GPIO17

TTGO T-ETH-POE-PRO

LAN8720

0

23

18

5 (RST)

50MHz Output GPIO0

TTGO T-INTER_COM

LAN8720

0

23

18

4 (RST)

50MHz Output GPIO0

TTGO T-EH-Lite-ESP32

RTL8201

0

23

18

12

External clock

See:

Ethernet with PoE

Some ethernet boards support Power over Ethernet (PoE), so only a single (ethernet) cable to the ESP is needed, and the ESP (and any sensors) will be powered via an onboard converter.

For Olimex boards in the ESP32-POE range, the supplier has documented this warning:

Warning

Important notice: Olimex ESP32-PoE has no galvanic isolation from Ethernet’s power supply, when you program the board via the micro USB connector the Ethernet cable should be disconnected (if you have power over the Ethernet cable)!

Consider using Olimex USB-ISO to protect your computer and board from accidental short circuit. Also consider instead using Olimex ESP32-PoE-ISO board, which is insulated.

Most likely, this warning is applicable to other brands as well.

Ethernet Isolation

Most Ethernet RJ45 phy (the connector on the PCB) have isolation transformers in them. This does isolate the TX/RX pins to make sure there is no direct connection between the long cables and the Ethernet controller chip. The isolation does protect the Ethernet chip from picked up high voltage spikes and ESD surges when inserting the Ethernet cable. However not all ESP boards with Ethernet have these installed.

Apart from the isolation of the TX/RX pins the metallic enclosure of the phy should also be isolated from the rest of the circuit of the ESP board. Typically this is done by connecting the metal enclosure of the phy via a capacitor to GND of the rest of the circuit. A lot of boards with Ethernet have these directly connected to GND, which may impose a problem when connecting the ESP board to your PC.

Warning

Important notice: For ESP boards with Ethernet which need debugging, never use Ethernet cables with metal shielding on the Ethernet connector.

Using shielded Ethernet cable will connect the metal shield of the RJ45 phy to the ground of the switch and this may be connected to other appliances which may be badly grounded. This will add a significant voltage offset between the ESP board and your PC while debugging. Such a high voltage is very likely to destroy electronics.

Change log

Changed in version 2.0:

added Major overhaul for 2.0 release.

Added in version 1.0:

added Initial release version.

Description