ESP32-S3 Firmware Architecture
Files Referenced in This Article
CMakeLists.txtesp32_common.cmakemain/CMakeLists.txtmain/idf_component.ymlboards/mpython_v3/mpconfigboard.cmakeboards/labplus_Ledong_v2/mpconfigboard.cmakecomponents/esp_lcd_jd9853/CMakeLists.txtcomponents/gen_bmgr_codes/CMakeLists.txtmakeimg.py
Product Overview
This repository is the MicroPython firmware project for the ESP32-S3 product line (mPython Board 3.0, mPython Core 2.0, etc.), organizing code with the ESP-IDF v5.x and CMake build system. Through a “top-level CMake + board-level configuration + componentization” approach, the project decouples the MicroPython core, ESP-IDF components, user-defined components (LVGL/ESP-Who, etc.), and board-specific resources, supporting one-click build and packaging for multiple boards. Target users are educational hardware developers, system integrators, and maker engineers; it applies to scenarios such as voice interaction, AI vision, GUI display, sensor acquisition, and IoT communication.
Core Business Flow
Select the board: specify mpython_v3 / labplus_Ledong_v2, etc. via MICROPY_BOARD; the top-level CMake loads the corresponding mpconfigboard.cmake and merges SDKCONFIG_DEFAULTS.
Integrate IDF: after including main/CMakeLists.txt, bring in esp32_common.cmake, register the MicroPython main component, and link ESP-IDF components with TinyUSB and audio/video/AI-related dependencies.
Generate pin headers: generate pins.c/pins.h from pins.csv and make-pins.py for use by runtime modules such as Pin/TouchPad.
Freeze Python packages: freeze third-party libraries and business scripts into ROM according to the board’s manifest.py.
Build artifacts: idf.py build produces bootloader/partition/app; then merge_bin invokes makeimg.py to write VFS/LittleFS, voice models, fonts, TTS data, etc. into the final bin according to the partition table, and generates a UF2 on S3.
flowchart TD
A["Set MICROPY_BOARD"] --> B["Load boards/<board>/mpconfigboard.cmake"]
B --> C["Merge SDKCONFIG_DEFAULTS"]
C --> D["include main/CMakeLists.txt -> esp32_common.cmake"]
D --> E["Register the MicroPython main component and IDF dependencies"]
E --> F["Generate pins.c/pins.h"]
F --> G["Compile the application and components"]
G --> H["merge_bin: makeimg.py packages the firmware"]
H --> I{"IDF_TARGET=ESP32S2/S3?"}
I --> |Yes| J["Generate .uf2"]
I --> |No| K["Output .bin only"]
Diagram Sources
CMakeLists.txt:12-46esp32_common.cmake:243-265esp32_common.cmake:355-378makeimg.py:106-222
Section Sources
CMakeLists.txt:12-46esp32_common.cmake:243-265esp32_common.cmake:355-378makeimg.py:106-222
Feature Module List
Build system and entry points
Top-level CMake: defines boards, merges sdkconfig, includes the IDF project, registers the merge_bin target, and checks lockfiles.
main/CMakeLists.txt: sets the port path and brings in esp32_common.cmake.
esp32_common.cmake: aggregates MicroPython sources, extension modules, port adaptation, TinyUSB, IDF components, compile options, and link fragments.
Board configuration system
mpython_v3: enables SPIRAM, BLE, 240MHz, board-level builtin sources, and the frozen manifest.
labplus_Ledong_v2: builds on mpython_v3 by adding ESP-Who-related component directories to enable AI vision capabilities.
Custom components (components)
esp_lcd_jd9853: a screen driver component that depends on esp_lcd and privately depends on driver.
gen_bmgr_codes: generates board information code based on esp_board_manager, archived as a whole package.
Dependency management (idf_component.yml)
Declares official components such as mdns/tinyusb/esp-sr/esp_audio_codec/esp_video/esp32-camera, as well as local path overrides for the gmf_* series components.
Firmware packaging (makeimg.py)
Reads the partition table, assembles bootloader/partitions/application/VFS/voice_data/model, and generates a UF2 when necessary.
Section Sources
CMakeLists.txt:12-46CMakeLists.txt:79-106main/CMakeLists.txt:1-14esp32_common.cmake:40-55esp32_common.cmake:182-224esp32_common.cmake:277-329boards/mpython_v3/mpconfigboard.cmake:1-44boards/labplus_Ledong_v2/mpconfigboard.cmake:1-50components/esp_lcd_jd9853/CMakeLists.txt:1-8components/gen_bmgr_codes/CMakeLists.txt:1-13main/idf_component.yml:1-55makeimg.py:81-222
Data and State
Build-time configuration
Board flags: MPY_PORT_DIR/MICROPY_BOARD/MICROPY_BOARD_DIR, MICROPY_BOARD_VARIANT.
Target chip: IDF_TARGET (esp32s3).
SDK configuration: SDKCONFIG_DEFAULTS merges multiple sdkconfig.* files and finally outputs sdkconfig.combined.
Frozen manifest: MICROPY_FROZEN_MANIFEST points to each board’s manifest.py.
Runtime dependencies
IDF components: app_update/bootloader_support/bt/driver/esp_wifi/nvs_flash/sdmmc/spi_flash/vfs, etc.
Peripherals and protocol stacks: tinyusb (CDC), lwip, mbedtls, nimble (BLE), esp_lcd, esp32-camera, esp-sr, etc.
Storage and partitions
The partition table is described by partition-table.bin and includes bootloader, partitions, application, vfs (LittleFS), voice_data, model (SR model), etc.
makeimg.py writes each segment by offset, validates overflow, and generates the final firmware image; the S3 platform additionally generates a UF2.
graph TB
subgraph "Build time"
A["mpconfigboard.cmake<br/>Set IDF_TARGET/SDKCONFIG_DEFAULTS"] --> B["esp32_common.cmake<br/>Register components/link dependencies"]
B --> C["idf_component.yml<br/>Declare external component versions/paths"]
end
subgraph "Runtime"
D["bootloader"] --> E["partition-table.bin"]
E --> F["application (micropython.bin)"]
E --> G["vfs (littlefs.bin)"]
E --> H["voice_data / model"]
end
C --> B
Diagram Sources
boards/mpython_v3/mpconfigboard.cmake:5-13esp32_common.cmake:182-224main/idf_component.yml:1-55makeimg.py:144-186
Section Sources
boards/mpython_v3/mpconfigboard.cmake:5-13esp32_common.cmake:182-224main/idf_component.yml:1-55makeimg.py:144-186
Key Constraints and Boundaries
Build environment
Requires ESP-IDF v5.2+ (see idf_component.yml) and the presence of the IDF_PATH environment variable.
Lockfiles must be consistent before building; otherwise maintainer builds will fail or warn.
Board differences
mpython_v3 and labplus_Ledong_v2 share the base configuration; the latter additionally brings in ESP-Who component directories to enable camera/AI vision capabilities.
The builtin sources and frozen manifest may differ between boards and must be configured per mpconfigboard.cmake.
Component dependencies
esp_lcd_jd9853 depends on esp_lcd and driver; gen_bmgr_codes depends on esp_board_manager and links as a whole package with WHOLE_ARCHIVE.
TinyUSB is enabled for S3/S2/P4 and resolves the DWC2 ZLP issue via a patch branch.
Storage and partitions
The final image size is limited by the partition table; makeimg.py detects overflow during writing and exits with an error.
If native USB flashing is enabled, the S3 platform automatically generates a UF2 for drag-and-drop flashing.
Section Sources
main/idf_component.yml:51-55CMakeLists.txt:95-106boards/labplus_Ledong_v2/mpconfigboard.cmake:43-49components/esp_lcd_jd9853/CMakeLists.txt:1-8components/gen_bmgr_codes/CMakeLists.txt:1-13makeimg.py:190-222