ESP32: Erase Flash Memory (Factory Reset)

This is a quick guide showing how to erase the ESP32 flash memory to restore it to its original state. This might be useful if you want to delete any changes made to the firmware or configuration settings; if the system is crashing constantly and you can’t upload new code; to clear data that is no longer needed, and other applications. We’ll use a tool called esptool.

ESP32 Erase Flash Memory Factory Reset firmware


To perform an ESP32 factory reset, we’ll use esptool, which is “a Python-based, open-source, platform-independent utility to communicate with the ROM bootloader in Espressif chips.

To install esptool, you need Python 3.7 or newer installed on your system. You can download and install Python at the following link (make sure you download the right package for your system):

With Python 3 installed, open a Terminal window and install the latest stable release with pip:

pip install esptool

Note: with some Python installations that command may not work and you’ll receive an error. If that’s the case, try to install with:

  • pip3 install esptool
  • python -m pip install esptool
  • pip2 install esptool

Setuptools is also a requirement that is not available on all systems by default. You can install it with the following command:

pip install setuptools

After installing, you will have installed into the default Python executables directory and you should be able to run it with the command esptool. In your Terminal window, run the following command:

python -m esptool

If it was installed properly, it should display a similar message (regardless of your operating system):

esptool utility

Erasing the ESP32 Flash

Follow the next steps to erase the ESP32 flash:

1) Connect the ESP32 to your computer;

2) Open a Terminal window on your computer;

3) Hold the ESP32 BOOT button;

ESP32 BOOT button

4) Copy the following command to your terminal window and press Enter (continue holding the BOOT button).

python -m esptool --chip esp32 erase_flash

5) When the “Erasing” process begins, you can release the “BOOT/FLASH” button. After a few seconds, the ESP32 flash memory will be erased.

ESP32 erase flash esptool

Note: if after the “Connecting …” message you keep seeing new dots appearing, it means that your ESP32 is not in flashing mode. You need to repeat all the steps described earlier and hold the “BOOT/FLASH” button again to ensure that your ESP32 goes into flashing mode and completes the erasing process successfully.


If you encounter a permission error while trying to run the esptool command, open the command prompt as a administrator (or as sudo on Linux).

run commands as an administrator command prompt

Wrapping Up

This was a quick guide showing you how to erase the ESP32 flash to perform a factory reset. We hope this tutorial is useful.

If you’re using an ESP8266 board, you can follow the instructions in the following tutorial:

If you would like to learn more about the ESP32 board and IoT, make sure you take a look at our resources:

Thanks for reading.

Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…

Enjoyed this project? Stay updated by subscribing our newsletter!

53 thoughts on “ESP32: Erase Flash Memory (Factory Reset)”

      • invalid syntax every time, I followed your instructions trying all the possible entries
        I went over to Espressif and they said to …… pip install esptool it also did not work????
        invalid syntax
        I want to get this to work it is a great tool to clean out bugs

          • this might be the problem?
            Note If you’re a newcomer and you get an error like this:
            python –version
            Traceback (most recent call last):
            File “”, line 1, in
            NameError: name ‘python’ is not defined
            It’s because this command and other suggested commands in this tutorial are intended to be run in a shell (also called a terminal or console). See the Python for Beginners getting started tutorial for an introduction to using your operating system’s shell and interacting with Python.

          • Are you able to run the commands on the Terminal window?
            We mention in the tutorial that you need to open a Terminal window…
            I’m sorry for the misunderstanding.

          • I was having the same problem and found my system did not have the path to python set. I did a new full install with all option checked “set path” and all worked fine.

    • Hello! sara thanks for your post.

      i am coming to add

      james firstly open your cmd
      –> write “python” and enter (you need internet) (start to download python 3XXX)
      –> after in your write “pip install esptool” and enter ( installing esptool)
      –> after write “pip install setuptools” and enter ( installing setuptools)
      –> write “python -m esptool” and enter
      –>follow this Erasing the ESP32 Flash of Sara
      –>in your cmd write this commande , change COMXX by your COM and enter
      “python -m esptool –port COMXX write_flash_status –non-volatile 0”


  1. Thank you for this tutorial, but there is something that I don’t understand:
    The post starts by “… you can’t upload new code …”, and your solution is based on “… install Python …”. Isn’t it contradictory ?
    Or does that mean that you advise to install python on each new ESP32, even if you don’t use it (Arduino IDE instead), just in case you would need to do a factory reset ?

    • Hi.
      You don’t need to install Python on the ESP32.
      You need to install Python on your computer so that you can install a tool called esptool on your computer, not on the ESP32.

  2. FYI,
    The ESP tool is good for both ESP32 and ESP8266 (nodeMCU) boards with the “–chip auto” switch. I have been using it to clear flash storage structures while testing. You can use the following syntax for either board. Just change the COM port to where your board is connected. I have python and python3 in my system path so no need to call it.

    In the CLI navigate to your esptool folder and type –port COM3 –chip auto –before no_reset –baud 115200 erase_flash

    and if you want to restore a factory bin image make sure its in the same directory and use –port COM5 –before no_reset –baud 115200 write_flash 0 factory_WROOM-32.bin


  3. Thank you for this tutorial.
    My ESP32, connected on “COM5” always fails. I try a lot of times with “boot” button and the result is always the same:
    PS C:> python -m esptool –chip esp32 erase_flash v4.5.1
    Found 2 serial ports
    Serial port COM5
    COM5 failed to connect: Failed to connect to ESP32: Wrong boot mode detected (0xb)! The chip needs to be in download mode.
    For troubleshooting steps visit:
    Serial port COM3
    COM3 failed to connect: Failed to connect to ESP32: No serial data received.
    For troubleshooting steps visit:

    A fatal error occurred: Could not connect to an Espressif device on any of the 2 available serial ports.
    PS C:>

    Do you think that this could be a hardware malfunctioning? It is a new one that I bought some months ago.

    • Hi.
      As the error mentions, your ESP32 is not in flashing mode.
      You may need to hold the BOOT button when the dots start showing up.
      Do you have any peripherals connected to your board?
      Which board are you using?
      Were you able to program your board before?


      • i have same problem.
        C:\Users\claw>python -m esptool –chip esp32 erase_flash v4.6.2
        Found 4 serial ports
        Serial port COM9
        COM9 failed to connect: Could not open COM9, the port doesn’t exist
        Serial port COM16
        COM16 failed to connect: Failed to connect to ESP32: No serial data received.
        For troubleshooting steps visit:
        Serial port COM15
        COM15 failed to connect: Write timeout
        Serial port COM1
        COM1 failed to connect: Failed to connect to ESP32: No serial data received.
        For troubleshooting steps visit:

        A fatal error occurred: Could not connect to an Espressif device on any of the 4 available serial ports.

      • hola, no consigo borrar el ESP32, es nuevo y se haquedado bloqueado por una mala programación. Lo he probado instalando arduido IDE, python, con la herramienta online, con el grabador flash…y nada, se queda colgado mientras salen puntos.
        no consigo que nada funcione, simplemente no responde, detecta el puerto COM utilizado pero no se deja borrar.
        ¿puede haberse estropeado definitivamente o se puede resetear seguro?
        necesito ayuda, gracias.

        • Hola Marcel, lo que me funciono a mí es conectando un condensador entre la toma de tierra y el reset, el condensador debe ser de 10 microfaradios, dependiendo de microcontrolador debes conectarlo a otras tomas, busca en Youtube “Fixing a hardware ESP32 Upload problem” el vídeo del usuario Xtronical ahí lo explican muy bien.

          • Hola Daniel, gracias por la info me sirve de mucho! tengo una pregunta adicional yo no cuento con la tarjeta que aparece en el video de Xtronical en ese caso como hago?? podrias ayudarme

  4. Hi,
    Can this software work also with ESP32-CAM ? I have two of them that I cannot upload anymore. They seem dead, or not communicating.

      • You can also erase the flash in PlatformIO by clicking on the little alien on the sidebar.
        under project tasks click on the board you are using.
        then click on platform and the erase flash menu will appear.

    • If you have python 3 installed but not in your system path then you have to invoke it with python3 -m and for python 2 you do python -m supports both python 3 and python 3.


  5. PS C:\Users\riza manalo> pip install setuptools
    pip : The term ‘pip’ is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and
    try again.
    At line:1 char:1
    + pip install setuptools
    + ~~~
    + CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    can’t recognize pip

  6. Failed to communicate with the flash chip, read/write operations will fail. Try checking the chip connections or removing any other hardware connected to IOs
    how to resolve this error??

      • I get the same error.

        PS C:\Windows\system32> python -m esptool –chip esp32 erase_flash v4.6.2
        Found 1 serial ports
        Serial port COM8
        Chip is ESP32-D0WDQ6-V3 (revision v3.0)
        Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
        Crystal is 40MHz
        MAC: d4:d4:da:5a:de:c8
        Uploading stub…
        Running stub…
        Stub running…
        WARNING: Failed to communicate with the flash chip, read/write operations will fail. Try checking the chip connections or removing any other hardware connected to IOs.
        Erasing flash (this may take a while)…

        A fatal error occurred: Packet content transfer stopped (received 8 bytes)
        PS C:\Windows\system32>

        This is a brand new ESP-WRover Dev V1.6.
        I thought I would try this erase operation, as I cannot write to thie flash on this device. This erase operation also does not work.

        • Does it have a BOOT/FLASH button?
          Try to hold-down the button after you see the “Connecting…” message.

  7. hey, i cant enter in the bootloader because i uploaded a program that prevents the esp32 to enter the bootloader, is there any other way to factory reset without bootloader?

  8. Re ESP32-S3 You might get this error:

    “COMXXX failed to connect: This chip is ESP32-S3 not ESP32. Wrong –chip argument?
    A fatal error occurred: Could not connect to an Espressif device on any of the X available serial ports.”

    Solution: change the line to
    “python -m esptool –chip esp32s3 erase_flash”

    On some boards, the button to hold down on the ESP board might be labeled “RST” rather than “BOOT”

    Thank you Sarah and Rui, as always your tutorials are incredible. I can only imagine the wonderful things people are creating because you two empower them. Respect.

  9. Hi, i finish erasing the Flash of my ESP32-SOLO-1. am i suppose to reflash it with the same factory settings or it just reboots itself?

  10. Hello, I am using the ESP32 wroom (30 pins – Dev Module). I erased the Flash Memory by writing the codes on my windows terminal (codes: python -m esptool –chip esp32 erase_flash).
    now whenver I connect my esp32 to my laptop with the USB cable it floods my serial monitor screen with “e (7238) task_wdt: esp_task_wdt_reset(763): task not found” repeatedly almost for 20 seconds then after it runs my original codes

    is there any solution to fix it?


Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.