Completely format or erase ESP8266 flash memory

posted in: Internet of Things (IoT) | 22

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.

Programmer used

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:

Erase ESP8266 flash memory completely
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:

Output on booting ESP8266 with clean formatted flash


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)



22 Responses

  1. Charlie BART

    hey man,
    where can i find this blank_1m.bin file?
    i’m getting tired of this esp12 not working…

    • Hello Charlie,
      I have fixed the post and added a button to download the file at the end of the article.
      Let me know if it solved your problem… 🙂

      – Pratik

  2. Hi Pratik,
    Why do you have such baud rate (74880)? What default baud rate esp communicates at after flash erase?

    • After flash erase, the baud rate is 74880 if you are using a 26MHz crystal. For 40MHz crystal, I think baud rate is 115200

  3. Hi there

    I tried this – the problem is – it looks like it is wiping the entire 4MBYTE but if you look at the address bar, at least on the current version – it is actually repeatedly wiping the first meg.

    Using the tool that Espressif supply I appear to have had more luck with this – and it works in a second.

    C:\Espressif\utils> -p COM3 -b 115200 erase_flash

    • You could make a combined BIN of all to suit your flash. 🙂
      And you’re right, the command will work as well.

  4. Ok, so I have a new problem – oh KAROL – 78k is the baud rate set by Expressif for power up debug – sadly there is no way to control this – you can have any baud you like in your own software – but at powerup – 78k – you have to wonder what they were thinking of because most terminals can’t DO 78k!!! I wrote my own.

    Ok, so my new problem – when I was messing with SDK 1.54 and getting no-where I noted I could not write to the LAST 1 Meg in the 4 meg block. I could write slightly LESS than that. I dismissed it when I found the esptool.

    But – I have a board now which will NOT do anything other than complain about system parameter error – turns out this is in the TOP of the 4th MEG – and I THINK the reason I’m having difficulty is because that last block is write protected.. so the ESPTOOL appears to wipe everything EXCEPT that write protected bit…. I simply can’t get past this – I wonder if there is a tool or a flag to ensure the ENTIRE 4MB is wiped – including any write protected areas??!!!?!?

    • I wouldn’t know the reason for this for sure. The flash chips do come with write protection and usually that is OTP. So if that gets programmed by mistake, you’re stuck permanently. This used to be a major issue with memory cards as well. You can just lock the card by mistake and then you can never erase it again.
      I’d just recommend using completely Espressif solutions for ESP8266. The other tools are made without accurate knowledge of the hardware employed and will usually do more harm than good.

  5. Bob Green

    Regarding the 74880 baud rate. Coolterm can use any baud rate that you set in an INI file. I set up a baud rate of 74880 and its works really well.
    either find a file called baudrates.ini or make it in a text editor then inside it simply put 74880. That baud rate will then appear in the baud rate selection drop down list. Easy and coolterm is a really good package and free!

    • I use RealTerm on Windows 10. 🙂
      74880 is fine as long as the USB-UARt converter and the terminal software both support it.

  6. Bob Green

    Pratik, my point was that the information spewed out at power, baud rate 74880, can be viewed in Coolterm. This enables the user to see what is being output and this can help in debugging. The USB-UART converter can be a factor but the variety of converters I have all work even the FTDI clones!

  7. Bob Green

    Pratik, further to Peter’s point about erasing the whole 4M can you clarify something for me please. In my simple mind I would assume that if the BIN file erases 1M then it would start at zero and write 0xFF to each location. The location would be incremented by 1 and then the write occurs again until the 1M boundary is reached.
    Therefore even though you set the address to 0x100000 it still starts at zero. OR does it start at the address set and then increment to the next boundary.
    In other words why does the counter at the bottom of the screen not display according to the base address set?

    • In the end the only tool I could reliably assure myself I’d wiped the whole lot – was/is esptool.exe – well under Windows anyway. so for example:

      esptool.exe -p COM3 -b 115200 erase_flash

      That has been so successful, along with ensuring that I re-flash the radio information at the very top of memory along with my code – that I’m no longer having issues. I’ve added this as an option in Eclipse – in the makefile.

      $(ESPTOOL) -p $(ESPPORT) -b $(ESPBAUD) erase_flash

      • Bob Green

        Peter, Thanks for the reply I was aware the method you use works and I have used too, so we have a good tool! My question was really trying to understand Pratik’s approach better. It does seem to erase the first 1M Ok and has helped me sort out a few ESP’s that were malfunctioning. I use the Expressif flash tool and so it is quiet easy to Pratik’s 1M erase BIN within that tool.

        • Hello Bob,
          Sticking to Espressif official tools guarantees that your design doesn’t become obsolete or incompatible suddenly. That’s why I wrote this making use of official flash tool.
          As for BIN files, they are just data bytes. Unlike HEX files, they do not contain any address information. Therefore you have to supply an offset where the file contents are written to. Thats why dumping blank files all over the flash range acts as erase operation. Also, simply erasing a block doesn’t mean it is working. Writing 0xFF can cause failure on faulty sectors and actually point out potential faulty sectors when programming some chips.

          • Bob Green

            Pratik, thanks for your explanations, very helpful. A number of people have commented on various sites that erasing the flash has enabled their new code to run as expected. I appreciate that erasing the flash doesn’t necessarily mean it is working or, if faulty, that it will be repaired. None the less it is a useful thing to try if one is experiencing problems with loading or executing code.
            I’ll look forward to more postings from you.

          • I have this small startup and consultancy idea that will help people get their IoT designs up and running. The website should have a lot of new content at
            Do check on there from time to time for detailed info and code samples for ESP8266. And of course I post here as well 🙂

  8. Hello
    thanks super

  9. I recently played with ESP8266 and use erase_flash to erase the flash. I am using linux. Thanks for your great post and discussion.

  10. cool dude

    i wanted blank.bin for 4k
    please give me download link

Leave a Reply