AgentSkillsCN

ESP-IDF Target Management

严格校验并管理 IDF 构建目标(如 esp32、esp32s3 等),以避免芯片不匹配错误及无谓的重新构建周期。

SKILL.md
--- frontmatter
name: ESP-IDF Target Management
description: Verify and manage the IDF build target (esp32, esp32s3, etc.) to avoid chip mismatch errors and wasted rebuild cycles

ESP-IDF Target Management

When to Use

  • Before any idf.py build or idf.py flash command
  • After running idf.py fullclean (which wipes the target setting)
  • When flashing fails with "Wrong chip argument"
  • When switching between different ESP32 variants

Step 1: Check Current Target

Before building, always verify the current target:

powershell
// turbo
$cmakeCache = "build\CMakeCache.txt"
if (Test-Path $cmakeCache) {
    $target = (Select-String "IDF_TARGET:INTERNAL=(.+)" $cmakeCache).Matches.Groups[1].Value
    Write-Host "Current IDF target: $target"
} else {
    Write-Host "WARNING: No CMakeCache.txt found - target is not set. Run set-target first."
}

Step 2: Set Target (Only If Needed)

Only run set-target if the target is wrong or unset. Note: set-target internally runs fullclean — it will wipe the entire build directory.

powershell
& '<profile>'; idf.py set-target esp32s3

CRITICAL: set-target output is very long. The terminal will show the fullclean portion first, then a CMake configure. The truncated output may only show fullclean — this does NOT mean it failed. Always verify by checking CMakeCache.txt afterward.

Step 3: Verify Target Was Set

After set-target completes, confirm the target before proceeding:

powershell
// turbo
$cmakeCache = "build\CMakeCache.txt"
if (Test-Path $cmakeCache) {
    $target = (Select-String "IDF_TARGET:INTERNAL=(.+)" $cmakeCache).Matches.Groups[1].Value
    if ($target -eq "esp32s3") {
        Write-Host "Target confirmed: $target"
    } else {
        Write-Host "ERROR: Target is '$target', expected 'esp32s3'"
    }
} else {
    Write-Host "ERROR: CMakeCache.txt not found after set-target"
}

Step 4: Build and Flash

Only proceed with build+flash after target is confirmed:

powershell
& '<profile>'; idf.py build flash monitor

Common Gotchas

ProblemCauseFix
"Wrong chip argument" on flashBinary built for esp32 but device is esp32s3Run set-target esp32s3 then rebuild
set-target appears to only run fullcleanTruncated terminal output — configure ran but wasn't shownCheck build/CMakeCache.txt for IDF_TARGET
Target resets to esp32 after fullcleanfullclean removes the target setting fileAlways run set-target after fullclean
COM port locked during flashPrevious idf.py monitor still holding the portKill the previous terminal/process first

Quick Reference: Project Default Target

This project targets esp32s3 (Waveshare ESP32-S3-Touch-AMOLED-1.8).