和ESP8266 Arduino谈场恋爱 02 这神奇的程序烧写

版权声明:本文为twowinter原创文章,请联系微信公众号twowinter,未经博主允许不得转载。 https://blog.csdn.net/iotisan/article/details/84928341

前言

开发环境搭起来了,接着这篇笔记就要实现程序的烧写。

非著名情感博主 IoT小能手 twowinter,耗费数月心血,编著长篇言情小说《和ESP8266 Arduino谈场恋爱》,为广大技术宅男传授深度撩妹技巧。是时候了,关掉屏幕上的波多野结衣,跟着小能手的脚步,去找寻爱的真谛。

一、烧写方式

ESP8266是通过串口 boot 来烧写,两年前玩 ESP8266 时就接触过,ESP8266学习笔记1:如何在安信可全功能测试板上实现ESP-01的编译下载和调试

烧写前必须要将GPIO0拉低,复位模块才行。

可奇怪的是,我手头玩的是WEMOS D1 开发板,没想到直接在 Arduino IDE上点击 “Upload” 就把程序烧录进去了,甚至都不用复位模块。

都说 Arduino 开发方式很傻瓜化,可没想居然傻到这程度,哦,不傻,方便到本能手都要哭出来了。

二、为什么某些开发板可以直接用IDE Upload

2.1 esptool的解释

Esp8266 for Arduino 的烧写工具是集成了 esptool,esptool 的 github 有详细的解释。

## Entering the Bootloader

Both ESP8266 and ESP32 have to be reset in a certain way in order to launch the serial bootloader.

On some development boards (including NodeMCU, WeMOS, HUZZAH Feather, Core Board, ESP32-WROVER-KIT), esptool.py can automatically trigger a reset into the serial bootloader - in which case you don't need to read this section.

For everyone else, three things must happen to enter the serial bootloader - a reset, required pins set correctly, and GPIO0 pulled low:

### Boot Mode

Both ESP8266 and ESP32 chooses the boot mode each time it resets. A reset event can happen in one of several ways:

* Power applied to chip.
* The nRESET pin was low and is pulled high (on ESP8266 only).
* The CH_PD/EN pin ("enable") pin was low and is pulled high.

On ESP8266, both the nRESET and CH_PD pins must be pulled high for the chip to start operating.

For more details on selecting the boot mode, see the following Wiki pages:

* [ESP8266 Boot Mode Selection](https://github.com/espressif/esptool/wiki/ESP8266-Boot-Mode-Selection)
* [ESP32 Boot Mode Selection](https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection)

2.2 twowinter的解释

原来不是所有的板子都能这样神奇地烧写,NodeMCU, WeMOS, HUZZAH Feather, Core Board, ESP32-WROVER-KIT,这几款是可以。其他的板子还是得老老实实地去手动对GPIO0拉低且复位模块。

找出 WeMOS 的原理图确认了下,原来是 复位脚 和 GPIO0 其实都有串口芯片的流控脚连接着。

这样就解释通了,esptool在烧写时通过流控脚对ESP8266做了复位和拉低IO0的操作,这样就可以直接烧写了。

三、其他无流控板子的升级

再找出了原来的旧板子,它是用拨码开关将GPIO0给拉低的。

IDE上点击“Upload”后,会在串口等几秒钟,这期间对旧板子上电,就可以顺利地进行烧写了。

四、总结

现在想起来,本尊其实之前也接触过相同的操作,JN516X系列的开发板就是这样设计的。NXP的IDE工具在烧写JN516X时直接操作了流控脚控制了某些IO。

利用底板USB转串口芯片的流控脚去控制一些烧写时必要的IO,这种实现方式让烧写过程变得特别特别畅快。

人们是这样,一旦你用过这Upload,如同感受到秋裤的温暖,也就回不去了。


猜你喜欢

转载自blog.csdn.net/iotisan/article/details/84928341