【ESP32】Ubuntu2004搭建espressif

文章目录

环境

ubuntu2004

SDK目录:~/SDK/esp/esp-idf

官方参考给的文档是 ~/esp/esp-idf

流程概述

  1. 安装依赖
  2. 下载SDK
  3. 下载管理工具
    2.1 修改下载源
    2.2 下载、管理toolchain
    2.3 下载、管理子库
    2.4 etc
  4. 复制工程验证环境

一、安装依赖

二、下载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 版本
下载源码、编译、安装、替换链接、校验

URL: https://cmake.org/files/

下载文件: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++

附录

  1. 参考:https://gitee.com/EspressifSystems/esp-gitee-tools
  2. 参考:https://gitee.com/EspressifSystems/esp-idf
相关推荐
田三番1 天前
使用 vscode 简单配置 ESP32 连接 Wi-Fi 每日定时发送 HTTP 和 HTTPS 请求
单片机·物联网·http·https·嵌入式·esp32·sntp
T0uken2 天前
【ESP32+MicroPython】网络编程基础
网络·python·esp32
e调布鲁斯4 天前
esp32cam+Arduino IDE在编译时提示找不到 esp_camera.h 的解决办法
esp32·arduino
启明云端wireless-tag5 天前
ESP-IDF HTTP POST请求发送音频-启明云端乐鑫代理商
http·音视频·esp32·物联网开发
乐鑫科技 Espressif6 天前
ESP-HaloPanel:用 ESP32-C2 打造超低成本智能家居面板
esp32·智能家居·wi-fi
WKJay_8 天前
【ESP32S3】VSCode 开发环境搭建
wifi·esp32·ble
MonkeyKing_sunyuhua14 天前
ubuntu22.04 桌面系统怎么搭建一个esp-idf的项目,搭建开发环境
esp-idf
zhangrelay15 天前
Arduino-ESP32机器人控制器设计练习题汇总
机器人·esp32
柔贝特三哥15 天前
ESP32 S3 语音识别 语音唤醒程序流程
人工智能·esp32·语音识别·esp-idf·ai对话·语音唤醒·语音命令
事在人wёi24 天前
VSCode esp-idf环境搭建 报错 ERROR_INVALID_PIP
vscode·esp-idf