Skip to content

Commit ee1bc6b

Browse files
Add RMII Ethernet support for ESP32-P4 (#10479)
* fix(eth): Add ETH support for ESP32-P4 Also adds configuration to pins_arduino.h * fix(eth): Enable TLK110 Example on P4 * fix(eth): Fix Ethernet examples * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 612fc4c commit ee1bc6b

File tree

9 files changed

+96
-16
lines changed

9 files changed

+96
-16
lines changed

boards.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ esp32p4.build.variant=esp32p4
188188
esp32p4.build.board=ESP32P4_DEV
189189
esp32p4.build.bootloader_addr=0x2000
190190

191+
esp32p4.build.usb_mode=0
191192
esp32p4.build.cdc_on_boot=0
193+
esp32p4.build.msc_on_boot=0
194+
esp32p4.build.dfu_on_boot=0
192195
esp32p4.build.f_cpu=360000000L
193196
esp32p4.build.flash_size=4MB
194197
esp32p4.build.flash_freq=80m
@@ -216,10 +219,10 @@ esp32p4.menu.PSRAM.disabled.build.defines=
216219
esp32p4.menu.PSRAM.enabled=Enabled
217220
esp32p4.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM
218221

219-
esp32p4.menu.USBMode.hwcdc=Hardware CDC and JTAG
220-
esp32p4.menu.USBMode.hwcdc.build.usb_mode=1
221222
esp32p4.menu.USBMode.default=USB-OTG (TinyUSB)
222223
esp32p4.menu.USBMode.default.build.usb_mode=0
224+
esp32p4.menu.USBMode.hwcdc=Hardware CDC and JTAG
225+
esp32p4.menu.USBMode.hwcdc.build.usb_mode=1
223226

224227
esp32p4.menu.CDCOnBoot.default=Disabled
225228
esp32p4.menu.CDCOnBoot.default.build.cdc_on_boot=0

libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
// Important to be defined BEFORE including ETH.h for ETH.begin() to work.
77
// Example RMII LAN8720 (Olimex, etc.)
8-
#ifndef ETH_PHY_TYPE
9-
#define ETH_PHY_TYPE ETH_PHY_LAN8720
8+
#ifndef ETH_PHY_MDC
9+
#define ETH_PHY_TYPE ETH_PHY_LAN8720
10+
#if CONFIG_IDF_TARGET_ESP32
1011
#define ETH_PHY_ADDR 0
1112
#define ETH_PHY_MDC 23
1213
#define ETH_PHY_MDIO 18
1314
#define ETH_PHY_POWER -1
1415
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
16+
#elif CONFIG_IDF_TARGET_ESP32P4
17+
#define ETH_PHY_ADDR 0
18+
#define ETH_PHY_MDC 31
19+
#define ETH_PHY_MDIO 52
20+
#define ETH_PHY_POWER 51
21+
#define ETH_CLK_MODE EMAC_CLK_EXT_IN
22+
#endif
1523
#endif
1624

1725
#include <ETH.h>

libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
#include <ETH.h>
77

8-
#ifndef ETH_PHY_TYPE
9-
#define ETH_PHY_TYPE ETH_PHY_TLK110
8+
#ifndef ETH_PHY_MDC
9+
#define ETH_PHY_TYPE ETH_PHY_TLK110
10+
#if CONFIG_IDF_TARGET_ESP32
1011
#define ETH_PHY_ADDR 31
1112
#define ETH_PHY_MDC 23
1213
#define ETH_PHY_MDIO 18
1314
#define ETH_PHY_POWER 17
1415
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
16+
#elif CONFIG_IDF_TARGET_ESP32P4
17+
#define ETH_PHY_ADDR 1
18+
#define ETH_PHY_MDC 31
19+
#define ETH_PHY_MDIO 52
20+
#define ETH_PHY_POWER 51
21+
#define ETH_CLK_MODE EMAC_CLK_EXT_IN
22+
#endif
1523
#endif
1624

1725
static bool eth_connected = false;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"requires": [
33
"CONFIG_ETH_USE_ESP32_EMAC=y"
4-
],
5-
"targets": {
6-
"esp32p4": false
7-
}
4+
]
85
}

libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Set this to 1 to enable dual Ethernet support
1010
#define USE_TWO_ETH_PORTS 0
1111

12-
#ifndef ETH_PHY_TYPE
12+
#ifndef ETH_PHY_CS
1313
#define ETH_PHY_TYPE ETH_PHY_W5500
1414
#define ETH_PHY_ADDR 1
1515
#define ETH_PHY_CS 15
@@ -24,7 +24,7 @@
2424

2525
#if USE_TWO_ETH_PORTS
2626
// Second port on shared SPI bus
27-
#ifndef ETH1_PHY_TYPE
27+
#ifndef ETH1_PHY_CS
2828
#define ETH1_PHY_TYPE ETH_PHY_W5500
2929
#define ETH1_PHY_ADDR 1
3030
#define ETH1_PHY_CS 32

libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Set this to 1 to enable dual Ethernet support
99
#define USE_TWO_ETH_PORTS 0
1010

11-
#ifndef ETH_PHY_TYPE
11+
#ifndef ETH_PHY_CS
1212
#define ETH_PHY_TYPE ETH_PHY_W5500
1313
#define ETH_PHY_ADDR 1
1414
#define ETH_PHY_CS 15
@@ -22,7 +22,7 @@
2222

2323
#if USE_TWO_ETH_PORTS
2424
// Second port on shared SPI bus
25-
#ifndef ETH1_PHY_TYPE
25+
#ifndef ETH1_PHY_CS
2626
#define ETH1_PHY_TYPE ETH_PHY_W5500
2727
#define ETH1_PHY_ADDR 1
2828
#define ETH1_PHY_CS 32

libraries/Ethernet/src/ETH.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,27 @@ void ETHClass::setTaskStackSize(size_t size) {
148148
_task_stack_size = size;
149149
}
150150

151-
#if (CONFIG_ETH_USE_ESP32_EMAC && !defined(CONFIG_IDF_TARGET_ESP32P4))
151+
#if CONFIG_ETH_USE_ESP32_EMAC
152+
#if CONFIG_IDF_TARGET_ESP32
153+
#define ETH_EMAC_DEFAULT_CONFIG() ETH_ESP32_EMAC_DEFAULT_CONFIG()
154+
#elif CONFIG_IDF_TARGET_ESP32P4
155+
#define ETH_EMAC_DEFAULT_CONFIG() \
156+
{ \
157+
.smi_gpio = {.mdc_num = 31, .mdio_num = 52}, .interface = EMAC_DATA_INTERFACE_RMII, \
158+
.clock_config = {.rmii = {.clock_mode = EMAC_CLK_EXT_IN, .clock_gpio = (emac_rmii_clock_gpio_t)ETH_RMII_CLK}}, .dma_burst_len = ETH_DMA_BURST_LEN_32, \
159+
.intr_priority = 0, \
160+
.emac_dataif_gpio = \
161+
{.rmii = \
162+
{.tx_en_num = ETH_RMII_TX_EN, \
163+
.txd0_num = ETH_RMII_TX0, \
164+
.txd1_num = ETH_RMII_TX1, \
165+
.crs_dv_num = ETH_RMII_CRS_DV, \
166+
.rxd0_num = ETH_RMII_RX0, \
167+
.rxd1_num = ETH_RMII_RX1_EN}}, \
168+
.clock_config_out_in = {.rmii = {.clock_mode = EMAC_CLK_EXT_IN, .clock_gpio = (emac_rmii_clock_gpio_t) - 1}}, \
169+
}
170+
#endif
171+
152172
bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode) {
153173
esp_err_t ret = ESP_OK;
154174
if (_eth_index > 2) {
@@ -177,12 +197,16 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
177197
#define DEFAULT_RMII_CLK_GPIO (emac_rmii_clock_gpio_t)(CONFIG_ETH_RMII_CLK_IN_GPIO)
178198
#endif
179199

180-
eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
200+
eth_esp32_emac_config_t mac_config = ETH_EMAC_DEFAULT_CONFIG();
201+
#if CONFIG_IDF_TARGET_ESP32
181202
mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
182203
mac_config.clock_config.rmii.clock_gpio = (1 == clock_mode) ? EMAC_APPL_CLK_OUT_GPIO
183204
: (2 == clock_mode) ? EMAC_CLK_OUT_GPIO
184205
: (3 == clock_mode) ? EMAC_CLK_OUT_180_GPIO
185206
: EMAC_CLK_IN_GPIO;
207+
#elif CONFIG_IDF_TARGET_ESP32P4
208+
mac_config.clock_config.rmii.clock_mode = (emac_rmii_clock_mode_t)clock_mode;
209+
#endif
186210
mac_config.smi_gpio.mdc_num = digitalPinToGPIONumber(mdc);
187211
mac_config.smi_gpio.mdio_num = digitalPinToGPIONumber(mdio);
188212

libraries/Ethernet/src/ETH.h

+26
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
#if CONFIG_ETH_USE_ESP32_EMAC
7777
#define ETH_PHY_IP101 ETH_PHY_TLK110
78+
#if CONFIG_IDF_TARGET_ESP32
7879
typedef enum {
7980
ETH_CLOCK_GPIO0_IN,
8081
ETH_CLOCK_GPIO0_OUT,
@@ -88,6 +89,31 @@ typedef enum {
8889
#define ETH_RMII_RX0 25
8990
#define ETH_RMII_RX1_EN 26
9091
#define ETH_RMII_CRS_DV 27
92+
#elif CONFIG_IDF_TARGET_ESP32P4
93+
typedef emac_rmii_clock_mode_t eth_clock_mode_t;
94+
#include "pins_arduino.h"
95+
#ifndef ETH_RMII_TX_EN
96+
#define ETH_RMII_TX_EN 49
97+
#endif
98+
#ifndef ETH_RMII_TX0
99+
#define ETH_RMII_TX0 34
100+
#endif
101+
#ifndef ETH_RMII_TX1
102+
#define ETH_RMII_TX1 35
103+
#endif
104+
#ifndef ETH_RMII_RX0
105+
#define ETH_RMII_RX0 29
106+
#endif
107+
#ifndef ETH_RMII_RX1_EN
108+
#define ETH_RMII_RX1_EN 30
109+
#endif
110+
#ifndef ETH_RMII_CRS_DV
111+
#define ETH_RMII_CRS_DV 28
112+
#endif
113+
#ifndef ETH_RMII_CLK
114+
#define ETH_RMII_CLK 50
115+
#endif
116+
#endif
91117
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
92118

93119
#ifndef ETH_PHY_SPI_FREQ_MHZ

variants/esp32p4/pins_arduino.h

+14
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,18 @@ static const uint8_t T11 = 13;
5757
static const uint8_t T12 = 14;
5858
static const uint8_t T13 = 15;
5959

60+
#define ETH_PHY_TYPE ETH_PHY_TLK110
61+
#define ETH_PHY_ADDR 1
62+
#define ETH_PHY_MDC 31
63+
#define ETH_PHY_MDIO 52
64+
#define ETH_PHY_POWER 51
65+
#define ETH_RMII_TX_EN 49
66+
#define ETH_RMII_TX0 34
67+
#define ETH_RMII_TX1 35
68+
#define ETH_RMII_RX0 29
69+
#define ETH_RMII_RX1_EN 30
70+
#define ETH_RMII_CRS_DV 28
71+
#define ETH_RMII_CLK 50
72+
#define ETH_CLK_MODE EMAC_CLK_EXT_IN
73+
6074
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)