November 15, 2026, 07:15:13 AM

ESP32-P4 micropython port

Started by kerekesg, October 26, 2025, 01:26:53 AM

Previous topic - Next topic

kerekesg

Just in case anyone would need to run micropython on the ESP32-P4, you can get a build firmware from here:

https://codeberg.org/kerekesg/micropython-olimex-esp32-p4

AI helped me, but it works well on my Olimex ESP32-P4 board.

LubOlimex

Thank you for this, I am sure someone will find it helpful!
Technical support and documentation manager at Olimex

puhuri

I was testing ESP-P4-DevKit (rev D1) ethernet on micropython. Seems that I cannot find the right set of parameters to initialize connection.

With vanilla Micropython ESP32_P4 v1.29 (PRE_V3 variant:(sysname='esp32', nodename='esp32', release='1.29.0', version='v1.29.0 on 2026-08-24', machine='Generic ESP32P4 with pre revision 3 chip with ESP32-P4')) the error message is OSError: esp_eth_driver_install failed with invalid argument for all the cases.

With kerekesg firmware (sysname='esp32', nodename='esp32', release='1.27.0-preview', version='v1.27.0-preview.339.gbe4892097e.dirty on 2025-10-23', machine='Olimex ESP32-P4-DevKit with ESP32-P4') the error is a bit more useful:

E (30570) esp_eth: esp_eth_driver_install(209): can't set eth->mac or eth->phy to null
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
I've tried several intialization parameters but no luck (leaving some parameters out and trying out variations). The most correct I think is (based on schematic and micropython source):

lan=network.LAN(0, mdc=Pin(31), mdio=Pin(52), phy_type=network.PHY_IP101, phy_addr=1,  reset=Pin(51), ref_clk=Pin(50), ref_clk_mode=0)
but that fails with above error. With kerekesg firmware there seems to be an issue with GPIO configuration as Pin(52) results "ValueError: invalid pin" (Pin(32) works fine, for example).

The ref_clock_mode is a bit guess, 0 is input AFAIK but tried also 1.

Would just want to use wired network connection for a location as the wifi connection there is a bit spotty.

Have not yet tried to compile own firmware (with updated micropython), just trying to first check that it is not something trivial I'm missing here.


puhuri

Now had time to look at it more.

The modifications and instructions from kerekesg is a good base. The major issue is that one need build PRE_REV3 variant.

So my workflow was following. Clone both the micropython and the above repo according to their instructions.

Copy modified files over:

cd micropython
cp -r ../micropython-olimex-esp32-p4/board-files/OLIMEX_ESP32_P4 ports/esp32/boards/
cp ../micropython-olimex-esp32-p4/board-files/sdkconfig.p4 ports/esp32/boards/
cp ../micropython-olimex-esp32-p4/board-files/sdkconfig.riscv ports/esp32/boards/
cp ../micropython-olimex-esp32-p4/board-files/dependencies.lock.esp32p4 ports/esp32/lockfiles/
cp ports/esp32/boards/ESP32_GENERIC_P4/mpconfigvariant_PRE_REV3.cmake ports/esp32/boards/OLIMEX_ESP32_P4/

I used docker image (with podman) for interactive session (did run low with diskspace so need to check old photos had been backup to NAS  ;D ).

docker run --rm -v $PWD:/project -w /project -e HOME=/tmp -it espressif/idf:release-v5.5

Then within container commandline run:

cd ports/esp32 && make BOARD=OLIMEX_ESP32_P4 BOARD_VARIANT=PRE_REV3

And once compilation completed without major error (reported some re#defines warnings), just cd ports/esp32/build-OLIMEX_ESP32_P4-PRE_REV3 and write to board.

PORT=/dev/serial/by-id/usb-Espressif*
esptool --port $PORT --chip esp32p4 -b 460800 --before default-reset --after hard-reset write-flash "@flash_args"

I'm using MQTT_AS package, so one needs to install github:peterhinch/micropython-mqtt/mqtt_as_eth instead and define
import mqtt_as_eth in python initialization. The normal mqtt_as does use WLAN-dependent code that won't work. Successfully connects to MQTT server and communicates messages  8) . Next up some soldering, but that is for later.