Clock Radio

ESP32 DTR/RTS Boot Selection and Reset

Tue Oct 12 2021 13:34

The DTR/RTS boot programming is actually worth talking about. The ESP32 and friends enter boot mode by pulling a GPIO low on boot. Inspired by the Arduino method of using the DTR signal to reset the chip, ESPs have an even weirder method to control both an IO pin and the reset line.

If you look at an ESP32 dev board schematic, they all have this peculiar circuit. (This one is from the Sparkfun ESP32 Thing)

The longer you stare at it, the less it makes sense.

It's two transistors, but one is upside-down. Why are the emitters connected to the inputs? What in tarnation?

It makes a little more sense if you rearrange it like this:

I think it's like this to work around serial port behavior. DTR and RTS are both lines controlled by the other end of the serial line (Data Terminal Ready and Request To Send, respectively), and are normally used to signal the readiness of the other end to receive data. So when you open a serial port, they are both high. And on some OSes and drivers, when you close a serial port, they go low. Much to the annoyance of some Arduino users.

So the clever bit in this circuit is nothing happens when RTS and DTR are both low or high. It only toggles the pins when one is low and the other is high.

DTR high and RTS low pulls EN low. RTS high and DTR low pulls GPIO0 low. (Both EN and GPIO0 have pull-ups so they are normally high)

From a practical perspective, the reason this circuit is built with resistors and BJTs is cost. You could eliminate the resistors and use tiny signal mosfets but the total cost of that solution would be a few pennies more.

I was already using 2N7002 mosfets in the clock radio so that's what I did.

Oh, and the reason they can use DTR and RTS for this? Nobody has cared about serial signaling pins since about 1995. You only need them when the hardware isn't capable of keeping up with the incoming data rate. And that just hasn't been the case in a looooong time.

And yet, the full complement is available on pretty much every USB serial chip. Hooray for legacy.