阿里云ECS搭建ESP32开发环境

陈拓 2021/01/29-2021/02/03

1. 概述

在《用乐鑫国内Gitee镜像搭建ESP32开发环境》

https://zhuanlan.zhihu.com/p/348106034

https://blog.csdn.net/chentuo2000/article/details/113424934

一文中我们用乐鑫在国内的Gitee镜像搭建了ESP32开发环境,下面我们将ESP32的开发环境搭建到阿里云ECS服务器上。

2. 安装准备

https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/linux-setup.html

这一步,在《阿里云ECS搭建ESP8266_RTOS_SDK开发环境》

https://zhuanlan.zhihu.com/p/346975777

https://blog.csdn.net/chentuo2000/article/details/113173934

中已经做过了,可以看看其中的安装说明。

3. 获取 ESP-IDF

3.1 登录阿里云ECS

你可以使用Win10自带的ssh,也可以使用PuTTY,我用PuTTY。

查看阿里云上我的Linux系统版本:lsb_release -a

3.2 从github下载ESP-IDF

[https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/index.html#get-started-get-esp-idf]

3.2.1 下载ESP-IDF

git clone -b v4.2 --recursive https://github.com/espressif/esp-idf.git

ESP-IDF 将下载至 ~/esp/esp-idf

3.2.2 设置工具

除了 ESP-IDF 本身,您还需要安装 ESP-IDF 使用的各种工具,比如编译器、调试器、Python 包等。

cd ~/esp/esp-idf

./install.sh

提示pip可以升级,我们先不管它。

查看安装的工具:

ls -l ~/.espressif/tools

3.2.3 设置环境变量

  • 测试. $HOME/esp/esp-idf/export.sh

openocd-esp32没有安装。

  • 安装openocd

openOCD是一个用于JTAG调试的开源软件。为了更好地适配 ESP32,乐鑫对 OpenOCD 做了改动,命名为openocd-esp32。网址是github.com/espressif/openocd-esp32

要使用openocd-esp32必须通过源码编译安装,而我们现在在云端安装的开发工具并不能连接硬件进行JTAG调试,所以在这里我们安装一个标准的openocd,这样开发环境的安装工作就可以继续向下进行了

cd ~/esp

sudo yum install openocd

查看openocd是否已经安装:

yum list installed openocd

  • 再测试. $HOME/esp/esp-idf/export.sh

  • 将环境变量写入脚本文件

测试成功后,我们将这行代码增加至~/.bashrc或者.bash_profile脚本中,这样就不用每次登录执行它了。

可以在~/.bashrc或者~/.bash_profile中设置环境变量。.bashrc在每次执行shell脚本的时候都会重新读取,可以立即生效,而~/.bash_profile只在登录的时候才读取一次。

我们在这里使用~/.bash_profile

nano ~/.bash_profile

保存,退出。重新登录阿里云。

3.3 从乐鑫国内镜像gitee上下载ESP-IDF

从github上下载ESP-IDF很慢,不容易成功。现在从乐鑫国内镜像gitee上下载ESP-IDF,很快,但是有的麻烦。

3.3.1 网址

乐鑫已经在gitee上有了国内镜像,网址是:

https://gitee.com/EspressifSystems

3.3.2 安装方法

注意:Gitee ESP-IDF仓库的使用,请先参看https://gitee.com/EspressifSystems/esp-gitee-tools中的说明文档。

3.3.3 克隆 esp-idf

cd ~/esp

git clone https://gitee.com/EspressifSystems/esp-idf.git

ESP-IDF 将下载至 ~/esp/esp-idf。

注意:仅克隆 esp-idf,不包含子模块。即git 命令不带 --recursive 参数。

3.3.4 安装扩展工具esp-gitee-tools

在《阿里云ECS搭建ESP8266_RTOS_SDK开发环境》

https://zhuanlan.zhihu.com/p/346975777

https://blog.csdn.net/chentuo2000/article/details/113173934

一文中我们已经安装了扩展工具esp-gitee-tools

我们下面用esp-gitee-tools来安装esp-idf开发工具和子模块。

https://gitee.com/EspressifSystems/esp-gitee-tools/blob/master/docs/README-install.md

3.3.5 将pip源换到国内

查看我的pip版本:

pip 20.0.2 > 10.0.0

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple

pip config set global.trusted-host mirrors.aliyun.com

3.3.6 安装工具子模块

除了ESP-IDF本身,还需要安装ESP-IDF使用的各种工具,比如编译器、调试器、Python包等。

注意:不要使用ESP-IDF自带的install.sh,使用esp-gitee-tools内的 install.sh。

进入 esp-gitee-tools 目录,export install.sh 所在路径,方便后期使用:

cd ~/esp/esp-gitee-tools

export EGT_PATH=$(pwd)

测试环境变量:echo $EGT_PATH

进入 esp-idf 目录:

cd ~/esp/esp-idf

$EGT_PATH/install.sh

很快就安装安装完了。

3.3.7 安装更新子模块 submodules

$EGT_PATH/submodule-update.sh

安装顺利。

3.3.8 设置环境变量

见“3.2.3设置环境变量”。

4. 开始创建项目工程

https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/

cd ~/esp

cp -r esp-idf/examples/get-started/hello_world/ .

或者cp -r $IDF_PATH/examples/get-started/hello_world .

  • pip升级

/usr/bin/python -m pip install --upgrade pip

  • 安装 Python 依赖库

python -m pip install -r requirements.txt

5. 配置项目

https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/

cd ~/esp/hello_world

idf.py menuconfig

需要CMake 3.5或更高版本,当前版本为2.8.12.2

  • 升级CMake

1) 卸载原有的通过yum安装的cmake

yum remove cmake

2) 下载最新的cmake安装包

先看看最新版本:

https://github.com/Kitware/CMake/tags

下载1.19.4版本。

选择cmake-3.19.4-Linux-x86_64.tar.gz下载。

cd /opt

sudo wget https://github.com/Kitware/CMake/releases/download/v3.19.4/cmake-3.19.4-Linux-x86_64.tar.gz

3) 解压

sudo tar zxvf cmake-3.19.4-Linux-x86_64.tar.gz

4) 设置环境变量

sudo nano /etc/profile.d/cmake.sh

添加:

export CMAKE_HOME=/opt/cmake-3.19.4-Linux-x86_64

export PATH=$PATH:$CMAKE_HOME/bin

保存,退出。

5) 让 cmake 环境文件生效:source /etc/profile

6) 测试

cmake --version

  • 进入配置工具界面

cd ~/esp/hello_world

idf.py menuconfig

保持默认,退出。

6. 编译项目

https://gitee.com/EspressifSystems/esp-idf

编译应用程序,引导程序,并根据配置生成分区表。

6.1 编译

idf.py build

6.2 烧写命令

/home/ccdc/.espressif/python_env/idf4.2_py3.6_env/bin/python ../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 detect --flash_freq 40m 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello-world.bin

从命令中可以获取以下信息:

  • Flash芯片模式

flash_mode dio

  • Flash芯片频率

40m

需要下载3个文件和烧写地址:

  • bootloader.bin

0x1000 build/bootloader/bootloader.bin

  • partitions_singleapp.bin

0x8000 build/partition_table/partition-table.bin

  • hello-world.bin

0x10000 build/hello-world.bin

0x1000,0x8000和0x10000是烧写地址,后面要用到。

7. 将编译好的bin文件下载到本地

  • 进入CMD窗口

Win+R

输入cmd,确定。

  • 用sftp登录阿里云

@前面是用户名,后面是IP地址。

  • 进入远程项目的build目录

cd /home/ccdc/esp/hello_world/build

  • 切换本地目录

lcd E:\ct\ESP32

  • 下载bootloader.bin

get bootloader/bootloader.bin

  • 下载partitions_singleapp.bin

get build/partition_table/partition-table.bin

  • 下载hello-world.bin

get hello-world.bin

  • 查看本地目录

  • 退出sftp

8. 烧写项目

  • 下载Windows的Flash烧写工具

见《阿里云ECS搭建ESP8266_RTOS_SDK开发环境》

https://zhuanlan.zhihu.com/p/346975777

https://blog.csdn.net/chentuo2000/article/details/113173934

一文中的相关内容。

  • 设置Flash烧写工具

运行flash_download_tool_v3.8.5.exe

选择ESP32下载工具。设置如下,地址在前面已经有了,对应如下:

0x1000 bootloader.bin

0x8000 partitions_singleapp.bin

0x10000 hello-world.bin

如下设置:

点击START开始烧写。

烧写完成:

9. 用串口调试助手查看程序运行结果

串口调试助手的使用请看《Win10使用CH340 USB-SERIAL串口》

https://zhuanlan.zhihu.com/p/343013801

https://blog.csdn.net/chentuo2000/article/details/112323488

按开发板的RST键。

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晨之清风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值