I was having trouble figuring out why some random strings keep appearing at the UART (default port) after the system boots and starts executing my code. For example, I have 2 modules and when I burn the same program to both of them – they look for different access points to connect to and I did not even program either of that! All I did was LCD interface related coding only. This made me feel that some part of the flash that is not erased is responsible for this. If you have similar issues, here is how you may erase ESP8266 flash completely.
The programmer I used here was the one provided by Espressif Systems on their downloads page. More specifically, it is the ESP flash tool v.2.3, which you may download from Espressif Systems.
The issue with this version of the tool is that it just does not have a “erase flash” option. I guess I could use the command line interface to erase a specific range, but what I found more convenient was to just have a blank file that can be put into any location to effectively erase that range. For having blank flash blocks, you usually just need a blank.bin provided by Espressif Systems. Then program it into the area you want to erase.
But the blank binary is 4K in size only! So I created a larger version of it (1 MB or 8 Mbit). You can make your own too, you just need a file that contains 0xFF inside it. The size of the file will determine the length of flash area that will be erased.
Erase ESP8266 flash memory
To erase a 1MB range with this blank_1M.bin file, just download the file and set it for uploading to wherever you want it to be written.
In this case, I want 0x000000 to 0x100000 to be erased, so here is what I put into the Flash Download tool:
If you want to erase entire flash, for example of an ESP-12 E module, which has a 4MB flash memory chip, you need to upload the blank_1MB.bin file to 0x000000, 0x100000, 0x200000 and 0x300000. This will put 0xFF in the range 0x000000-0x3FFFFF. Which is same as clearing the entire flash!
By the way, this is what the ESP8266 prints out when booting if all of the internal memory is clean:
Now enjoy a brand new, “clean” memory free from saved information from previous sessions! If you have anything to say, or need a custom sized blank.bin, do leave a comment below…Download blank_1MB.bin (ZIP)