ESP32 Erase Flash Memory (Factory Reset)

Description

  • Recently, we are working on one project with ESP32 and just wanted to change the SSID of the Wi-Fi access point.
  • As usual, we change the SSID in the code and upload it to the ESP32 board, But when we test it wouldn’t change the SSID name.
  • It still shows the old SSID, which means it still had the old project data that we used in the last project.
  • In this case, we know there is an option to erase all memory in ESP32 like factory reset.
  • Every time when we program ESP32, Arduino IDE rewrite the code on existing one, because, if it has to perform Erase, it would have taken lot of time i.e. 1-2 minutes based on data presence. If we are constantly making changes in the code, programming ESP32 would have become so much time consuming. 

When we need to Erase Flash Memory?

There are multiple scenarios, where we need to erase ESP32 flash memory.

  1. When we are switching from Arduino programming to Python programming.
  2. Code is not uploading properly.
  3. ESP32/ NodeMCU crashing randomly.
  4. Old code configuration visibility i.e. Wi-Fi SSID, etc.
  5. Random behaviour of the firmware.

 

Does Erasing Flash removes the Bootloader?

Answer is no. The Bootloader is stored in secure and hidden space in the flash memory and it shouldn’t be erased. 

Just for information, What will happen if the ESP32 bootloader erased?

ESP32 will become lifeless, repairing it will become complex task. ESP32 won’t accept any code, it won’t be detected on COM port. Whatever the code in it, it won’t execute.

Another question asked is, does erasing flash reduces the Flash memory Lifespan?

As we know, Flash memory has some limit of Read/Write cycles. If we go through the Flash memory datasheet, it’s around 10K to 100K. It’s huge. Also it depends on how much data presence in flash, if it’s small, it will only affect that small portion of flash. Considering 100k lifecycles and every 15 mins erase cycles, and 128Kb data portion in flash, it will take more than 1000 years to end its lifespan.

 

Now that we understood why we need to erase the ESP32 and it’s safe to do so, Let’s see how to erase flash:

We will need esptool to earase flash memory of ESP32. Let’s install it.

 

Erase ESP32 flash memory with Windows

Step 1

Download Python for windows on your computer using the below link and install it.

https://www.python.org/downloads/

 

Step 2

Now open the command prompt. To open it press the windows button on your keyboard and type cmd

 

Now click on the command prompt to open it

Step 3

In this step, we will install esptool using a command prompt to install it copy the below command and paste it onto the command prompt.

Note: make sure your Python version and correct it on the command.

In our example, we installed python 3.10 so we have entered py -3.10  on command.

py -3.10 -m pip install esptool

 

Step 3

Copy the below command and paste it onto the command prompt.

py -3.10 -m esptool

 

Step 4

Connect your ESP32 board to your computer.

 

Step 5

This command is to erase the ESP32 flash memory.

Now copy the below command and paste it into the command prompt, before entering make sure your com port, my ESP32 board is connected to COM8, if you have a different com port then current it on the command line and press enter.

py -3.10 -m esptool --chip ESP32 --port COM8 erase_flash

Components Used

ESP32 WROOM
WiFi Development Tools - 802.11 ESP32 General Development Kit, embeds ESP32-WROOM-32E, 4MB flash.
1
Ad