Simple scenario with button/IRQ/write to file that leads to ESP crash + FS coruption
Posted: Sat Aug 31, 2019 8:07 pm
Hello,
I have a very annoying problem that I discovered in the last phase of my project, when I replaced some "print()" with logging to a file. I have reduced the program to a very simple issue that illustrates the unwanted behavior:
1) I push a button
2) it's associated IRQ handler is triggered; I do "micropython.schedule()" for the actual handler
3) the actual handler writes something to a file
4) If I press the button a couple of times, then my ESP8266 reboots with the message:
NOTE: on the small program below, one needs to press rather quickly on the button in order to reproduce. On my big program, the issue was more immediate.
===========================================
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 31024, room 16
tail 0
chksum 0xb4
load 0x3ffe8000, len 1104, room 8
tail 8
chksum 0x74
load 0x3ffe8450, len 824, room 0
tail 8
chksum 0x45
csum 0x45
===========================================
5) After reboot, a lot of strange entries appear on the file system:
===========================================
>>> import os
>>> os.listdir()
['\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', '\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', '\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', ...
===========================================
6) Some times the initial files still exist on the file system. But most of the time they disappear. And I need to reflash the ESP with the Micropython image.
A simple program that reproduces this behavior:
===========================================
import uos, machine
import gc
gc.collect()
import machine
import micropython
pinRobinetButon = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
import utime
def irqHandler(pin):
micropython.schedule(sch, None)
def sch(p):
d = utime.localtime();
str = "a text"
str = "{:02d}:{:02d}:{:02d} {}".format(d[3], d[4], d[5], str);
print(str)
with open("logfile.0", "a+") as f:
f.write(str)
f.write("\n")
pinRobinetButon.irq(irqHandler, machine.Pin.IRQ_FALLING)
===========================================
Is there something illegal that I'm doing in the above code? Or maybe have you got any other hints?
Thanks a lot in advance!
Best regards,
Cristian
I have a very annoying problem that I discovered in the last phase of my project, when I replaced some "print()" with logging to a file. I have reduced the program to a very simple issue that illustrates the unwanted behavior:
1) I push a button
2) it's associated IRQ handler is triggered; I do "micropython.schedule()" for the actual handler
3) the actual handler writes something to a file
4) If I press the button a couple of times, then my ESP8266 reboots with the message:
NOTE: on the small program below, one needs to press rather quickly on the button in order to reproduce. On my big program, the issue was more immediate.
===========================================
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 31024, room 16
tail 0
chksum 0xb4
load 0x3ffe8000, len 1104, room 8
tail 8
chksum 0x74
load 0x3ffe8450, len 824, room 0
tail 8
chksum 0x45
csum 0x45
===========================================
5) After reboot, a lot of strange entries appear on the file system:
===========================================
>>> import os
>>> os.listdir()
['\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', '\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', '\x00\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00', ...
===========================================
6) Some times the initial files still exist on the file system. But most of the time they disappear. And I need to reflash the ESP with the Micropython image.
A simple program that reproduces this behavior:
===========================================
import uos, machine
import gc
gc.collect()
import machine
import micropython
pinRobinetButon = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
import utime
def irqHandler(pin):
micropython.schedule(sch, None)
def sch(p):
d = utime.localtime();
str = "a text"
str = "{:02d}:{:02d}:{:02d} {}".format(d[3], d[4], d[5], str);
print(str)
with open("logfile.0", "a+") as f:
f.write(str)
f.write("\n")
pinRobinetButon.irq(irqHandler, machine.Pin.IRQ_FALLING)
===========================================
Is there something illegal that I'm doing in the above code? Or maybe have you got any other hints?
Thanks a lot in advance!
Best regards,
Cristian