How to fix ESP32 A fatal error occurred: ESP32 ROM does not support function erase_flash.

Problem:

When running esptool erase_flash, you an error message like:

esptool.py v2.8
Found 1 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 7c:9e:bd:f4:60:e0
Enabling default SPI flash mode...
Erasing flash (this may take a while)...

A fatal error occurred: ESP32 ROM does not support function erase_flash.

Solution:

You are likely using an outdated version of esptoolUse the esptool from GitHub:

git clone https://github.com/espressif/esptool.git

then run it using

cd esptool
python3 esptool.py erase_flash