【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
相关推荐
xiaohai@Linux3 天前
ESP32 在IDF_V5.3.1版本下实现AP无线热点模式!(带WIFI事件处理)
c语言·嵌入式硬件·tcp/ip·wifi·esp32
乐鑫科技 Espressif3 天前
解锁 AIoT 无限可能,乐鑫邀您共赴 Embedded World 2025
esp32·wi-fi·iot·乐鑫科技·embedded world
深圳启明云端科技7 天前
ESP32无线Wi-Fi蓝牙方案,设备智能连接控制,物联网通信应用
物联网·esp32·芯片·乐鑫·模组·无线方案
PassLink_12 天前
ESP32S3(主模式) 与 STM32(从模式) 进行SPI全双工通信
stm32·单片机·嵌入式硬件·esp32·spi
生活最重要(ง •̀_•́)ง13 天前
[ESP32:Vscode+PlatformIO]添加第三方库 开源库 与Arduino导入第三方库的区别
esp32·arduino·第三方库·开源库·platformio
生活最重要(ง •̀_•́)ง20 天前
[ESP32:Vscode+PlatformIO]新建工程 常用配置与设置
vscode·esp32·arduino·platformio
Android小码家1 个月前
ESP32-CAM导入ino项目编译和烧录
esp32
芜湖_1 个月前
CLion入门2.0(优雅进行STM32和ESP32开发)(船新版本)
stm32·esp32·开发环境·clion
大专生学编程1 个月前
基于ESP32-IDF驱动GPIO输出控制LED
嵌入式硬件·esp32·esp-idf
豆奶豆豆奶1 个月前
【ESP32】ESP32连接JY61P并通过WIFI发送给电脑
esp32·esp32 wifi