I am currently designing a board centered around the ESP32. I want to implement an auto-program circuit for convenience's sake, because I don't want to hold a boot button each time I want to program it.

My question is: Why is the below circuit that most ESPs use, designed the way it is? I am asking because this circuit fails to initiate the upload more often than I would like and I end up having to press the boot button. So I somehow think there is something with the design that causes this, as I had this problem with more than 1 ESP at different times.

partial schematic

Why not use something like this for instance? This is a thought experiment I made using the logic table and KV diagrams.

(1) EN = not(DTR) + RTS

(2) IO0 = not(RTS) + DTR

From this, I have developed this circuit:


So I know this can probably be done better, but maybe this will solve the reliability problem that I have. Or maybe I should use the relation I found on (1) and (2) to build the same circuit using OR-Gates. In any case, any thoughts on optimization or help on the matter would be appreciated.

  • \$\begingroup\$ Why do you think your circuit works more reliably than the more common one (which uses far less components)? I suspect that the problem is controlling the timing or RTS and DTR via USB-to-serial connection. If so, your circuit would be affected as well. A more reliable alternative would be to fit a JTAG connector. \$\endgroup\$
    – Codo
    Oct 27 '20 at 9:05
  • 2
    \$\begingroup\$ You should analyze the real cause of the unreliability. If it is a timing issue, then a more appropriate fix is either tuning the software or adding a capacitor to the EN pin. I doubt it is caused by voltage levels. \$\endgroup\$
    – Codo
    Oct 27 '20 at 9:22
  • 1
    \$\begingroup\$ The original circuit has a high impedance output when not in use, letting you use IO0 for other purposes if you need. Your problems could be caused by your circuit using GPIO0 for something that pulls the voltage down at boot. Also check the otherboot mode pins, maybe GPI02... \$\endgroup\$
    – bobflux
    Oct 27 '20 at 11:17
  • 1
    \$\begingroup\$ Yeah, I heard some devkits fail and others work. I have an adafruit huzzah32 which always works flawlessly. So you could compare the schematics of this with the schematics of yours, and see if you spot a difference. Check values of decoupling capacitors, for example, or if the LDO has good transient response and doesn't sag under load, etc. \$\endgroup\$
    – bobflux
    Oct 27 '20 at 12:06
  • 1
    \$\begingroup\$ What about decoupling caps and regulator? \$\endgroup\$
    – bobflux
    Oct 27 '20 at 13:04

This kind of intermittent failure can be a timing problem, but it can be a power supply problem. Since the latter is easier to debug, why not start there? If you did connect all the GND/VCC pins correctly I'll designate the HT7733 regulator as a suspect, since it's pretty much the only different part between the board that work and the one that doesn't. Well, that and the two bipolar transistors, but any BJT should work there. And I'll assume you didn't use Z5U caps.

Personally I'd be wary of a LDO that gets its transient response pictured at 4ms/div and 2V/div on the output. These settings are so huge it looks like they have something to hide. What looks like a tiny blip on Vout is actually a huge dip from 3.64V down to 2.76V, and that happens at 40mA which is much less than what ESP32 consumes. That will crash the microcontroller, or the USB-serial chip, or both. It might even corrupt the Flash if voltage drops while it's writing.

enter image description here

To check if this is the cause, first check the 3V3 rail with a scope to check if it stays within acceptable voltage range. Then add a huge electrolytic cap on the 3V3 rail. If that fixes things, you need a better LDO.

Here's AP2112 for comparison. Note the different scales, 10mV/div an 200µs/div, that's much better. Note this isn't a fancy chip, just a normal basic LDO, it isn't even more expensive, but it does have higher quiescent current.

enter image description here

EDIT: how to quickly select a LDO for this.

If you want to run it on batteries, choose max quiescent current. Hit mouser/digikey search engine with input/output voltage, current, quiescent, package, noise, etc. Sort by price, click on datasheets.

You're using ceramic caps on the output. So, Ctrl-F, "capa", ENTER. If it highlights "stable with ceramic caps", good. If it specs a minimum ESR value like 0.1 ohm or something, since your 10µF MLCC has an ESR below 0.01 ohms, next. If it says "tantalum" or "aluminium cap" on the output (which is another way to say "high ESR") but doesn't explicitly say "ESR" and doesn't say "stable with ceramics" then next.

For example this is the case with AMS1117. It says "22µF solid tantalum". Why put an expensive tantalum cap after a super cheap regulator? That's because it's an old chip design from the days when big ceramic caps were expensive. Now ceramics are cheap, so the new LDOs are pretty much all designed for ceramics. Cross-check with LM1117 datasheet:

enter image description here

So... next. Unless you put an aluminium cap, in this case it will work. With just ceramics it'll be unstable.

Note this is a different problem than HT7333. HT7333 is micropower, micropower regulators tend to be slow, and this one is extremely slow. It's probably designed for low power stuff that draws more or less constant current. AMS1117 is not slow, in fact it's pretty good, but its topology makes it unstable with low ESR caps, so it'll oscillate with ceramic caps. Result is the same, your micro will crash.

On AP2112 datasheet, hit Ctrl-F "capa" it says "Stable with 1.0µF Flexible Cap: Ceramic, Tantalum and Aluminum Electrolytic" like most modern LDOs.

So then you can check the rest of the specs. But really, if it's a one off, unless you have supply issues, it's not worth it reading 20 datasheets to select a 40 cents part. Just stick a 100µF cap, don't pay $20 postage for another LDO...

  • 1
    \$\begingroup\$ I used 0805 ceramic capacitors for all the decoupling purposes. And I really have to offer you my gratitude because you are right. I added a 100uF electrolytic cap to the Ht7333 input and the 3.3V Output and... it suddenly started working well. I uploaded around 10 times to be sure it did not fail, and it didnt. I had no idea HT7333 was so bad since it is so popular. Is the AMS1117 also just as bad? I am going to assume that it is since the DEV-Kits also have the same problem on occasion. If so would you recommend some other LDOs? Which one do you usually use? \$\endgroup\$
    – Emre Mutlu
    Oct 27 '20 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.