New Lolin D32 Pro with 4MB PSRAM

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Mike Teachman » Wed Aug 01, 2018 3:48 am

I'm having troubles using the esptool with both the new Lolin D32 Pro and Lolin D32 boards. I started by using the esptool to flash the latest MicroPython releases. That didn't work. Then, I tried a minimal test: using the esptool to read the chip_id. That did not work either.

for example, running esptool's chip_id command:

Code: Select all

esptool.py --port COM3 --no-stub chip_id
results in:

Code: Select all

esptool.py v2.4.1
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Invalid head of packet (0x08)
What does work: I can use Putty to communicate to the MicroPython REPL (these boards ship with MicroPython).

I scoped out the signals and observed very strange transitions on the Reset and GPIO0 pins, shown in the next two images. These scope captures reveal a showstopper problem in the boards shipped to me: GPIO0 is HIGH when Reset transitions to High. ESP32 devices will only enter the bootloader when GPIO0 is LOW when Reset goes High. This signal behaviour results in the ESP32 device resetting rather than entering the bootloader. I used the scope's RS232 decode feature to confirm this - I see the MicroPython REPL prompt rather than the bootloader message. The esptool needs the ESP32 to enter the bootloader for commands to work. Neither of these boards will enter the serial bootloader using the esptool.
esp32_1.PNG
esp32_1.PNG (139.13 KiB) Viewed 8525 times
ESP32_2.PNG
ESP32_2.PNG (137.12 KiB) Viewed 8525 times
Using the same setup, I used the esptool to read the chip_id from a WEMOS D1 mini, an ESP8266 device. This device entered the bootloader, with the captured traces showing the expected behaviour. The chip_id was returned by esptool. Here are the WEMOS D1 Mini signals.
ESP8266.PNG
ESP8266.PNG (170.1 KiB) Viewed 8525 times
Both the new Lolin branded boards and the Wemos D1 mini use the CH340 USB to Serial device. The Wemos D1 mini worked with the esptool, so my CH340 driver installation on windows would appear to be OK. Looking at the schematics, all 3 boards show the same autoreset circuitry, using RTS and DTR. Perhaps the Lolin board layouts were done incorrectly, or maybe they have incorrectly placed components?

The same test using an Adafruit ESP32 Huzzah feather also returned chip_id with esptool. Except, unfortunately, the Adafruit board does not breakout the GPIO0 or Rx/Tx signals, so it's not easy to capture the transitions with a scope.

I'm stumped. MicroPython is on these devices, so somehow it was flashed to the ESP32s at the factory. But, in my environment I can't get the esptool working with them.

Any ideas before I ask Aliexpress for a refund? thanks!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Roberthh » Wed Aug 01, 2018 5:20 am

Unless they changed the logic on the board, it looks like a fault in the circuit. The usual 2 transistor reset/IO0 logic cannot pull both inputs low at the same time. See schematics: https://wiki.wemos.cc/_media/products:d ... v2.0.0.pdf
You could try to add an external pull-up resistor to IO0. Maybe that one is missing (not enabled in the bootloader).

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Mike Teachman » Wed Aug 01, 2018 5:27 pm

Adding the pullup is really good idea. I tried adding a 4.7k pullup to the IO0 signal. Unfortunately, the esptool was still not able to coax the Lolin D32 boards into the bootloader state.

But, your idea to add external components led me to experiment with increasing the RESET circuit capacitance. I found that adding a 1uF capacitor from Reset to Ground fixes the problem for both the Lolin D32 and Lolin D32 Pro boards.

Here are the before and after oscilloscope captures, using esptool to read the flash_id.

BEFORE: no modifications
The ESP32 does not enter the bootloader. Instead it boots from SPI flash.
noCap.PNG
noCap.PNG (138.09 KiB) Viewed 8501 times
AFTER: 1uF external capacitor added between Reset (labelled RS or RST on the boards) and Ground (labelled GND on the boards)
With the added capacitance, the esptool can place the ESP32 into the bootloader state, and run the flash_id command (WooHoo!)
added-1uF-cap.PNG
added-1uF-cap.PNG (136.4 KiB) Viewed 8501 times
Why does this fix the problem? I think the root cause of the problem is an undersized Reset capacitor. The schematic for both the Lolin D32 boards show a 100nF (0.1uF) capacitor to ground and a 10k resistor to 3.3v. It appears that the Reset signal rises too quickly with a 100nF capacitor, with the ESP32 detecting IO0 in the HIGH state. In this condition, the ESP32 will boot from SPI flash rather than enter the bootloader. The measured Reset rise time is approximately 4 ms. With the addition of 1uF capacitance, the Reset rise time increases to about 30 ms, highlighted with blue in the AFTER scope capture. You can see that IO0 will be sampled as Low, triggering the ESP32 to enter the bootloader.

It is interesting to see that the Adafruit Huzzah32 ESP32 Feather schematic shows a 1uF between Reset and Ground.

Summary: Using the Esptool application with Lolin D32 or Lolin D32 Pro devices may require adding an external 1uF capacitor between Reset and Ground.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Roberthh » Wed Aug 01, 2018 8:35 pm

What is still confusing, compared with the esp8266, that IO0 is low while Reset is pulled low. The external circuitry cannot do this, at least not if is the one of the schematics. But looking on an older WEMOS LOLIN32 Pro, I see the same behavior, but w/o the IO0 going up for a moment after reset. The same with a Pycom device.
Can you read out the chip if with with esptool.py for comparison? The Pycom device has a chip ID ESP32D0WDQ6 (revision 1)

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: New Lolin D32 Pro with 4MB PSRAM

Post by devnull » Thu Aug 02, 2018 2:24 am

Sounds similar to this: viewtopic.php?f=18&t=4775

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Mike Teachman » Sat Aug 04, 2018 12:20 am

My devices have the same chip ID = ESP32D0WDQ6(revision 1).

Looking at the Lolin D32 schematic, there is no pull-up resistor for the GPIO0 signal. This is different than the ESP8266 based Wemos D1 mini, where GPIO0 is pulled high with a 10k resister. Why the difference? The ESP32 Datasheet indicates that GPIO0 is one of five "strapping pins" that have internal weak pull-down/pull-up resistors.
https://www.espressif.com/sites/default ... eet_en.pdf
GPIO0 has an internal weak pull-up. I guess the internal pull-up eliminates the need for an external pull-up on the dev board.

I was trying to come up with a theory on how both Reset and GPIO0 could both end up simultaneously low. Perhaps that weak pull-up does not drive the external GPIO0 pin to the high state while the chip is in reset? Is that possible? If that was that case, it appears possible that both Reset and GPIO0 can be simultaneously low. For example, when the USB driver drives RTS low and DTR high, the NPN transistor (in the autoreset circuit) connected to Reset will switch on, driving Reset low, but the 2nd NPN transistor will switch off, possibly allowing GPIO0 to float to a low state when nothing is actively driving that signal. On ESP8266 boards, GPIO0 would be high in this same situation, from the external 10k pull-up resistor.

Some more searching shows a very similar discussion in late 2016, where the added capacitance on the reset pin (EN) is used to overcome this bootloader issue.
https://github.com/espressif/esptool/issues/136
A solution that seems to work reliably is to add a ~2.2uF capacitor (I think 470nF-2.2uF range should be suitable) to the EN pin (between EN and GND), so it rises slower (there is a ~12K pullup on this pin.) This is not super desirable, as it requires a hardware change, but it works.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Roberthh » Sat Aug 04, 2018 6:40 am

I agree to the assumption that GPIO0 of the ESP32 is floating during reset. The oscilloscope picture also show some ripple during that phase. About your intial problem: For me it is more likely that it is a timing issue: the switch from reset low to GPIO0 low does not happen fast enough. And that include also the USB/UART bridge and the driving PC into the scope.
If I look at the device I have here, I see about 150 µs between the Reset and GPIO signal switch. In your pictures, it looks like 2 ms.

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Mike Teachman » Sat Aug 04, 2018 6:49 pm

The idea of a timing problem makes a lot of sense. In the esptool.py code, DTR is set low (to allow Reset to go high), followed by RTS set high (to pull GPIO0 low). Any delay between these events increases the risk that the ESP32 will sample GPIO0 as high when Reset rises.

Hopefully not many people will face this issue with their Lolin devices.

User avatar
patvdleer
Posts: 46
Joined: Mon Jun 13, 2016 11:52 am
Location: Maastricht, NL, Europe
Contact:

Re: New Lolin D32 Pro with 4MB PSRAM

Post by patvdleer » Fri Sep 14, 2018 11:04 am

So can the D32 Pro (v2?) run micropython without having to solder?
NodeMCU v0.9 / V1 / V2 / V3
WeMos D1 Mini
WeMos Lolin32 v1.0.0
WeMos Lolin D32 Pro V2

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: New Lolin D32 Pro with 4MB PSRAM

Post by Roberthh » Fri Sep 14, 2018 11:11 am

i have Micropython on the old LOLIN32 pro running, and I see no reason why it should not do so on the new one.

Post Reply