Windows 11 problem with Erasing/Flashing ESP32

Hi all, I have an ESP32 based device and PlatformIO project.

Chip erasing and flashing are working perfectly on Windows 10 but on Windows 11 I’m unable to do it even if the device (COM port) is recognized?

What can be wrong?

Please take a look at log below:

Processing devenv_up (platform: https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream; board: heltec_wifi_lora_32_V2; framework: arduino)
----------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/heltec_wifi_lora_32_V2.html
PLATFORM: Espressif 32 (3.3.1+sha.3784198) > Heltec WiFi LoRa 32 (V2)
HARDWARE: ESP32 240MHz, 320KB RAM, 8MB 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)
PACKAGES: 
 - framework-arduinoespressif32 0.0.0 
 - tool-esptoolpy 1.30100.210531 (3.1.0) 
 - toolchain-xtensa-esp32 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 54 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <LittleFS_esp32> 1.0.6
|   |-- <FS> 2.0.0
|-- <Ticker> 3.2.0
|-- <Adafruit INA219> 1.1.1
|   |-- <Wire> 2.0.0
|   |-- <Adafruit BusIO> 1.9.1
|   |   |-- <Wire> 2.0.0
|   |   |-- <SPI> 2.0.0
|   |-- <SPI> 2.0.0
|-- <KXTJ3-1057> 0.0.1
|   |-- <Wire> 2.0.0
|-- <ArduinoJson> 6.18.4
|-- <NimBLE-Arduino> 1.3.1
|-- <PCF8563_Library> 0.0.1
|   |-- <Wire> 2.0.0
|-- <CRC32> 2.0.0
|-- <RadioLib> 4.5.0
|   |-- <SPI> 2.0.0
|-- <mcommon> 1.0
|-- <miniz> 1.0
|-- <mupgrade> 1.0
|   |-- <mcommon> 1.0
|   |-- <mwifi> 1.0
|   |   |-- <mcommon> 1.0
|   |   |-- <miniz> 1.0
|-- <ESPPerfectTime> 0.3.0
|-- <TinyGSM> 0.11.4
|-- <StreamDebugger> 1.0.1
|-- <Wire> 2.0.0
|-- <FS> 2.0.0
|-- <mwifi> 1.0
|   |-- <mcommon> 1.0
|   |-- <miniz> 1.0
|-- <SPI> 2.0.0
|-- <WiFi> 2.0.0
Building in release mode
Looking for serial port...
Auto-detected: COM3
Erasing...
esptool.py v3.1
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____....._____

Open a CLI and execute pio run -t erase -v. What is the output?

Below you can see the log

pio run -t erase -v
Processing devenv (platform: espressif32; board: nodemcu-32s; framework: arduino; board_build.partitions: partitions_custom.csv; monitor_speed: 115200; lib_deps: lorol/LittleFS_esp32@^1.0.5, sstaub/Ticker@^3.2.0, adafruit/Adafruit INA219@^1.1.1, ldab/KXTJ3-1057@^0.0.1, bblanchon/ArduinoJson@^6.18.3, h2zero/NimBLE-Arduino@^1.3.1, lewisxhe/PCF8563_Library@^0.0.1, hunamizawa/ESPPerfectTime@^0.3.0, vshymanskyy/StreamDebugger@^1.0.1; extra_scripts: ./littlefsbuilder.py; lib_ldf_mode: deep+)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/nodemcu-32s.html
PLATFORM: Espressif 32 (3.4.0) > NodeMCU-32S
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)
PACKAGES:
 - framework-arduinoespressif32 3.10006.210326 (1.0.6)
 - tool-esptoolpy 1.30100.210531 (3.1.0)
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 49 compatible libraries
Scanning dependencies...
Warning! Classic Pre Processor is used for `D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\KXTJ3-1057\src\kxtj3-1057.cpp`, advanced has failed with `'charmap' codec can't decode byte 0x9d in position 8180: character maps to <undefined>`
Warning! Classic Pre Processor is used for `D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\KXTJ3-1057\src\kxtj3-1057.h`, advanced has failed with `'charmap' codec can't decode byte 0x9d in position 2490: character maps to <undefined>`
Dependency Graph
|-- <LittleFS_esp32> 1.0.6 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\LittleFS_esp32)
|   |-- <FS> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|-- <Ticker> 3.2.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\Ticker)
|-- <Adafruit INA219> 1.1.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\Adafruit INA219)
|   |-- <Wire> 1.0.1 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|   |-- <Adafruit BusIO> 1.9.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\Adafruit BusIO)
|   |   |-- <Wire> 1.0.1 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|   |   |-- <SPI> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|   |-- <SPI> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|-- <KXTJ3-1057> 0.0.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\KXTJ3-1057)
|   |-- <Wire> 1.0.1 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|-- <ArduinoJson> 6.18.4 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\ArduinoJson)
|-- <NimBLE-Arduino> 1.3.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\NimBLE-Arduino)
|-- <PCF8563_Library> 0.0.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\PCF8563_Library)
|   |-- <Wire> 1.0.1 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|-- <ESPPerfectTime> 0.3.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\ESPPerfectTime)
|-- <StreamDebugger> 1.0.1 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\.pio\libdeps\devenv\StreamDebugger)
|-- <Wire> 1.0.1 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|-- <FS> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|-- <mcommon> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mcommon)
|-- <mwifi> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mwifi)
|   |-- <mcommon> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mcommon)
|   |-- <miniz> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\miniz)
|-- <mupgrade> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mupgrade)
|   |-- <mcommon> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mcommon)
|   |-- <mwifi> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mwifi)
|   |   |-- <mcommon> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\mcommon)
|   |   |-- <miniz> 1.0 (D:\Projects\Upwork\Markus\git\arduino-dev\FIRMWARE\TestApps\RECENT_TESTS_DEMO\lib\miniz)
|-- <SPI> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|-- <WiFi> 1.0 (C:\Users\milan\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
Building in release mode
MethodWrapper(["erase"], [])
Auto-detected: COM3
"C:\Users\milan\.platformio\penv\Scripts\python.exe" "C:\Users\milan\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32 --port "COM3" erase_flash
esptool.py v3.1
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x5B)
*** [erase] Error 2
=========================================================================================== [FAILED] Took 35.89 seconds ===========================================================================================

Does regular uploading fail in the same way?

What USB-Serial converter chip is installed on your ESP32 target board?

Does a board with a different USB-Serial converter work?

It is the same error with the Upload command.

cp2102 is used.

For example, ESP32 DevKit v4 is working fine.

Does uploading also fail in the Arduino IDE?

The same result is in Arduino IDE.

I found out that I need to hold one button on my board in order to start flashing. I’m 100% sure that I don’t need to do this on Windows 10 machine.

Not being able to reset the board is an indication that the DTR and RTS signals of the USB-serial controller weren’t well-controllable by esptool.py (these lines pulse RESET and GPIO0 for the reset). This possibly has something to do with the drivers used in Windows 11. I don’t have that operating system so I can’t be sure.

Since it fails both in the Arduino IDE and PlatformIO for you that culprit should thus be either esptool.py or the used serial drivers. You should open an issue at Issues · espressif/esptool · GitHub to get the developers there on board with your problem.

EDIT: I see that this issue is now tracked in Windows 11 problem with connecting to ESP32 (ESPTOOL-374) · Issue #706 · espressif/esptool · GitHub.

Thank you for that. Hope this issue can help other people by giving them a clue what can be wrong on Windows 11.