Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/esp32-p4-evboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
],
"f_cpu": "360000000L",
"f_flash": "80000000L",
"f_psram": "200000000L",
"flash_mode": "qio",
"mcu": "esp32p4",
"variant": "esp32p4"
Expand Down
1 change: 1 addition & 0 deletions boards/esp32-p4.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
],
"f_cpu": "360000000L",
"f_flash": "80000000L",
"f_psram": "200000000L",
"flash_mode": "qio",
"mcu": "esp32p4",
"variant": "esp32p4"
Expand Down
1 change: 1 addition & 0 deletions boards/m5stack-tab5-p4.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"f_cpu": "360000000L",
"f_flash": "80000000L",
"f_psram": "200000000L",
"flash_mode": "qio",
"mcu": "esp32p4",
"variant": "m5stack_tab5"
Expand Down
174 changes: 107 additions & 67 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,20 @@ def generate_board_specific_config():
if f_cpu:
cpu_freq = str(f_cpu).replace("000000L", "")
board_config_flags.append(f"CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ={cpu_freq}")

# MCU name mapping for config flags (uppercase MCU name)
mcu_upper = mcu.upper().replace("-", "")

# Disable other CPU frequency options and enable the specific one
common_cpu_freqs = ["80", "160", "240"]
for freq in common_cpu_freqs:
if freq != cpu_freq:
if mcu == "esp32":
board_config_flags.append(f"# CONFIG_ESP32_DEFAULT_CPU_FREQ_{freq} is not set")
elif mcu in ["esp32s2", "esp32s3"]:
board_config_flags.append(f"# CONFIG_ESP32S2_DEFAULT_CPU_FREQ_{freq} is not set" if mcu == "esp32s2" else f"# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_{freq} is not set")
elif mcu in ["esp32c2", "esp32c3", "esp32c6"]:
board_config_flags.append(f"# CONFIG_ESP32C3_DEFAULT_CPU_FREQ_{freq} is not set")
# Enable the specific CPU frequency
if mcu == "esp32":
board_config_flags.append(f"CONFIG_ESP32_DEFAULT_CPU_FREQ_{cpu_freq}=y")
elif mcu == "esp32s2":
board_config_flags.append(f"CONFIG_ESP32S2_DEFAULT_CPU_FREQ_{cpu_freq}=y")
elif mcu == "esp32s3":
board_config_flags.append(f"CONFIG_ESP32S3_DEFAULT_CPU_FREQ_{cpu_freq}=y")
elif mcu in ["esp32c2", "esp32c3", "esp32c6"]:
board_config_flags.append(f"CONFIG_ESP32C3_DEFAULT_CPU_FREQ_{cpu_freq}=y")
board_config_flags.append(f"# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_{freq} is not set")
board_config_flags.append(f"# CONFIG_{mcu_upper}_DEFAULT_CPU_FREQ_{freq} is not set")

# Enable the specific CPU frequency (both generic and MCU-specific)
board_config_flags.append(f"CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_{cpu_freq}=y")
board_config_flags.append(f"CONFIG_{mcu_upper}_DEFAULT_CPU_FREQ_{cpu_freq}=y")

# Set flash size with platformio.ini override support
# Priority: platformio.ini > board.json manifest
Expand Down Expand Up @@ -434,53 +429,83 @@ def generate_board_specific_config():
if not f_boot:
f_boot = board.get("build.f_boot", None)

# Get f_psram with override support (ESP32-P4 specific)
f_psram = None
if hasattr(env, 'GetProjectOption'):
try:
f_psram = env.GetProjectOption("board_build.f_psram", None)
except:
pass
if not f_psram:
f_psram = board.get("build.f_psram", None)

# Determine the frequencies to use
esptool_flash_freq = f_flash # Always use f_flash for esptool compatibility
compile_freq = f_boot if f_boot else f_flash # Use f_boot for compile-time if available
# ESP32-P4: f_flash for Flash, f_psram for PSRAM (doesn't affect bootloader name)

if mcu == "esp32p4":
# ESP32-P4: f_flash is always used for Flash frequency
# f_psram is used for PSRAM frequency (if set), otherwise use f_flash
# Note: f_boot is NOT used for P4 as it affects bootloader filename
flash_compile_freq = f_flash
psram_compile_freq = f_psram if f_psram else f_flash
else:
# Other chips: f_boot overrides f_flash for compile-time (both Flash and PSRAM)
compile_freq = f_boot if f_boot else f_flash
flash_compile_freq = compile_freq
psram_compile_freq = compile_freq

if f_flash and compile_freq:
# Ensure frequency compatibility (>= 80MHz must be identical for Flash and PSRAM)
compile_freq_val = int(str(compile_freq).replace("000000L", ""))
if f_flash and flash_compile_freq and psram_compile_freq:
# Validate and parse frequency values
try:
flash_freq_val = int(str(flash_compile_freq).replace("000000L", ""))
psram_freq_val = int(str(psram_compile_freq).replace("000000L", ""))
except (ValueError, AttributeError):
print("Warning: Invalid frequency values, skipping frequency configuration")
flash_freq_val = None
psram_freq_val = None

if compile_freq_val >= 80:
# Above 80MHz, both Flash and PSRAM must use same frequency
unified_freq = compile_freq_val
flash_freq_str = f"{unified_freq}m"
psram_freq_str = str(unified_freq)
if flash_freq_val and psram_freq_val:
# Determine frequency strings
flash_freq_str = f"{flash_freq_val}m"
psram_freq_str = str(psram_freq_val)

print(f"Info: Unified frequency mode (>= 80MHz): {unified_freq}MHz for both Flash and PSRAM")
else:
# Below 80MHz, frequencies can differ
flash_freq_str = str(compile_freq).replace("000000L", "m")
psram_freq_str = str(compile_freq).replace("000000L", "")
# Info message
if mcu == "esp32p4":
print(f"Info: ESP32-P4 frequency mode: Flash={flash_freq_val}MHz, PSRAM={psram_freq_val}MHz")
elif flash_freq_val >= 80:
print(f"Info: Unified frequency mode (>= 80MHz): {flash_freq_val}MHz for both Flash and PSRAM")
else:
print(f"Info: Independent frequency mode (< 80MHz): Flash={flash_freq_str}, PSRAM={psram_freq_str}")

print(f"Info: Independent frequency mode (< 80MHz): Flash={flash_freq_str}, PSRAM={psram_freq_str}")

# Configure Flash frequency
# Disable other flash frequency options first
flash_freqs = ["20m", "26m", "40m", "80m", "120m"]
for freq in flash_freqs:
if freq != flash_freq_str:
board_config_flags.append(f"# CONFIG_ESPTOOLPY_FLASHFREQ_{freq.upper()} is not set")
# Then set the specific frequency configs
board_config_flags.append(f"CONFIG_ESPTOOLPY_FLASHFREQ=\"{flash_freq_str}\"")
board_config_flags.append(f"CONFIG_ESPTOOLPY_FLASHFREQ_{flash_freq_str.upper()}=y")

# Configure PSRAM frequency (same as Flash for >= 80MHz)
# Disable other SPIRAM speed options first
psram_freqs = ["40", "80", "120"]
for freq in psram_freqs:
if freq != psram_freq_str:
board_config_flags.append(f"# CONFIG_SPIRAM_SPEED_{freq}M is not set")
# Then set the specific SPIRAM configs
board_config_flags.append(f"CONFIG_SPIRAM_SPEED={psram_freq_str}")
board_config_flags.append(f"CONFIG_SPIRAM_SPEED_{psram_freq_str}M=y")

# Enable experimental features for frequencies > 80MHz
if compile_freq_val > 80:
board_config_flags.append("CONFIG_IDF_EXPERIMENTAL_FEATURES=y")
board_config_flags.append("CONFIG_SPI_FLASH_HPM_ENABLE=y")
board_config_flags.append("CONFIG_SPI_FLASH_HPM_AUTO=y")
# Configure Flash frequency
# Disable other flash frequency options first
flash_freqs = ["20m", "26m", "40m", "80m", "120m"]
for freq in flash_freqs:
if freq != flash_freq_str:
board_config_flags.append(f"# CONFIG_ESPTOOLPY_FLASHFREQ_{freq.upper()} is not set")
# Then set the specific frequency configs
board_config_flags.append(f"CONFIG_ESPTOOLPY_FLASHFREQ=\"{flash_freq_str}\"")
board_config_flags.append(f"CONFIG_ESPTOOLPY_FLASHFREQ_{flash_freq_str.upper()}=y")

# ESP32-P4 requires additional FLASHFREQ_VAL setting
if mcu == "esp32p4":
board_config_flags.append(f"CONFIG_ESPTOOLPY_FLASHFREQ_VAL={flash_freq_val}")

# Configure PSRAM frequency
# Disable other SPIRAM speed options first
psram_freqs = ["20", "40", "80", "120", "200"]
for freq in psram_freqs:
if freq != psram_freq_str:
board_config_flags.append(f"# CONFIG_SPIRAM_SPEED_{freq}M is not set")
# Then set the specific SPIRAM configs
board_config_flags.append(f"CONFIG_SPIRAM_SPEED={psram_freq_str}")
board_config_flags.append(f"CONFIG_SPIRAM_SPEED_{psram_freq_str}M=y")

# Enable experimental features for Flash frequencies > 80MHz
if flash_freq_val > 80:
board_config_flags.append("CONFIG_IDF_EXPERIMENTAL_FEATURES=y")
board_config_flags.append("CONFIG_SPI_FLASH_HPM_ENABLE=y")
board_config_flags.append("CONFIG_SPI_FLASH_HPM_AUTO=y")

# Check for PSRAM support based on board flags
extra_flags = board.get("build.extra_flags", [])
Expand All @@ -497,9 +522,6 @@ def generate_board_specific_config():
# Check for SPIRAM mentions in extra_flags
elif any("SPIRAM" in str(flag) for flag in extra_flags):
has_psram = True
# For ESP32-S3, assume PSRAM capability (can be disabled later if not present)
elif mcu == "esp32s3":
has_psram = True

if has_psram:
# Enable basic SPIRAM support
Expand All @@ -524,13 +546,21 @@ def generate_board_specific_config():
# Priority 3: Check build.psram_type field as fallback
elif not psram_type and "psram_type" in board.get("build", {}):
psram_type = board.get("build.psram_type", "qio").lower()
# Priority 4: Default to qio
# Priority 4: Default based on MCU
elif not psram_type:
psram_type = "qio"
# ESP32-P4 defaults to HEX (only type available)
if mcu == "esp32p4":
psram_type = "hex"
else:
psram_type = "qio"

# Configure PSRAM mode based on detected type
if psram_type == "opi":
# Octal PSRAM configuration (for ESP32-S3 only)
if psram_type == "hex":
# HEX PSRAM configuration (ESP32-P4 only)
board_config_flags.append("CONFIG_SPIRAM_MODE_HEX=y")

elif psram_type == "opi":
# Octal PSRAM configuration (for ESP32-S3)
if mcu == "esp32s3":
board_config_flags.extend([
"CONFIG_IDF_EXPERIMENTAL_FEATURES=y",
Expand All @@ -539,7 +569,7 @@ def generate_board_specific_config():
"CONFIG_SPIRAM_TYPE_AUTO=y"
])
else:
# Fallback to QUAD for non-S3 chips
# Fallback to QUAD for other chips
board_config_flags.extend([
"# CONFIG_SPIRAM_MODE_OCT is not set",
"CONFIG_SPIRAM_MODE_QUAD=y"
Expand All @@ -557,13 +587,21 @@ def generate_board_specific_config():
"# CONFIG_SPIRAM_MODE_OCT is not set",
"# CONFIG_SPIRAM_MODE_QUAD is not set"
])
else:
# Explicitly disable PSRAM if not present
board_config_flags.extend([
"# CONFIG_SPIRAM is not set"
])

# Use flash_memory_type for flash config
if flash_memory_type and "opi" in flash_memory_type.lower():
# OPI Flash configurations require specific settings
# According to ESP-IDF documentation, OPI flash must use DOUT mode for bootloader
# The bootloader starts in DOUT mode and switches to OPI at runtime
# Reference: ESP-IDF Programming Guide - SPI Flash Configuration
board_config_flags.extend([
"# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set",
"# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set",
"# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set",
"# CONFIG_ESPTOOLPY_FLASHMODE_DIO is not set",
"CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y",
"CONFIG_ESPTOOLPY_OCT_FLASH=y",
Expand Down Expand Up @@ -2522,7 +2560,9 @@ def _skip_prj_source_files(node):
#

ulp_dir = str(Path(PROJECT_DIR) / "ulp")
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32h2"):
# ULP support: ESP32, ESP32-S2, ESP32-S3, ESP32-C6, ESP32-P4
# No ULP: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-H2
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32c5", "esp32h2"):
env.SConscript("ulp.py", exports="env sdk_config project_config app_includes idf_variant")

#
Expand Down