-->
Page 1 of 1

Programming firmware: DTR/RTS issues

PostPosted: Tue Apr 14, 2015 4:28 pm
by DavidMPerlman
I'm experienced with microcontrollers, and had no trouble setting up an ESP-01 module to communicate through AT commands, connecting to wifi, etc. However, when I wanted to take it to the next level and update to the NodeMCU firmware, I ran into a block.

The firmware flashing software esptool.py uses DTR and RTS. To quote its documentation on github:

esptool uses the RTS and DTR modem status lines to automatically enter the bootloader. Connect RTS to CH_PD (which is used as active-low reset) and DTR to GPIO0.


I verified that by looking at the python source code. However, the odd thing is, it is extremely rare for a USB-Serial adapter to actually have pins for both of those. "Standard" FTDI adapter cables have CTS and RTS, like these:
http://www.amazon.com/GearMo®-Header-Like-FTDI-TTL-232R-5V/dp/B004LC28G2
http://www.amazon.com/GearMo®-3-3v-Header-like-TTL-232R-3V3/dp/B004LBXO2A
http://www.adafruit.com/products/70
http://www.adafruit.com/products/284
https://www.pololu.com/product/1308
etc.

Ones that are designed to be maker-friendly for Arduino put out DTR instead of RTS, like these:
https://www.sparkfun.com/products/9716
https://www.sparkfun.com/products/11736
http://www.dfrobot.com/index.php?route= ... uct_id=147

A *few* of the items I linked are full-pins breakout boards that break out *all* the pins from the FTDI chip. However, this is definitely the exception rather than the norm. I have three usb-serial TTL adapters lying around already and none of them make it possible to access both DTR and RTS.

This seems odd to me because I've looked at every "getting started" guide I can find, and none of them say anything about using an odd, rare kind of adapter to run esptool.py. Including the esptool.py documentation... no mention at all.

Am I missing something? Is there some reason why it's obvious to everyone else, but not to me? Is that why none of the authors of any of the getting-started guides mention this?

It seems like the most obvious thing to do is simply to manually pull GPIO_0 low for programming, as described in many (but not all) of the guides I've seen, like this one:
http://randomnerdtutorials.com/flashing ... g-windows/

I guess that's good enough, but the esptool.py documentation really had me running up the DTR/RTS blind alley for a while.

Side note: this one simply has an error:
https://www.openhomeautomation.net/gett ... d-esp8266/
Connecting CTS won't do you any good, since that is an input not an output...

Re: Programming firmware: DTR/RTS issues

PostPosted: Wed Apr 15, 2015 7:56 am
by cal
Moin,

you can ignore theDTR/RTS stuff completely and use manual reset button + "enter flash mode" button or switch.
I still do that currently because I didn't noticed support for that and my adapter does not
have them, too.

I ordered another one that should have it.
I found another idea that uses the BREAK signal and a simple C/R-Kombination
on RST and CH_PD to enter flash mode. Maybe I test that.

Carsten

Re: Programming firmware: DTR/RTS issues

PostPosted: Wed Apr 15, 2015 12:40 pm
by ozayturay
Have a look at this post and this post.

Re: Programming firmware: DTR/RTS issues

PostPosted: Wed Apr 15, 2015 3:38 pm
by krzychb
Indeed it is not so often for an USB-Serial adapter to actually have pins broken out for both DTR and RTS. The reason for that may be that most of such adapters are used for other microcontrollers that require only RESET to activate the boot loader. ESP8266 requires flipping two pins (EXT_RSTB and GPIO0) but still you may do it manually and several ESP development boards have dedicated buttons to do so.

I am developing firmware for ESP ESP8266 in c language (using great Project Unofficial Development Kit for Espressif ESP8266 by CHERTS - http://programs74.ru/udkew-en.html) and I am flashing the modules quite frequently. Depending on the application I may need to flash from two to four binary files in a sequence. I do not like to muck around with EXT_RSTB and GPIO0 pins for each file. To make my life easier I am using esptool.exe (tweaked by CHERTS) and a custom cable for flipping DTR and RTS for me. Sometimes I have the module away from my workbench or have several other wires hanging around and it is inconvenient to play with EXT_RSTB and GPIO0 wires by reconnecting them back and forth.

I have been also inspired by wiring scheme by CHERTS - viewtopic.php?f=9&t=820 but encountered couple of issues before I finally got the loading fully automatic:

1. EXT_RSTB input looks to be susceptible to noise over the wire connected to RTS (I am using 20 cm wires between ESP and USB adapter):
a. I observed ESP8255 not entering the boot loader mode or spuriously rebooting if subject to typical electrical noise that is generated by e.g. switching the light on/off nearby.
b. I did not observe such issues at all if nothing was connected to EXT_RSTB pin.
c. Spurious reboots happen also when I disconnect RTS and leave a lose wire hanging but still connected to EXT_RSTB.
d. GPIO0 looks not affected by any of the “20 cm connecting wire” issues above.
2. On some development boards that have multiple ground terminals I observed unusable connection (already started transmission may get randomly aborted by esptool.exe) depending to which board’s terminal I connected the ground of the USB-Serial adapter.
3. I could not make the GPIO0 / DTR pair work until I connected it using a transistor like on attached schematic.
Cable for flashing ESP8266.JPG

[EDIT] After some more testing I have discovered that the problem is caused by too long cables between USB converter and ESP board. Original cables were 20 cm (8 inch) long. After cutting them to 10 cm (4 inch) the problem was gone / no need for any extra components like transistor.
4. On some USB-Serial adapters there is a capacitor in series with DTR to produce a reset pulse. I believe it introduced for other microcontrollers to work with code loaders that hold DTR down throughout the whole transmission. This makes them "friendly for Arduino" as pointed out by DavidMPerlman (above) to provide reset signal to activate boot loader. Such adapters may not work as desired with esptool.exe.
5. On next two pictures I put one of USB adapters that I am currently using that works perfectly for various ESP types. This particular adapter is based on CP2102 chip from Silicon Labs.
CP2102_Top.jpg
CP2102_Bottom.jpg

6. After the firmware is flashed I usually would like use the same USB adapter for debugging over serial connection. Most of terminals I am aware of keep RTS line down during the whole the connection. That would cause ESP to reset unless you disconnect it. But my goal was not to muck around with wires :D . To resolve this issue I recommend using Termite - http://www.compuphase.com/software_termite.htm that lets your configure RTS/CTS behaviour (go to “Settings” and change “Flow control” to “none”).

Hope this helps.

Cheers, Krzysztof