esp-idf开发环境搭建(ubuntu)

安装前置工作

  1. 非ubuntu系统安装ubuntu系统
  • Windows 系统
    • WSL2
    • 虚拟机
  • Mac 系统
    • OrbStack
    • 虚拟机
  1. 本地VSCode 安装
    2.1 VSCode 插件安装
  • Remote - SSH 用于连接ubuntu系统
  1. ubuntu 系统安装依赖
    1
    sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

安装 ESP-IDF 工具

0. 安装ESP工具

  • 为了解决国内开发者从 github 克隆 esp 相关仓库慢的问题,已将 esp-idf 和部分重要仓库及其关联的子模块镜像到了 jihu,这些仓库将自动从原始仓库进行同步。
  • 运行以下命令, 下载工具,并切换到jihu 镜像
    1
    2
    3
    git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
    cd esp-gitee-tools
    ./jihu-mirror.sh set
  • ./jihu-mirror.sh set 使用jihu 镜像
  • ./jihu-mirror.sh unset 取消jihu 镜像

1. 下载 ESP-IDF

1
2
3
mkdir -p ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git
  • --recursive 表示递归克隆子模块
  • 可使用 -b v5.4 下载指定版本

切换版本

默认为最新版本,无特殊要求可以不切换版本

1
2
git checkout v5.2.3
git submodule update --init --recursive
  • git submodule update --init --recursive 更新子模块

2. 安装 ESP-IDF 工具

Esp工具安装方式

目录

1
2
3
4
5
 ~/esp
L esp-idf
L esp-gitee-tools
# cd ~/esp/esp-idf
# ../install.sh
  • 在 esp-idf 目录下执行 esp-gitee-tools目录下的install.sh

官方安装方式

1
2
cd ~/esp/esp-idf
./install.sh all
  • export IDF_GITHUB_ASSETS="dl.espressif.cn/github_assets" 使用国内的下载服务器,以加快下载速度,** 本人安装时不管有没有配置都出现了403 错误 **
  • 如果需要指定工具安装路径可使用 export IDF_TOOLS_PATH="$HOME/required_idf_tools_path" ,默认为$HOME/.espressif
  • all 表示安装所有目标芯片,如果只要安装其中一个或多个可以手动指定,如:esp32,esp32s3

安装报错

403 错误

1
2
ERROR: HTTP error 403 while getting https://dl.espressif.cn/pypi/cffi/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (from https://dl.espressif.cn/pypi/cffi/)
ERROR: Could not install requirement cffi>=1.12 from https://dl.espressif.cn/pypi/cffi/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (from cryptography->-r /home/lyii/esp/esp-idf/tools/requirements/requirements.core.txt (line 13)) because of HTTP error 403 Client Error: Forbidden for url: https://dl.espressif.cn/pypi/cffi/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl for URL https://dl.espressif.cn/pypi/cffi/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (from https://dl.espressif.cn/pypi/cffi/)

解决办法:用梯子

3. 配置环境变量

此时,刚刚安装的工具尚未添加至 PATH 环境变量,无法通过“命令窗口”使用这些工具。因此,必须设置一些环境变量。这可以通过 ESP-IDF 提供的另一个脚本进行设置。

1
. ~/esp/esp-idf/export.sh

创建别名

  1. 复制并粘贴以下命令到 shell 配置文件中(.profile、.bashrc、.zprofile 等)
    1
    alias get_idf='. ~/esp/esp-idf/export.sh'
  2. 通过重启终端窗口或运行 source [path to profile],如 source ~/.bashrc 来刷新配置文件。

现在可以在任何终端窗口中运行 get_idf 来设置或刷新 ESP-IDF 环境。