esp-idf-helper Skill
Provide a repeatable, command-line-first workflow for ESP-IDF development on Linux/WSL: configure → build → flash → monitor → debug/troubleshoot.
Quick Reference
CODEBLOCK0
Common commands
- -
idf.py --help — Help - INLINECODE1 — Set chip target: esp32, esp32s2, esp32s3, esp32c3, esp32p4
- INLINECODE2 — Configure project settings (must run in a new terminal window)
- INLINECODE3 — Build the project
- INLINECODE4 — Update project component dependencies
- INLINECODE5 — Build partition table and print partition entries
- INLINECODE6 — Flash partition table to device
- INLINECODE7 — Flash storage filesystem partition
- INLINECODE8 — Show firmware size information
- INLINECODE9 — Flash firmware (default baud: 460800)
- INLINECODE10 — Open serial monitor
- INLINECODE11 — Open serial monitor with specific baud (e.g. 460800)
- INLINECODE12 — Flash then monitor
Component Management
ESP-IDF projects can include external components from the ESP Component Registry.
- - Registry Website: https://components.espressif.com/components
- Search components: Browse or search for components on the registry website
Component Commands
- -
idf.py add-dependency "<component>" — Add a component dependency to INLINECODE14 - INLINECODE15 — Download and update all project dependencies
Component Management Workflow
CODEBLOCK1
Note: Dependencies are recorded in idf_component.yml in your project's main component directory (main/).
Bundled resources
references/
- -
references/esp-idf-cli.md — concise command patterns + what to paste back when reporting errors. - INLINECODE19 — captured
idf.py --help output for quick lookup/search.
To refresh the help text for your installed ESP-IDF version, run:
assets/
Not used by default.
Serial Port Management (WSL2)
For WSL2 users, USB serial devices need to be attached via usbipd to be accessible in WSL.
List Available Serial Devices
scripts/usbipd_attach_serial.sh --list
Shows all connected USB serial devices (CH340, CH343, CP210, FTDI, etc.).
Note: This script runs in WSL2 and uses powershell.exe to communicate with Windows usbipd.
Bind/Attach All Serial Devices
CODEBLOCK3
Serial Port Script Options
- -
--list — List all matching serial devices and exit - INLINECODE24 — Specify device bus ID (e.g.,
3-2) - INLINECODE26 — Filter devices by keyword (e.g.,
COM, CH343, ESP32) - INLINECODE30 — Bind only (skip attach), useful for first-time setup with admin privileges
- INLINECODE31 — Specify WSL distribution name
- INLINECODE32 — Print commands without executing
Typical Workflow
CODEBLOCK4
Note: This script runs in WSL2 and internally uses powershell.exe to communicate with Windows usbipd service.
Troubleshooting: powershell.exe not found
If you encounter powershell.exe: command not found, the Windows paths are not in your PATH environment variable.
Quick Fix (current session only):
CODEBLOCK5
Permanent Fix (add to ~/.bashrc):
CODEBLOCK6
Firmware Packaging
Pack ESP-IDF build output into a distributable firmware package with cross-platform flash scripts.
Usage
CODEBLOCK7
Example
CODEBLOCK8
Generated Package Contents
| File | Description |
|---|
| INLINECODE35 | Linux/Mac flash script with retry and parallel support |
| INLINECODE36 |
Windows multi-port flash launcher |
|
flash_one.bat | Windows single-port flash with retry |
|
mac_addresses.txt | Recorded MAC addresses (deduplicated) |
|
*.bin | Firmware binary files |
|
tools/esptool/esptool.exe | Windows esptool executable |
|
README.txt | Usage instructions |
Flash Script Features
- - Auto-retry: 3 attempts on failure
- Parallel flashing: Multiple devices simultaneously
- MAC recording: Automatic MAC address extraction and deduplication
- Cross-platform: Linux/Mac/Windows support
Production Workflow
CODEBLOCK9
esp-idf-helper 技能
提供在 Linux/WSL 上可重复执行的、以命令行优先的 ESP-IDF 开发工作流程:配置 → 构建 → 烧录 → 监控 → 调试/故障排查。
快速参考
bash
1) 加载 ESP-IDF 环境(每个终端会话只需执行一次)
. $IDF_PATH/export.sh
1.1) 启用 ccache 以加速编译(推荐)
export IDF
CCACHEENABLE=1
2) 进入项目目录并构建
cd /path/to/your/project
idf.py set-target
# 设置目标芯片(每个项目只需执行一次)
idf.py build # 编译
3) 烧录
idf.py -p -b flash # 烧录到设备(可选)
常用命令
- - idf.py --help — 帮助信息
- idf.py set-target — 设置芯片目标:esp32、esp32s2、esp32s3、esp32c3、esp32p4
- idf.py menuconfig — 配置项目设置(必须在新终端窗口中运行)
- idf.py build — 构建项目
- idf.py update-dependencies — 更新项目组件依赖
- idf.py partition-table — 构建分区表并打印分区条目
- idf.py partition-table-flash — 将分区表烧录到设备
- idf.py storage-flash — 烧录存储文件系统分区
- idf.py size — 显示固件大小信息
- idf.py -p -b flash — 烧录固件(默认波特率:460800)
- idf.py -p monitor — 打开串口监视器
- idf.py -p -b monitor — 以指定波特率打开串口监视器(例如 460800)
- idf.py -p -b flash monitor — 先烧录后监控
组件管理
ESP-IDF 项目可以包含来自 ESP 组件注册表 的外部组件。
- - 注册表网站: https://components.espressif.com/components
- 搜索组件: 在注册表网站上浏览或搜索组件
组件命令
- - idf.py add-dependency — 向 idf_component.yml 添加组件依赖
- idf.py update-dependencies — 下载并更新所有项目依赖
组件管理工作流程
bash
1) 向项目添加依赖
idf.py add-dependency
2) 更新依赖(将组件下载到 managed_components/ 目录)
idf.py update-dependencies
注意: 依赖项记录在项目主组件目录(main/)中的 idf_component.yml 文件中。
捆绑资源
references/ 目录
- - references/esp-idf-cli.md — 简洁的命令模式 + 报告错误时需要粘贴的内容。
- references/idf-py-help.txt — 捕获的 idf.py --help 输出,便于快速查找/搜索。
要刷新已安装 ESP-IDF 版本的帮助文本,请运行:
- - scripts/captureidfhelp.sh
assets/ 目录
默认情况下不使用。
串口管理(WSL2)
对于 WSL2 用户,需要通过 usbipd 连接 USB 串行设备,才能在 WSL 中访问。
列出可用串行设备
bash
scripts/usbipdattachserial.sh --list
显示所有已连接的 USB 串行设备(CH340、CH343、CP210、FTDI 等)。
注意: 此脚本在 WSL2 中运行,并使用 powershell.exe 与 Windows usbipd 通信。
绑定/连接所有串行设备
bash
绑定并连接所有 COM 端口设备
scripts/usbipdattachserial.sh --keyword COM
或通过 busid 连接特定设备
scripts/usbipdattachserial.sh --busid 3-2
或按设备类型过滤
scripts/usbipdattachserial.sh --keyword CH343
scripts/usbipdattachserial.sh --keyword ESP32
串口脚本选项
- - --list — 列出所有匹配的串行设备并退出
- --busid — 指定设备总线 ID(例如 3-2)
- --keyword — 按关键字过滤设备(例如 COM、CH343、ESP32)
- --bind — 仅绑定(跳过连接),适用于首次使用管理员权限设置
- --distro — 指定 WSL 发行版名称
- --dry-run — 打印命令但不执行
典型工作流程
bash
1. 检查可用设备
scripts/usbipdattachserial.sh --list
2. 连接所有串行设备
scripts/usbipdattachserial.sh --keyword COM
3. 在 WSL 中验证设备
ls -la /dev/ttyACM /dev/ttyUSB
4. 与 idf.py 一起使用
idf.py -p /dev/ttyACM0 flash monitor
注意: 此脚本在 WSL2 中运行,并在内部使用 powershell.exe 与 Windows usbipd 服务通信。
故障排查:找不到 powershell.exe
如果遇到 powershell.exe: command not found,说明 Windows 路径未包含在 PATH 环境变量中。
快速修复(仅当前会话):
bash
export PATH=$PATH:/mnt/c/Windows/System32:/mnt/c/Windows/System32/WindowsPowerShell/v1.0
~/skills/esp-idf-helper/scripts/usbipdattachserial.sh --list
永久修复(添加到 ~/.bashrc):
bash
echo export PATH=$PATH:/mnt/c/Windows/System32:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/SysWOW64 >> ~/.bashrc
source ~/.bashrc
固件打包
将 ESP-IDF 构建输出打包成可分发的固件包,并附带跨平台烧录脚本。
使用方法
bash
scripts/packfirmware.sh directory>
示例
bash
构建项目后
idf.py build
创建固件包
scripts/pack_firmware.sh ./build
输出:build/firmwarepackage/ 和 build/espfirmwareYYYYMMDDHHMMSS.zip
生成的包内容
| 文件 | 描述 |
|---|
| flash.sh | Linux/Mac 烧录脚本,支持重试和并行烧录 |
| flash.bat |
Windows 多端口烧录启动器 |
| flash_one.bat | Windows 单端口烧录脚本,支持重试 |
| mac_addresses.txt | 记录的 MAC 地址(去重后) |
| *.bin | 固件二进制文件 |
| tools/esptool/esptool.exe | Windows esptool 可执行文件 |
| README.txt | 使用说明 |
烧录脚本特性
- - 自动重试:失败时重试 3 次
- 并行烧录:同时烧录多个设备
- MAC 记录:自动提取并去重 MAC 地址
- 跨平台:支持 Linux/Mac/Windows
生产工作流程
bash
1. 构建项目
idf.py build
2. 打包固件
scripts/pack_firmware.sh ./build
3. 将 ZIP 分发给生产线
生产团队运行:flash.bat all(Windows)或 ./flash.sh /dev/ttyUSB*(Linux)