【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
相关推荐
桑榆肖物5 天前
手搓开机棒:使用.Net nanoFramework 实现WOL唤醒远程开机
.net·esp32
skywalk81637 天前
使用 ESP-IDF 进行esp32-c3开发第四步:VSCode里安装ESP-IDF插件
ide·vscode·物联网·编辑器·esp32
茴香豆的茴8 天前
基于ESP32的桌面小屏幕实战[4]:硬件设计之PCB Layout
esp32·嵌入式开源项目
skywalk81639 天前
奇怪的知识又增加了:ESP32下的Lisp编程=>ULisp--Lisp for microcontrollers
开发语言·单片机·物联网·esp32·lisp
优信电子22 天前
ESP32驱动PCM5102A播放SD卡音频
音视频·esp32·pcm5102a·esp32音频
smallerxuan1 个月前
在Ubuntu2004中搭建基于ESP-IDF v5.1的ESP32-S3开发环境
esp32
启明云端wireless-tag1 个月前
乐鑫ESP32物联网方案,设备人机交互技术应用,启明云端乐鑫代理商
物联网·esp32·无线通信·乐鑫
skywalk81631 个月前
esp32c3开发板通过micropython的mqtt库连MQTT物联网消息服务器
单片机·物联网·mqtt·esp32·micropython
flashier1 个月前
ESP32学习笔记_FreeRTOS(1)——Task的创建和使用
c语言·开发语言·笔记·学习·esp32
T0uken1 个月前
【ESP32+MicroPython】硬件控制基础
python·单片机·嵌入式硬件·esp32