Uploading to ESP32 via FTDI FT230X?

Where is the script that calls the esptool? I am using the Linux VSCode/PlatformIO package.

The reason I ask, is that in the Arduino environment I was able to add a wrapper called esptool-ftdi.py (by Jim Paris GitHub - jimparis/esptool-ftdi: esptool.py wrapper for FTDI devices to use RTS/CTS instead of RTS/DTR) around the esptool command that solved all my FDTI problems.

Can I do the same for the Platformio Environment?

Regards, M.

Well first of all things are managed a bit differently in PlatformIO. The esptool script is a package, and packages are referred to in a platform’s platform.json file, and then the platform (your case: espressif32) uses that packages and calls binaries or scripts in it, with customaziable options.

If you want to add esptool-ftdi.py as a test, you should follow the documentation to use a custom upload tool.

All other things would require platform modifications, this can be done in the project as a test.

But I don’t get why that script is needed? Doesn’t the esptool.py already work with all general USB-UART adapters? If there’s something to fix, why not fix it in the main esptool.py repo?

I think the critical word here is “WORK”? Yes, esptool will talk to a FT23x chips but esptool will not correctly control the reset/upload ( EN/IO0) sequence. I quote directly from Jim Paris’s github:

This esptool.py wrapper lets you use RTS/CTS for ESP8266/ESP32 chip resets instead of the usual RTS/DTR. It only works with FTDI-based USB to serial adapters.

Normally, CTS is an input. On FTDI chips, CTS can be reconfigured as an output by entering bitbang mode. This wrapper replaces all of the internal esptool.py serial routines with direct calls into libftdi1 and libusb-1.0 to dynamically switch between normal and bitbang modes as needed to make the typical reset-into-bootloader sequence work.

If there is an easier route to program ESP32 custom board without physical access to the typical PROG & RESET buttons, I’d love to hear about it.

Many regards, M.

1 Like

Did you get it to work with a custom upload protocol?

No. Not yet!

Can I confirm the advice you have kindly offered?

  1. platformio/platform-espressif32/blob/2615af95057b4df0a0abf72773c1937607cdd610/builder/main.py#L299-L314

This is a snippet from the source code to highlight that Platformio is different to the Arduino environment and NOT intended for me to modify my copy in some way?

  1. The route I should follow; is to use the advice in the documentation? The extent of which is between the headings Custom Upload Tool and CustomOCDTool?

If the above is correct, my familiarity (48hrs) with Platfomio is insufficient to make any further progress on this problem. The learning delta is too big to warrant switching.

I was hoping for a quick 'n dirty way to do this:
In ~/.arduino15/packages/esp32/hardware/esp32/1.0.4/platform.txt (last but 1 line)
tools.esptool_py.upload.pattern.linux=python “{path}/esptool-ftdi.py” “{path}/{cmd}” --chip esp32 --port “{serial.port}” <…line truncated…>

i.e. Make the original esptool command a parameter of esptool-ftdi.py

Best regards, M.

Let me just quickly write something up.

Can you please try the following thing.

As platformio.ini

platform = espressif32
board = esp32dev
framework = arduino
extra_scripts = wrap_esptool_ftdi.py

and then in the project’s root folder (same level as platformio.ini), add the wrap_esptool_ftdi.py file

# check if we need to install pip modules (pyusb)
# in PlatformIO's isolated python environment
    import usb.core 
except ImportError: 
    print("Failed to import USB lib. Installing dependency.")
            '$PYTHONEXE -m pip install "pyusb"',
            "Installing esptool_ftdi's Python dependencies",
prev_uploader = env["UPLOADER"]
prev_flags = env["UPLOADERFLAGS"]
# if this tool in your global PATH; if not, use direct path variable below
#esptool_ftdi_path = "esptool-ftdi.py"
esptool_ftdi_path = "C:/Users/Max/Downloads/esptool-ftdi-master/esptool-ftdi.py"
# the new tool just takes as argument the complete invocation line of the old tool.
# exchange uploader fot esptool-ftdi.py and move esptool.py and old arguments as new args.
    UPLOADERFLAGS=[prev_uploader] + prev_flags

while either adapting the esptool_ftdi_path value or commenting it out and uncommenting the line above.

For me, this leads to a successfull wrap (look at invocation in Verbose Upload)


Now of course since I’m on Windows I don’t have libusb so that part fails, but the tool also states it only works for Linux.

Yep! I tried…

> Executing task in folder 201205-104709-esp32dev: pio run --target upload <

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (2.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
 - framework-arduinoespressif32 3.10004.201016 (1.0.4) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - tool-mkspiffs 2.230.0 (2.30) 
 - tool-openocd-esp32 2.1000.20200709 (10.0) 
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 26 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
NameError: name 'env' is not defined:
  File "/home/mprowe/.platformio/penv/lib/python3.6/site-packages/platformio/builder/main.py", line 178:
    env.SConscript(item, exports="env")
  File "/home/mprowe/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/mprowe/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/mprowe/Documents/PlatformIO/Projects/201205-104709-esp32dev/wrap_esptool_ftdi.py", line 5:
Failed to import USB lib. Installing dependency.
==================================================== [FAILED] Took 0.74 seconds ====================================================
The terminal process "pio 'run', '--target', 'upload'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

… and how is Verbose enabled?
Verbose mode can be enabled via -v, --verbose option

… are the millions of references like “$ pio run -t upload -v” assuming that Platformio-cli is installed?
Should/would Platformio-cli be installed with the VSCode extension? When I look to install from my installer reports conflicts?

Regards, M.

Weird. As if the first line of the script was missing or not executed. Can you show a screenshot of your VSCode window with the script file opened?

Just use the Verbose Upload build task.


With the VSCode PlatformIO extension, that core is auto-installed. Everything builds on the core. Just like the documentation says, the CLI commands can also be accessed there. However, doing it via the CLI is not needed here. All works with the GUI, too.

Dho… :blush: Missed the first line in the cut 'n paste!!

What a star you are. Works perfectly. Thank you.

Regards, M.

At the end, did you guys manage to get the upload (with auto /RST and GPIO0-EN selection) to work with the FT230X?

According to that yeah. Since I don’t have the hardware I could never test it. Did you test the instructions above?