1# Ethernet Examples
2
3See the [README.md](../README.md) file in the upper level [examples](../) directory for more information about examples.
4
5## Common Pin Assignments
6
7### Using ESP32 internal MAC
8
9* RMII PHY wiring is fixed and can not be changed through either IOMUX or GPIO Matrix. By default, they're connected as follows:
10
11| GPIO   | RMII Signal | Notes        |
12| ------ | ----------- | ------------ |
13| GPIO21 | TX_EN       | EMAC_TX_EN   |
14| GPIO19 | TX0         | EMAC_TXD0    |
15| GPIO22 | TX1         | EMAC_TXD1    |
16| GPIO25 | RX0         | EMAC_RXD0    |
17| GPIO26 | RX1         | EMAC_RXD1    |
18| GPIO27 | CRS_DV      | EMAC_RX_DRV  |
19
20* SMI (Serial Management Interface) wiring is not fixed. You may need to changed it according to your board schematic. By default they're connected as follows:
21
22| GPIO   | SMI Signal  | Notes         |
23| ------ | ----------- | ------------- |
24| GPIO23 | MDC         | Output to PHY |
25| GPIO18 | MDIO        | Bidirectional |
26
27* PHY chip has a reset pin, if want to do a hardware reset during initialization, then you have to connect it with one GPIO on ESP32. See more information from [here](#configure-the-project). The default GPIO used for resetting PHY chip is GPIO5.
28
29### Using SPI ethernet modules
30
31* SPI Ethernet modules (DM9051, W5500, ...) typically consume one SPI interface plus an interrupt and reset GPIO. They can be connected as follows for ESP32 as an example. However, they can be remapped to any pin using the GPIO Matrix.
32
33| GPIO   | DM9051      |
34| ------ | ----------- |
35| GPIO14 | SPI_CLK     |
36| GPIO13 | SPI_MOSI    |
37| GPIO12 | SPI_MISO    |
38| GPIO15 | SPI_CS      |
39| GPIO4  | Interrupt   |
40| NC     | Reset       |
41
42Please consult Espressif Technical reference manual along with datasheet for specific ESP Module you use when assigning any other pins, especially when choosing from system configuration menu for the ethernet examples, some pins cannot be used (they may already be utilized for different purpose like SPI Flash/RAM, etc.).
43
44## Common Configurations
45
461. In the `Example Configuration` menu:
47    * Choose the kind of Ethernet.
48    * If `Internal EMAC` is selected:
49        * Choose PHY device under `Ethernet PHY Device`, by default, the **ESP32-Ethernet-Kit** has an `IP101` on board.
50        * Set GPIO number used by SMI signal under `SMI MDC GPIO number` and `SMI MDIO GPIO number` respectively.
51    * If `SPI Ethernet` is selected:
52        * Set SPI specific configuration, including SPI host number, GPIO numbers and clock rate.
53        * Multiple Ethernet SPI modules of the same type can be connected to single SPI interface at a time. The modules then share data and CLK signals. The CS, interrupt and reset pins need to be specifically configured for each module separately.
54    * Set GPIO number used by PHY chip reset under `PHY Reset GPIO number`, you may have to change the default value according to your board schematic. **PHY hardware reset can be disabled by set this value to -1**.
55    * Set PHY address under `PHY Address`, you may have to change the default value according to your board schematic.
56
572. In the `Component config > Ethernet` menu:
58    * Under `Support ESP32 internal EMAC controller` sub-menu:
59        * In the `PHY interface`, select `Reduced Media Independent Interface (RMII)`, ESP-IDF currently only support RMII mode.
60        * In the `RMII clock mode`, select one of the source that RMII clock (50MHz) comes from: `Input RMII clock from external` or `Output RMII clock from internal`.
61        * If `Output RMII clock from internal` is enabled, you also have to set the GPIO number that used to output the RMII clock, under `RMII clock GPIO number`. In this case, you can set the GPIO number to 16 or 17.
62        * If `Output RMII clock from GPIO0 (Experimental!)` is also enabled, then you have no choice but GPIO0 to output the RMII clock.
63        * In `Amount of Ethernet DMA Rx buffers` and `Amount of Ethernet DMA Tx buffers`, you can set the amount of DMA buffers used for Tx and Rx.
64    * Under `Support SPI to Ethernet Module` sub-menu, select the SPI module that you used for this example. Currently ESP-IDF only supports `DM9051`, `W5500` and `KSZ8851SNL`.
65
66## Common Troubleshooting
67
68* The data panel between ESP32's MAC and PHY needs a fixed 50MHz clock to do synchronization, which also called RMII clock. It can either be provided by an external oscillator or generated from internal APLL. The signal integrity of RMII clock is strict, so keep the trace as short as possible!
69* If the RMII clock is generated from internal APLL, then APLL can't be used for other purpose (e.g. I2S).
70