【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
相关推荐
听我一言10 天前
ESP32-WROOM-32 [创建AP站点-TCP服务端-数据收发]
esp32
听我一言12 天前
ESP32-WROOM-32 [ESP连接路由器+TCP Client 透传 + TCP Server数据发送]
网络·网络协议·tcp/ip·esp32
听我一言13 天前
ESP32-WROOM-32 [创建AP站点-客户端-TCP透传]
网络·网络协议·tcp/ip·esp32
康de哥14 天前
使用SonarQube扫描ESP32项目,如何生成build-wrapper-dump.json
esp32·sonarqube·idf·build-wrapper
启明云端wireless-tag15 天前
ESP32无线WiFi蓝牙SOC,设备物联网通信方案,启明云端乐鑫代理商
嵌入式硬件·物联网·wifi·esp32·乐鑫·wifi模组
启明云端wireless-tag1 个月前
ESP32无线WiFi芯片模组,设备物联网连接通信,产品智能化交互升级
物联网·esp32·智能家居·乐鑫·启明云端·设备升级
platform1 个月前
少走弯路,ESP32 读取Micro SD(TF)播放mp3的坑路历程。
esp32·蓝牙 歌词
启明云端wireless-tag1 个月前
智能儿童对讲机语音交互,乐鑫ESP-RTC音视频通信,ESP32无线语音方案
物联网·wifi·esp32·乐鑫·语音交互·wifi模组·对讲机
宁子希1 个月前
ESP32-S3 IDF框架 控制 WS2812 灯条:实现多种灯效
python·单片机·嵌入式硬件·esp32
帅得不敢出门1 个月前
ESP32-IDF http请求崩溃问题分析与解决
网络协议·http·esp32·c·开发板·乐鑫·esp32-idf