
Classic ESP32: built-in MAC, outside PHY
The classic ESP32 has an Ethernet MAC inside and needs a PHY outside. Its six RMII data pins are fixed, and the 50 MHz clock comes in on GPIO0, a strapping pin that needs care at power-up.
Half of the interface is in the chip
The classic ESP32 has an Ethernet MAC built in, with its own DMA to move frames between the MAC and memory. It has no PHY. A board that wants a cable needs a PHY chip, usually a transformer, and a jack, and the RMII lines between the ESP32 and the PHY.
The hardware also describes MII, but RMII is the only mode ESP-IDF supports on this chip. ESP-IDF ships drivers for several PHYs (IP101, RTL8201, LAN87xx, DP83848 and KSZ80xx) and a generic driver for any PHY that keeps to the IEEE 802.3 registers.
Six pins that do not move
The six RMII data lines go through the chip's IO mux, so their pins are fixed: TXD0 on GPIO19, TX_EN on GPIO21 and TXD1 on GPIO22 send; RXD0 on GPIO25, RXD1 on GPIO26 and CRS_DV on GPIO27 receive. A board design that has already spent one of these on an LED or a button has to move the LED. The management pair, MDC and MDIO, can go on any free GPIO.
The clock and GPIO0
The 50 MHz reference clock can come into the ESP32 only on GPIO0. GPIO0 is also a strapping pin: the chip reads it at power-up, and low means download mode. A PHY or an oscillator already ticking on GPIO0 when the power comes on can put the chip into download mode, and the board sits there waiting for a firmware upload instead of running its program. Espressif's workaround is to keep the clock disabled in hardware until the Ethernet driver starts, and let the driver turn it on.
The ESP32 can make the clock itself instead, sending it out on GPIO0, GPIO16 or GPIO17. On ESP32-WROVER modules, GPIO16 and GPIO17 belong to the PSRAM and cannot be used for anything else. And if Ethernet has to work while Wi-Fi is running, Espressif says not to use the ESP32 as the clock source: let the PHY or an oscillator make it.
For wiring a real board and the code that brings the interface up, see Ethernet instead of Wi-Fi in the ESP32 book.
Common mistakes
- Choosing pins for the RMII data lines. They are fixed by the IO mux. Only MDC and MDIO can go where the layout likes.
- Feeding the clock to GPIO0 from power-up. The chip can start in download mode. Hold the clock off until the driver starts.
- Sending the clock out on GPIO16 or GPIO17 of a WROVER module. Those pins are the PSRAM's. With Wi-Fi in use, let the PHY or an oscillator make the clock anyway.
Edit this page — content/fundamentals/ethernet/classic-esp32-built-in-mac.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.