r/esp32 • • 13h ago

I made a thing! php-esp32-sdk 2.0: the upstream PHP interpreter on ESP32-S3/P4, now on ESP-IDF v6.1.1

https://www.php-baremetal.com/blog/php-esp32-sdk-2-composer-firmware

php-baremetal runs the real Zend engine (PHP 8.3 to 8.6) cross-compiled on top of ESP-IDF. PHP's memory lives in PSRAM, so the targets are the ESP32-S3 and ESP32-P4 with PSRAM (2 to 32 MB). Chips without PSRAM aren't supported.

2.0 is a rewrite. What might interest this sub:

  • ESP-IDF v6.1.1 (was v5.5.5), installed by the CLI.
  • ESP32-S3 tuning, set in the SDK: CPU at 240 MHz instead of the 160 MHz default, a 32 KB instruction cache instead of 16 KB, and an 8 KB main-task stack instead of 32 KB (it uses about 1 KB, and the 24 KB go back to internal RAM for Wi-Fi). Boards can also move Wi-Fi/lwIP/mbedTLS buffers to PSRAM and tune the static buffer count, which is what lets Wi-Fi start next to a double-buffered 1024x600 RGB panel. QIO flash where the board supports it.
  • Boards are JSON files (chip, PSRAM, flash, and peripheral blocks for display, I2C, touch, LED, microSD…). Drivers read the blocks, so Ws2812::onboard() already knows the LED pin. A project can override a block or add one, for example an SPI microSD slot on a generic S3 module, and every pin is checked before anything compiles.
  • Pin names: the new Arduino Nano ESP32 and Seeed Studio XIAO ESP32-S3 board files expose D13, A3, LED_BUILTIN to PHP as Pin::LED_BUILTIN. Waveshare, Freenove and Espressif DevKitC boards are supported too.
  • Slate: a retained-mode scene graph that composes only the bands that changed. A still screen costs zero frames.
  • Fixes measured on hardware:

    • Uninitialised PSRAM chunk headers caused zend_mm_heap corrupted on up to 20 of 20 cold starts of a large app. Now 0 of 20.
    • On the P4, core 1 polled the scheduler with no pause and could stall core 0 before app_main. One image faulted on all 102 starts; with the fix, none.
    • A closure-cache patch leaked about 49 B per bind(). Now 9M rounds run with flat memory.

bash

composer global require php-baremetal/phpbm php-baremetal/conductor
phpbm sdk:install esp32 && phpbm init blink
phpbm toolchain:install && phpbm flash && phpbm monitor

Write-up with diagrams: https://www.php-baremetal.com/blog/php-esp32-sdk-2-composer-firmware

Custom composer Registry : https://repository.php-baremetal.com/ with all available package

web simulator, built on Velxio: https://sim.php-baremetal.com/

Github: https://github.com/php-baremetal/php-esp32-sdk

It's an independent, MIT-licensed project, not affiliated with Espressif. If you have an S3 or P4 board that isn't covered, a board file is a small JSON. Which boards should we add next?

6 Upvotes

1 comment sorted by

1

u/AI_Tonic 4h ago

Ha great work