--- kind: build_system name: Multi-Board MicroPython Firmware Build System (ESP32-S3 CMake/ESP-IDF) category: build_system scope: - '**' source_files: - esp32s3/firmware/CMakeLists.txt - esp32s3/firmware/makeimg.py - esp32s3/firmware/eim_config.toml - esp32s3/firmware/boards/mpython_v3/mpconfigboard.cmake - esp32s3/firmware/boards/mpython_v3/sdkconfig.board - esp32s3/firmware/boards/labplus_Ledong_v2/mpconfigboard.cmake - esp32s3/firmware/boards/labplus_Ledong_v2/partitions-16MiB.csv - esp32s3/firmware/boards/manifest.py --- # 1. Build System and Toolchain This repository's ESP32-S3 product line adopts a unified, modern firmware build system: - **ESP32-S3 mPython Board series** (`esp32s3/firmware/`): Built with ESP-IDF v5.x (default `v5.5.4`, see `eim_config.toml`) + CMake; the top-level `CMakeLists.txt` selects the board via `MICROPY_BOARD`, automatically concatenates the `SDKCONFIG_DEFAULTS` list to generate `sdkconfig.combined`, is ultimately driven to compile by IDF's `project.cmake`, and parses the partition table via `makeimg.py` to generate `.bin` and `.uf2`. The documentation side uses Sphinx (`esp32s3/docs/conf.py`) and generates the Chinese manual via `make html` / `make.bat`, separate from the firmware source code; mPython Core 2.0's `esp32s3/docs/boards/ledong_v2/` can be built independently. # 2. Key Files and Packages - **Build entry points**: `esp32s3/firmware/CMakeLists.txt`, `esp32s3/firmware/esp32_common.cmake`, `esp32s3/firmware/makeimg.py` (parses the partition table, generates bin/uf2, injects voice_data/srmodels). - **Board-level configuration**: `esp32s3/firmware/boards//mpconfigboard.cmake` (declares `IDF_TARGET=esp32s3`, `SDKCONFIG_DEFAULTS`, `MICROPY_SOURCE_BOARD`, `MICROPY_FROZEN_MANIFEST`), `partitions-16MiB.csv` (defines the factory/vfs/voice_data/model/fr/user_nvs partitions), `sdkconfig.board` (Kconfig options such as audio/GMF AI voice, BLE, SPIRAM). - **Environment configuration**: `esp32s3/firmware/eim_config.toml` (specifies the IDF path, toolchain versions, and mirror sources). - **Release script**: `esp32s3/firmware/makeimg.py` dynamically reads offsets from the partition table and validates overflow, avoiding manual hard-coding. # 3. Architecture and Conventions ## 3.1 Multi-Board Abstraction - Selects `boards//mpconfigboard.cmake` via `MICROPY_BOARD` (default `mpython_v3`) and supports the `MICROPY_BOARD_VARIANT` variant; each board has its own `sdkconfig.board`, `partitions-*.csv`, and `manifest.py`. ## 3.2 Configuration Layering - Base configuration: `sdkconfig.base` provides common Kconfig values. - Capability switches: composable fragments such as `sdkconfig.ble`, `sdkconfig.spiram`, `sdkconfig.usb`. - Board-specific: `sdkconfig.board` centralizes board-level peripherals (such as the S3's GMF AI Audio and SR_WN_WN9_NIHAOXIAOZHI_TTS). - Build-time concatenation: in CMake, `foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})` writes to `sdkconfig.combined.in`, which is then copied to `sdkconfig.combined`. ## 3.3 Firmware Image Assembly - CMake builds `micropython.bin` + bootloader + partition-table.bin; `makeimg.py` first calls `mklittlefs` to package `file_system/` into `littlefs.bin`, then writes to the vfs/voice_data/model partitions according to the partition-table offsets, and finally generates an additional `.uf2` for S3/S2 chips. ## 3.4 Python Module Freeze Strategy - `boards/manifest.py` includes `asyncio`, requires `bundle-networking`, `aioespnow`, `dht`, `ds18x20`, `onewire`, `upysh`, `collections`, and other standard libraries, and appends custom Python modules per board. ## 3.5 Dependency and Toolchain Management - Declares `idf_versions=["v5.5.4"]` and the required toolsets (xtensa/riscv/clang/ninja/openocd) via `eim_config.toml`. - Uses `lockfiles/dependencies.lock.esp32s3` to constrain the component versions pulled by the ESP-IDF Component Manager; under CI, a build fails if the lockfile changes. # 4. Conventions and Constraints - **Board naming**: ESP32-S3 boards reside uniformly under `esp32s3/firmware/boards//`; five are currently supported: `mpython_v3`, `labplus_Ledong_v2`, `labplus_for_xuejing`, `labplus_xunfei_js_middle`, and `labplus_xunfei_js_primary`. - **Partition-table-driven layout**: All offsets come from `partitions-*.csv`, parsed by `makeimg.py` via `gen_esp32part.PartitionTable.from_binary()`; any manual modification must synchronously update the CSV; the build asserts `offset >= cur_offset` to prevent overlap. - **VFS file system**: Uses LittleFS; packages the contents of the two subdirectories `file_system/common/*` and `file_system//*` via `mklittlefs` and writes them into the `vfs` partition. - **Font resources**: `makeimg.py` references the `Noto_Sans_CJK_SC_Light16.bin` font file for GUI display. - **Version information**: `makeimg.py` also extracts `git describe --tags`, the short hash, and the build date into the firmware filename for version traceability. - **Build artifact isolation**: Outputs to the CMake `BUILD` directory (default `build/`) to avoid conflicts during parallel multi-board builds. - **Documentation-firmware decoupling**: `esp32s3/docs/` contains only Sphinx sources and example code and does not participate in firmware compilation; example code resides in `esp32s3/docs/3_examples/` and `esp32s3/firmware/examples/`, for user reference rather than as part of the build system.