【Ubuntu】Ubuntu+VScode+ESP-IDF 的环境搭建
·
Ubuntu 下搭建 VScode + ESP-IDF 开发环境
安装必要的依赖工具 确保系统已安装 Python 3.8 或更高版本,推荐使用 Python 3.10。运行以下命令安装基础依赖:
sudo apt-get install git wget flex bison gperf python3 python3-pip cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
获取 ESP-IDF 工具链 使用官方安装脚本快速配置环境。以下命令会下载工具链并设置环境变量:
mkdir -p ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
./install.sh
配置环境变量 每次打开新终端时需要加载环境变量,将以下命令添加到 ~/.bashrc 文件末尾:
alias get_idf='. $HOME/esp/esp-idf/export.sh'
执行 source ~/.bashrc 后,通过 get_idf 命令即可激活环境。
安装 VScode 及扩展 从官网下载并安装 VScode。安装完成后添加必要扩展:
Espressif IDF(官方插件)C/C++(Microsoft 官方扩展)CMake Tools(CMake 支持)
配置 VScode 插件 打开 VScode 设置(Ctrl + ,),搜索 ESP-IDF: Custom Extra Paths,添加工具链路径:
$HOME/.espressif/tools
在命令面板(Ctrl + Shift + P)运行 ESP-IDF: Configure ESP-IDF extension,选择 Advanced 模式并指定 ESP-IDF 路径为 ~/esp/esp-idf。
创建测试项目 验证环境是否正常工作:
cd ~/esp
cp -r ~/esp/esp-idf/examples/get-started/hello_world .
cd hello_world
code .
在 VScode 中打开项目后,使用底部状态栏的 ESP-IDF: Build 按钮编译项目,通过 ESP-IDF: Select Device Port 选择串口后即可烧录程序。
常见问题处理 若遇到权限问题,将用户加入 dialout 组:
sudo usermod -a -G dialout $USER
需要注销后重新登录生效。若 CMake 报错,检查是否安装了正确版本的 ninja:
sudo apt install ninja-build
调试配置(可选) 在项目 .vscode/launch.json 中添加配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "espidf",
"name": "ESP-IDF Debug",
"request": "launch",
"mode": "auto",
"env": {"PATH": "${config:idf.customExtraPaths}"}
}
]
}
更多推荐


所有评论(0)