My NodeMCU program has gone in to infinite reboot loop.
My code is functionally working but any action I try to do, e.g. file.remove("init.lua")
or even just =node.heap()
, it panics and reboots saying: PANIC: unprotected error in call to Lua API (not enough memory)
.
Because of this, I'm not able to change any code or delete init.lua
to stop automatic code execution.
How do I recover?
I tried re-flashing another version of NodeMCU, but it started emitting garbage in serial port.
Then, I recalled that NodeMCU had two extra files: blank.bin
and esp_init_data_default.bin
.
I flashed them at 0x7E000
and 0x7C000
respectively.
They are also available as INTERNAL://BLANK
and INTERNAL://DEFAULT
in the NodeMCU flasher.
This booted the new NodeMCU firmware, all my files were gone and I'm out of infinite reboot loop.
Flash the following files:
0x00000.bin to 0x00000
0x10000.bin to 0x10000
And, the address for esp_init_data_default.bin depends on the size of your module's flash.
0x7c000 for 512 kB, modules like ESP-01, -03, -07 etc.
0xfc000 for 1 MB, modules like ESP8285, PSF-A85
0x1fc000 for 2 MB
0x3fc000 for 4 MB, modules like ESP-12E, NodeMCU devkit 1.0, WeMos D1 mini
Then, after flashing those binaries format its file system (run "file.format()" using ESPlorer) before flashing any other binaries.
Downloads Link
I've just finished working through a similar problem. In my case it was end-user error that caused a need to forcibly wipe init.lua
, but I think both problems could be solved similarly. (For completeness, my problem was putting a far-too-short dsleep()
call in init.lua
, leaving the board resetting itself immediately upon starting init.lua
.)
I tried flashing new NodeMCU firmware, writing blank.bin
and esp_init_data_default.bin
to 0x7E000
and 0x7C000
, and also writing 0x00000.bin
to 0x00000
and 0x10000.bin
to 0x10000
. None of these things helped in my case.
My hardware is an Adafruit Huzzah ESP8266 breakout (ESP-12), with 4MB of flash.
What worked for me was:
- Download the NONOS SDK from Espressif (I used version 1.5.2 from http://bbs.espressif.com/viewtopic.php?f=46&t=1702).
- Unzip it to get at
boot_v1.2.bin
, user1.1024.new.2.bin
, blank.bin
, and esp_init_data_default.bin
(under bin/ and bin/at/).
- Flash the following files to the specified memory locations:
boot_v1.2.bin
to 0x00000
user1.1024.new.2.bin
to 0x010000
esp_init_data_default.bin
to 0xfc000
blank.bin
to 0x7e000
- Note about flashing:
- I used
esptool.py
1.2.1.
- Because of the nature of my problem, I was only able to write changes to the flash when in programming mode (i.e. after booting with GPIO0 held down to GND).
- I found that I needed to reset the board between each step (else invocations of
esptool.py
after the first would fail).
- Erased the flash.
esptool.py --port <your/port> erase_flash
- Then I was able to write a new firmware. I used a stock nodeMCU 0.9.5 just to isolate variables, but I strongly suspect any firmware would work at this point.
The only think that worked for me was python flash tool esptool in ubuntu, windows flashtool never deleted init.lua and reboot loop.
Commands (ubuntu):
git clone https://github.com/themadinventor/esptool.git
cd esptool
python esptool.py -h
ls -l /dev/tty*
nodemcu_latest.bin can be downloaded from github or anywhere.
sudo python esptool.py -p /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 nodemcu_latest.bin