Ubuntu20.04下的ESP8266环境

2021/4/19 7:25:12

本文主要是介绍Ubuntu20.04下的ESP8266环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

硬件设备

使用的是一块好几年前购买的ESP8266开发板, 不是官方的开发板, 而是淘宝上卖的最多的CH341做USB TTL, 带Rest和Flash两个按钮的第三方板子.

环境配置

安装软件

根据文档安装软件, 文档中列出需要安装的python和python-serial是有问题的, 在Ubuntu20.04中只有python3没有python, 而python3已经安装, 另外没有python-serial, 这个要在后面通过pip安装

sudo apt install gcc git wget make libncurses-dev flex bison gperf

安装工具链

tar zxvf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz 
cd /opt/
sudo mkdir esp8266
cd esp8266/
sudo mv ~/Backup/linux/xtensa-lx106-elf .
sudo chown -R root:root xtensa-lx106-elf/
回到用户home目录, 将这个路径添加到PATH
```bash
vi .profile
# append start
export PATH="$PATH:/opt/esp8266/xtensa-lx106-elf/bin"
# append end

安装SDK

在用户home目录下

mkdir Esp
cd Esp/
# 这一步会下载超过190M大小的源代码, 需要提前设置好代理
git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git

将IDF_PATH添加到环境变量

vi ~/.profile
# append start
export IDF_PATH="/home/milton/Esp/ESP8266_RTOS_SDK"
# append end

通过以下方式验证

printenv IDF_PATH
printenv PATH

安装python库

# 如果python命令不存在, 需要提前设置好ln或alias
cd /usr/bin/
sudo ln -s python3.8 python
# 检查python版本
python --version
# 安装
python -m pip install --user -r $IDF_PATH/requirements.txt

连接开发板

直接通过microUSB线连接, 通过dmesg可以看到创建的虚拟串口为ttyUSB0

[ 4348.546767] usbcore: registered new interface driver usbserial_generic
[ 4348.546778] usbserial: USB Serial support registered for generic
[ 4348.549509] usbcore: registered new interface driver ch341
[ 4348.549994] usbserial: USB Serial support registered for ch341-uart
[ 4348.550112] ch341 2-2:1.0: ch341-uart converter detected
[ 4348.552247] usb 2-2: ch341-uart converter now attached to ttyUSB0

运行示例

到SDK目录下, 将hello world项目复制到最上一层

cp -r ESP8266_RTOS_SDK/examples/get-started/hello_world/ .
cd hello_world/

首先执行make menuconfig, 在这里选择菜单Serial flasher config, 设置

  • Default serial port: /dev/ttyUSB0
  • Default baud rate: 115200 baud
  • Use compressed upload: Yes
  • Flash SPI mode: DOUT
  • Flash SPI speed: 40 MHz
  • Flash size: 4MB
  • Before flashing: Reset to bootloader
  • After flashing: Hard reset after flashing
  • make monitor baud rate: 74880 bps

然后save, exit.

编译+烧录: make flash, 查看串口输出make monitor, 编译+烧录+查看串口输出make flash monitor

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 7032, room 16 
tail 8
chksum 0x9e
load 0x3ffe8408, len 24, room 0 
tail 8
chksum 0x77
load 0x3ffe8420, len 3324, room 0 
tail 12
chksum 0x32
csum 0x32
I (80) boot: ESP-IDF v3.4-4-gd4507156 2nd stage bootloader
I (81) boot: compile time 00:50:46
I (81) boot: SPI Speed      : 40MHz
I (93) boot: SPI Mode       : DOUT
I (106) boot: SPI Flash Size : 4MB
I (118) boot: Partition Table:
I (130) boot: ## Label            Usage          Type ST Offset   Length
I (152) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (176) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (199) boot:  2 factory          factory app      00 00 00010000 000f0000
I (222) boot: End of partition table
I (235) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x1b2b8 (111288) map
0x40210010: _stext at ??:?

I (337) esp_image: segment 1: paddr=0x0002b2d0 vaddr=0x4022b2c8 size=0x06f24 ( 28452) map
I (357) esp_image: segment 2: paddr=0x000321fc vaddr=0x3ffe8000 size=0x00554 (  1364) load
I (360) esp_image: segment 3: paddr=0x00032758 vaddr=0x40100000 size=0x00080 (   128) load
I (387) esp_image: segment 4: paddr=0x000327e0 vaddr=0x40100080 size=0x04f6c ( 20332) load
I (427) boot: Loaded app from partition at offset 0x10000
Hello world!
This is ESP8266 chip with 1 CPU cores, WiFi, silicon revision 1, 4MB external flash
Restarting in 10 seconds...

参考

  • 官网ESP8266 RTOS SDK文档
    https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/index.html#get-started-get-esp-idf


这篇关于Ubuntu20.04下的ESP8266环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程