文章目录
- 环境
- 流程概述
- 一、安装依赖
- 二、下载SDK、管理工具
-
- [1. 管理工具下载](#1. 管理工具下载)
- [2. 下载SDK](#2. 下载SDK)
- 三、安装toolchain、更新子库、配置SDK环境
-
- [1. 替换下载源,安装虚拟环境等等](#1. 替换下载源,安装虚拟环境等等)
- [2. 更新子库](#2. 更新子库)
- [3. 配置SDK环境](#3. 配置SDK环境)
- 四、复制例程验证环境
- 问题汇总
-
- [1. CMake 版本低](#1. CMake 版本低)
- [2. 编译cmake源码时提示无g++编译器](#2. 编译cmake源码时提示无g++编译器)
- 附录
环境
ubuntu2004
SDK目录:~/SDK/esp/esp-idf
官方参考给的文档是 ~/esp/esp-idf
流程概述
- 安装依赖
- 下载SDK
- 下载管理工具
2.1 修改下载源
2.2 下载、管理toolchain
2.3 下载、管理子库
2.4 etc - 复制工程验证环境
一、安装依赖
略
二、下载SDK、管理工具
1. 管理工具下载
repo:https://gitee.com/EspressifSystems/esp-gitee-tools.git
bash
mkdir -p ~/SDK/esp
cd ~/SDK
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
2. 下载SDK
repo:https://gitee.com/EspressifSystems/esp-idf.git
bash
cd ~/SDK
git clone https://gitee.com/EspressifSystems/esp-idf.git、
mv esp-idf/ esp/
要特定分支就切一下版本
三、安装toolchain、更新子库、配置SDK环境
1. 替换下载源,安装虚拟环境等等
bash
cd ~/SDK/esp-gitee-tools
export EGT_PATH=$(pwd)
echo $EGT_PATH
cd ~/SDK/esp/esp-idf
$EGT_PATH/install.sh
参考log如下:
bash
Detecting Python interpreter
Checking "python3" ...
Checking "python3.8" ...
Python 3.8.0
"python3.8" has been detected
Installing ESP-IDF tools
Updating /home/liam/.espressif/idf-env.json
Selected targets are: esp32c3, esp32c5, esp32s3, esp32, esp32h2, esp32c2, esp32s2, esp32p4, esp32c6
Current system platform: linux-amd64
Installing tools: xtensa-esp-elf-gdb, riscv32-esp-elf-gdb, xtensa-esp-elf, riscv32-esp-elf, esp32ulp-elf, openocd-esp32, esp-rom-elfs
Installing xtensa-esp-elf-gdb@12.1_20231023
Downloading https://dl.espressif.com/github_assets/espressif/binutils-gdb/releases/download/esp-gdb-v12.1_20231023/xtensa-esp-elf-gdb-12.1_20231023-x86_64-linux-gnu.tar.gz
Destination: /home/liam/.espressif/dist/xtensa-esp-elf-gdb-12.1_20231023-x86_64-linux-gnu.tar.gz.tmp
Done
Extracting /home/liam/.espressif/dist/xtensa-esp-elf-gdb-12.1_20231023-x86_64-linux-gnu.tar.gz to /home/liam/.espressif/tools/xtensa-esp-elf-gdb/12.1_20231023
Installing riscv32-esp-elf-gdb@12.1_20231023
Downloading https://dl.espressif.com/github_assets/espressif/binutils-gdb/releases/download/esp-gdb-v12.1_20231023/riscv32-esp-elf-gdb-12.1_20231023-x86_64-linux-gnu.tar.gz
Destination: /home/liam/.espressif/dist/riscv32-esp-elf-gdb-12.1_20231023-x86_64-linux-gnu.tar.gz.tmp
74%
...
Creating a new Python environment in /home/liam/.espressif/python_env/idf5.3_py3.8_env
Upgrading pip and setuptools...
Collecting pip
Downloading https://files.pythonhosted.org/packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl (2.1MB)
32% |██████████▎ | 675kB 7.4kB/s eta 0:03:13
...
等待一会儿,让他自己下自己装
2. 更新子库
bash
$EGT_PATH/submodule-update.sh
参考log:
bash
Submodule 'components/bt/controller/lib_esp32c3_family' (https://gitee.com/espressif/esp32c3-bt-lib.git) registered for path 'components/bt/controller/lib_esp32c3_family'
Submodule 'components/bt/controller/lib_esp32c6/esp32c6-bt-lib' (https://gitee.com/espressif/esp32c6-bt-lib.git) registered for path 'components/bt/controller/lib_esp32c6/esp32c6-bt-lib'
Submodule 'components/bt/controller/lib_esp32h2/esp32h2-bt-lib' (https://gitee.com/espressif/esp32h2-bt-lib.git) registered for path 'components/bt/controller/lib_esp32h2/esp32h2-bt-lib'
Submodule 'components/bt/esp_ble_mesh/lib/lib' (https://gitee.com/espressif/esp-ble-mesh-lib.git) registered for path 'components/bt/esp_ble_mesh/lib/lib'
Submodule 'components/bt/host/nimble/nimble' (https://gitee.com/espressif/esp-nimble.git) registered for path 'components/bt/host/nimble/nimble'
Submodule 'components/cmock/CMock' (https://gitee.com/ThrowTheSwitch/CMock.git) registered for path 'components/cmock/CMock'
...
Cloning into '/home/liam/SDK/esp/esp-idf/components/bt/controller/lib_esp32h2/esp32h2-bt-lib'...
remote: Enumerating objects: 100, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 100 (delta 38), reused 0 (delta 0), pack-reused 37
Receiving objects: 100% (100/100), 6.37 MiB | 502.00 KiB/s, done.
Resolving deltas: 100% (47/47), done.
Cloning into '/home/liam/SDK/esp/esp-idf/components/bt/esp_ble_mesh/lib/lib'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 24 (delta 2), reused 24 (delta 2), pack-reused 0
...
3. 配置SDK环境
每次新shell中更新环境变量:在shell rc中价格别称,添加esp-ief/export.sh环境
bash
vi ~/.bashrc
# Add :
alias get_idf='. $HOME/SDK/esp/esp-idf/export.sh'
更新shell环境,验证esp环境配置
bash
source ~/.bashrc
get_idf
参考log:
bash
Setting IDF_PATH to 'xxxxxxx/SDK/esp/esp-idf'
Detecting the Python interpreter
Checking "python3" ...
Checking "python3.8" ...
Python 3.8.0
"python3.8" has been detected
Checking Python compatibility
Checking other ESP-IDF version.
Adding ESP-IDF tools to PATH...
Checking if Python packages are up to date...
...
Added the following directories to PATH:
...
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:
idf.py build
四、复制例程验证环境
例程:~/SDK/esp/esp-idf/examples/get-started/hello_world
创个文件夹,把例程复制过来,更新下SDK环境,开始编译
bash
mkdir -p ~/tmp/esp
cp -rf ~/SDK/esp/esp-idf/examples/get-started/hello_world ~/tmp/esp/
cd ~/tmp/esp/hello_world/
get_idf
idf.py build
//idf.py set-target esp32s3 // 看个人需求
编译不报错即可。
参考log:
bash
...
[100%] Built target hello_world.elf
[100%] Generating binary image from built executable
esptool.py v4.7.0
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
Generated /xxxxx/tmp/hello_world/build/hello_world.bin
[100%] Built target gen_project_binary
hello_world.bin binary size 0x2aa40 bytes. Smallest app partition is 0x100000 bytes. 0xd55c0 bytes (83%) free.
[100%] Built target app_check_size
[100%] Built target app
Project build complete. To flash, run this command:
/xxx/.espressif/python_env/idf5.1_py3.8_env/bin/python ../../SDK/esp/esp-idf/components/esptool_py/esptool/esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size 2MB --flash_freq 40m 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello_world.bin
or run 'idf.py -p (PORT) flash'
xxx@ubuntu:~/tmp/hello_world$
问题汇总
1. CMake 版本低
设置编译目标时,提示cmake版本低
Make 3.16 or higher is required. You are running version 3.10.2
fix:更新cmake 版本
下载源码、编译、安装、替换链接、校验下载文件:https://cmake.org/files/v3.28/cmake-3.28.1.tar.gz
解压、编译、安装
bash
cd ~/tmp/
wget https://cmake.org/files/v3.22/cmake-3.28.1.tar.gz // 看个人需求变更版本
tar -zxvf cmake-3.28.1.tar.gz
cd cmake-3.28.1/
# chmod 777 configure
./configure // 需要g++编译器,注意安装
make
sudo make install
# 更新链接
sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
校验版本
bash
cmake --version
2. 编译cmake源码时提示无g++编译器
如题
fix:安装g++
sudo apt install g++