Skip to content

Commit e295322

Browse files
committed
ESP32: Modernize Build System Infrastructure (Step 1)
This PR introduces the core infrastructure for a data-driven build system for ESP32, aligning it further with the standard ArduPilot hwdef.dat approach while maintaining strict compatibility with existing board syntax. Key Infrastructure Changes: - Generalized esp32_hwdef.py: Supports multiple chip variants (ESP32, S2, S3, C3, C6, P4) through a data-driven capability database. - Auto-detection: The advanced engine is automatically activated by the presence of the 'MCU' directive in hwdef.dat. - Backward Compatibility: Full support for current master 'ESP32_...' syntax ensures zero breakage for existing boards. - Dynamic sdkconfig: Added support for generating board-specific settings (FLASH_SIZE_MB, PSRAM_SIZE) into a generated 'sdkconfig.board' file, reducing reliance on shared templates. - Partition Table Support: Automated copying of custom partition tables from board directories. - RISC-V Support: Integrated toolchain selection logic for ESP32-C3, C6, and P4 variants in boards.py. - Feature Flags: Introduced C++ capability defines (e.g., HAL_ESP32_HAS_MCPWM) triggered by the hardware database. - Documentation: Added MIGRATION.md detailing the 'MCU' upgrade path. Relates to #30709
1 parent 46ae785 commit e295322

File tree

3 files changed

+433
-664
lines changed

3 files changed

+433
-664
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ESP32 Board Migration Guide: Upgrading to Advanced Build Logic
2+
3+
This document outlines how to upgrade an ESP32 board from the "Simple" V1 build system (current master) to the "Advanced" V2 system.
4+
5+
## 1. The V2 Activation Trigger
6+
7+
The build system automatically detects which logic to use based on your `hwdef.dat`.
8+
9+
* **V1 Mode (Compatibility):** If the `MCU` directive is **missing**, the script emulates current master behavior. It accepts existing `ESP32_...` syntax and relies on static environment templates.
10+
* **V2 Mode (Advanced):** Adding the `MCU` directive (e.g., `MCU ESP32S3`) activates the advanced data-driven engine.
11+
12+
## 2. Benefits of Upgrading to V2
13+
14+
By adding the `MCU` tag, you unlock several features without needing to change your existing pin configuration:
15+
16+
1. **Dynamic sdkconfig:** You can add `FLASH_SIZE_MB 8` or `PSRAM_SIZE 4MB` directly to `hwdef.dat`, eliminating the need for manual background template edits.
17+
2. **Strict Validation:** Every pin assignment is checked against a chip capability database to catch conflicts and "impossible" assignments at compile time.
18+
3. **RISC-V Support:** Enables builds for ESP32-C3, C6, and P4 variants using the same syntax.
19+
4. **Feature Flags:** Automatically defines C++ capability flags (e.g., `HAL_ESP32_HAS_MCPWM`) based on the detected hardware.
20+
21+
## 3. Migration Steps
22+
23+
### Step 1: Add the MCU Directive
24+
Add the target chip type to the top of your `hwdef.dat`:
25+
```bash
26+
MCU ESP32S3 # Options: ESP32, ESP32S2, ESP32S3, ESP32C3, ESP32C6, ESP32P4
27+
```
28+
29+
### Step 2: Migrate Board-Specific Configuration (Optional)
30+
Previously, board-specific settings like Flash size and PSRAM were often hardcoded in the shared `sdkconfig.defaults` for a whole chip family. These should now be moved to each board's `hwdef.dat`:
31+
32+
```bash
33+
FLASH_SIZE_MB 8
34+
PSRAM_SIZE 4MB
35+
```
36+
37+
The build system will generate a board-specific `sdkconfig.board` in the build directory that contains these values, ensuring correct hardware support without manual template edits.
38+
39+
*(No other tag changes are required, though you can now also use the `RESERVED_PINS` directive for extra safety).*
40+
41+
## 4. Verification
42+
1. Run: `./waf configure --board=<yourboard>`
43+
2. Verify `build/hwdef.h` contains the `#define HAL_ESP32_HWDEF_V2 1` flag.
44+
3. Check that hardware features (like `HAL_ESP32_HAS_MCPWM`) are correctly defined for your chip.
45+
4. Build: `./waf copter`.

0 commit comments

Comments
 (0)