Python教程

ESP32-S2原生USB 烧录 TinyUF2 bootloader 加 CircuitPython

本文主要是介绍ESP32-S2原生USB 烧录 TinyUF2 bootloader 加 CircuitPython,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

概述

ESP32-S2最令我心仪的改进是原生支持USB,即带有一个集成了收发器的全速 USB OTG 外设,符合 USB 1.1 规范,理论速度1.5m/s,利用得当将会是一个非常巨大的进步。

目前ESP32-S2已经得到CircuitPython的支持,本文内容是我经过一番资料查询和整理后做出的关于仅使用原生USB接口来烧录 TinyUF2 bootloaderCircuitPython 的方法总结。

本文列举的操作是在一款搭载 ESP32-S2-WROVER 模组的小型开发板ESP32-S2-Saola-1上进行的,操作系统为Windows10,其他不同型号的模组及开发板则需进行对应适配,在下就不另作描述了。

在开发板上接一个直连芯片的USB母口

  1. ESP32-S2-Saola-1开发板上并没有提供直连ESP32-S2的USB接口,需要参考 ESP32-S2-WROVER模组技术规格书(PDF)中的管脚定义确定 USB OTG 从哪些管脚引出的,也可以直接看看外围设计原理图

image

image

  1. 整一个四线的USB Type-C母口对应接口焊接上去,当然别的USB接口型号也类似。

image

将ESP32-S2设为 bootloader 引导模式

参考ESP32-S2官方API指南中的通过USB升级设备固件章节,通过原生USB接口与PC连接上后,按住 Boot 键的同时按一下 Reset 键,再松开 Boot 键,使ESP32-S2芯片处于 bootloader 引导模式,此时在windows设备管理器里即可以查看到新的USB串行设备。

image

通过esptool将TinyUF2烧录进ESP32-S2的flash中

  1. 确保已经安装了python3.4或更高版本,进入cmd命令提示符窗口,输入:
pip install esptool
  1. 安装上esptool后,再输入以下命令擦除flash:
esptool -p com9 --after no_reset erase_flash

--after no_reset在此处比较关键,指定在esptool.py操作完成后,不重置芯片,而将芯片留在 bootloader 引导模式中,执行结果如下:

>esptool -p com9 --after no_reset erase_flash
esptool.py v3.1-dev
Serial port com9
Connecting...
Detecting chip type... ESP32-S2
Chip is ESP32-S2
Features: WiFi, ADC and temperature sensor calibration in BLK2 of efuse
Crystal is 40MHz
MAC: xx:xx:xx:xx:xx:xx
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 16.3s
Staying in bootloader.
>
  1. 在此连接:github TinyUF2 下载对应开发板型号的 tinyuf2-espressif_saola_1_wrover-0.5.1.zip 文件到本地然后解压。
    image

  2. 在cmd中输入指令进入此文件路径中,例如:

请在cd /d 后正确输入你所解压到的文件夹的路径

cd /d D:\Users\Wind\esp\tinyuf2-espressif_saola_1_wrover-0.5.1
  1. 参考TinyUF2的ESP32S2说明文档在cmd中输入如下指令将其烧录进flash中:
esptool --chip esp32s2 -p com9  -b 460800 --before=default_reset --after=no_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x8000 partition-table.bin 0xe000 ota_data_initial.bin 0x1000 bootloader.bin 0x2d0000 tinyuf2.bin

正确烧录完成的话执行结果如下:

D:\Users\Wind\esp\tinyuf2-espressif_saola_1_wrover-0.5.1>esptool --chip esp32s2 -p com9  -b 460800 --before=default_reset --after=no_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x8000 partition-table.bin 0xe000 ota_data_initial.bin 0x1000 bootloader.bin 0x2d0000 tinyuf2.bin
esptool.py v3.1
Serial port com9
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.

Chip is ESP32-S2
Features: WiFi, ADC and temperature sensor calibration in BLK2 of efuse
Crystal is 40MHz
MAC: xx:xx:xx:xx:xx:xx
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00001000 to 0x00006fff...
Flash will be erased from 0x002d0000 to 0x002effff...
Compressed 3072 bytes to 136...
Wrote 3072 bytes (136 compressed) at 0x00008000 in 0.1 seconds (effective 446.1 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 31...
Wrote 8192 bytes (31 compressed) at 0x0000e000 in 0.1 seconds (effective 645.0 kbit/s)...
Hash of data verified.
Compressed 20832 bytes to 13005...
Wrote 20832 bytes (13005 compressed) at 0x00001000 in 0.4 seconds (effective 464.5 kbit/s)...
Hash of data verified.
Compressed 130736 bytes to 82339...
Wrote 130736 bytes (82339 compressed) at 0x002d0000 in 1.5 seconds (effective 677.7 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.

D:\Users\Wind\esp\tinyuf2-espressif_saola_1_wrover-0.5.1>
  1. 按一下开发板上的RESET复位键,可以在本地设备管理器列表中查看到一个名为 SAOLA1RBOOT 的便携存储器,及一个名为 Adafruit UF2 Bootloader USB Device的磁盘驱动器
    image
    image

烧录CircuitPython固件

1.前往CircuitPython官网ESP32相关下载页面,所有CircuitPython支持的ESP32开发板都在这里了。此处没有我使用的ESP32-S2-Saola-1,但找到一个相似度极高的使用同一个ESP32-S2-WROVER模组的,即 NanoESP32 S2 w/WROVER 。

2.点击CircuitPython 7.0.0-alpha.6中的DOWNLOAD .UF2 NOW下载到本地

image

3.最后一步很简单,复制到 SAOLA1RBOOT 移动存储器中。

image

4.待开发板自动复位后,可以在本地设备管理器列表中查看到与之前不同的便携存储器及磁盘驱动器,且新增了一个USB串行设备com端口。

image
image

5.通过支持CircuitPython的IDE例如Thonny即可在此开发板上进行编程。

image

各模式之间的切换方法

  1. 在烧录好CircuitPython固件后,开发板重新上电或按一下Reset键,将进入CircuitPython模式。

  2. 按住 Boot 键的同时按一下 Reset 键,再松开 Boot 键,将进入 ESP32-S2 bootloader 模式,esptool在此模式下可对flash进行操作。

  3. 在0.5秒内快速按一下 Reset 键再按一下 Boot 键,将进入TinyUF2 bootloader 模式,支持UF2的固件可以由此烧录进flash。

这篇关于ESP32-S2原生USB 烧录 TinyUF2 bootloader 加 CircuitPython的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!