Repair broken / unwritable ESPs

This has happened to me a couple of times and I’ll write it here as much to keep it in memory !

Symptom: ESP suddenly refuses to update from Arduino or update SPIFFS / LittleFS.

In my experience this shows up as an MD5 error after any upload. The chip restarts and continues running the old code!

On investigation, I have found that I can also get an error “Superblock 0x0 has become unwritable”.

What might have happened?
It’s consistent with the ESP chip (ESP32 or ESP8266) having somehow set a write protection bit.

Fix it
This is a bit contentious. While the fix certainly works, I have read that there can be “side effects”.
I’m happy to say that I have not noticed any ill effects..

So : Reset the flash_status…
(Be sure to enter your own chip type and com / cu port !)

python3 esptool.py --chip esp32s2 --baud 115200 --port /your.port write_flash_status --non-volatile 0

After confirming that the chip returns a satisfactory response:

Initial flash status: 0x4200
Setting flash status: 0x0000
After flash status:   0x0000
Hard resetting via RTS pin...

Now go ahead, erase the chip completely and it’s ready for software installation.

python3 esptool.py --chip esp32s2 --port /your.port erase_flash