APIs and example programs related to Ethernet of CoreP4X.
3.3.10-aM5CoreP4X0.3.10.3.1pins_arduino.h.CoreP4X has an onboard IP101GRI 10/100M Ethernet PHY. The RMII signals are connected as follows:
| Signal | ESP32-P4 Pin |
|---|---|
| RMII MDC | G31 |
| RMII MDIO | G36 |
| RMII CLK | G32 |
| RMII RXDV | G28 |
| RMII RXD0 | G29 |
| RMII RXD1 | G30 |
| RMII TXEN | G33 |
| RMII TXD0 | G41 |
| RMII TXD1 | G35 |
| PHY RST | G52 |
The RESET_N of the IP101GRI on CoreP4X is pulled down by default. Therefore, before calling ETH.begin(), drive G52 high and wait for the PHY to output the 50 MHz RMII clock.
#include <M5Unified.h>
#include <ETH.h>
enum EthState : uint8_t {
ETH_STARTING,
ETH_CONNECTED,
ETH_GOT_IP,
ETH_DISCONNECTED,
};
volatile bool eth_connected = false;
volatile EthState ethState = ETH_STARTING;
M5Canvas canvas(&M5.Display);
static void drawStatus(const char* title, const char* detail, uint16_t color)
{
canvas.fillSprite(TFT_BLACK);
canvas.setTextDatum(middle_center);
canvas.setTextColor(color, TFT_BLACK);
canvas.setFont(&fonts::FreeSansBold24pt7b);
canvas.drawString(title, 240, 190);
canvas.setTextColor(TFT_WHITE, TFT_BLACK);
canvas.setFont(&fonts::FreeSansBold12pt7b);
canvas.drawString(detail, 240, 264);
canvas.pushSprite(0, 0);
}
static void drawNetworkState(void)
{
char detail[96];
switch (ethState) {
case ETH_CONNECTED:
drawStatus("Link Connected", "Waiting for DHCP", TFT_CYAN);
break;
case ETH_GOT_IP:
snprintf(detail, sizeof(detail), "IP: %s", ETH.localIP().toString().c_str());
drawStatus("Ethernet Ready", detail, TFT_GREEN);
break;
case ETH_DISCONNECTED:
drawStatus("Ethernet Offline", "Check cable and PHY", TFT_RED);
break;
case ETH_STARTING:
default:
drawStatus("Ethernet", "Starting PHY...", TFT_YELLOW);
break;
}
}
void onEvent(arduino_event_id_t event)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
ETH.setHostname("corep4x");
ethState = ETH_STARTING;
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
ethState = ETH_CONNECTED;
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.println("ETH Got IP");
Serial.println(ETH);
eth_connected = true;
ethState = ETH_GOT_IP;
break;
case ARDUINO_EVENT_ETH_LOST_IP:
Serial.println("ETH Lost IP");
eth_connected = false;
ethState = ETH_DISCONNECTED;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
ethState = ETH_DISCONNECTED;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
ethState = ETH_DISCONNECTED;
break;
default:
break;
}
}
void testClient(const char* host, uint16_t port)
{
Serial.print("\nconnecting to ");
Serial.println(host);
drawStatus("Network Test", host, TFT_CYAN);
NetworkClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
drawStatus("Connect Failed", host, TFT_RED);
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available()) {
delay(1);
}
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
drawStatus("HTTP Response", "See Serial Monitor", TFT_GREEN);
}
void setup()
{
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5.begin(cfg);
M5.Display.setBrightness(128);
canvas.createSprite(M5.Display.width(), M5.Display.height());
drawStatus("Ethernet", "Starting PHY...", TFT_YELLOW);
Network.onEvent(onEvent);
pinMode(ETH_PHY_POWER, OUTPUT);
digitalWrite(ETH_PHY_POWER, LOW);
delay(10);
digitalWrite(ETH_PHY_POWER, HIGH);
delay(50);
ETH.begin(ETH_PHY_TYPE,
ETH_PHY_ADDR,
ETH_PHY_MDC,
ETH_PHY_MDIO,
ETH_PHY_POWER,
ETH_CLK_MODE);
}
void loop()
{
static EthState lastState = ETH_STARTING;
static uint32_t lastTest = 0;
const EthState state = ethState;
if (state != lastState) {
lastState = state;
drawNetworkState();
if (state == ETH_GOT_IP) {
lastTest = millis();
}
}
if (eth_connected && millis() - lastTest >= 10000) {
lastTest = millis();
testClient("baidu.com", 80);
}
delay(200);
}After CoreP4X powers on, the screen displays PHY startup, link connection, the IP address obtained through DHCP, and network test results; the serial port also outputs detailed network information. The program accesses baidu.com every 10 seconds. If the connection fails, Connect Failed is displayed and connection failed is output.
Serial output example:
ETH Started
ETH Connected
ETH Got IP
*eth0: <UP,100M,FULL_DUPLEX,AUTO,ADDR:0x1> (DHCPC,GARP,IP_MOD) PRIO: 50
ether 80:F1:B2:DC:59:54
inet 10.42.0.212 netmask 255.255.255.0 broadcast 10.42.0.255
gateway 10.42.0.1 dns 10.42.0.1
connecting to baidu.com
HTTP/1.1 301 Moved Permanently
Location: https://www.baidu.com/
Date: Sat, 28 Nov 2026 03:14:00 GMT
Content-Length: 57
Content-Type: text/html; charset=utf-8
<a href="https://www.baidu.com/">Moved Permanently</a>.
closing connection ETH Started
ETH Connected
ETH Got IP
*eth0: <UP,100M,FULL_DUPLEX,AUTO,ADDR:0x1> (DHCPC,GARP,IP_MOD) PRIO: 50
ether 80:F1:B2:DC:59:54
inet 10.42.0.212 netmask 255.255.255.0 broadcast 10.42.0.255
gateway 10.42.0.1 dns 10.42.0.1
connecting to baidu.com
connection failed