GPY rogue safe mode reboots
-
@robert-hh So when you say 'try development release versions of the firmware' Rob you mean versions after the 1.18.1.r7 we're running now? My problem with later releases is that the code run time between deepsleeps if nearly doubled with later versions. Ours is a battery powered application so that's why we've been sticking with 1.18.1.r7. Also, if I understand you correctly, later versions like v1.20.0.r13 use the littlefs file system which is even more prone to corruption than 1.18.1.r7s FAT?
-
@kjm With v1.20.0.rtc13 you have the choice between FAT and littlefs. I cannot tell a lot about boot times, only that they seem slow. I have no GPy for testing, only FiPy. And that may be similar. The difference I noticed between 1.18. and 1.20 is, that the LTE modem is already started during boot without instantiating the LTE class. That may be the reason for increased boot time.
-
@robert-hh I don't understand why our user code in main.py is subject to corruption when strings we store in a regular python file with f.write or integers we store with pycom.nvs_set are never corrupted. Do you know if all 3 are stored in the same flash memory? If yes any thoughts on why main.py is more susceptible to corruption than the other two?
-
@kjm They all are stored in the same flash chip. The nvs store is in a different memory region. So that is not affected by re-creating the file system. I wonder why just main.py and boot.py are re-created, but not any other file. Because recreating these w/o touching other files would only happen if they cannot be opened during boot. If the filesystem cannot be mounted, it will be recreated, deleting all files in it.
-
@robert-hh I agree that boot.py & main.py are being recreated after the machine wakes from a deepsleep & can't open one of them. The question is why? I think it must be down to dodgy flash. I've got a hunch it might be temperature related, this only seems to happen when we mount them outside with a solar panel. Inside the enclosure can get up to 50 Celsius here in Australia. Surely flash should remain functional at 50 celsius?
-
@kjm IIRC there have been quite a few discussions about corruption of the filesystem when mixing writing to files and deep sleep. Something like the write not being fully finished before going to sleep and the filesystem being left in an inconsistent state. I guess this would most probably happen any time a file crosses a cluster boundary. But my understanding is that the whole flash would be wiped, not just the two files.
Don't remember all the details, especially whether that was with "native" deep sleep (
machine.deepsleep) or Pysense/Pytrack-controlled deep sleep (or both), nor whether that was fixed in some release in the firmware.I believe littleFS was actually introduced especially for this reason (and I see at least one post saying switching from FAT to littleFS fixed a similar issue).
Sorry, don't have the time right now to dig in the forum (just found a bunch of posts with issues similar to yours), but this could give you pointers to look for.
Things you can try:
- switch to littleFS (requires an upgrade)
- upgrade to get a newer version which may include some fixes?
- make sure you properly close files before going to deep sleep, and possibly adding a small delay before sleep. Not really what you want to hear in terms of power efficiency, though.
-
-
@kjm If the flash file system cannot be mounted, then it will be recreated, erasing all files.
If the file system exists, then main.py and boot.py will be independently tested for existence and then re-built.
Before boot.py and main.py, the scripts _boot.py and _main.py are executed. These reside in the firmware as frozen bytecode. You can change these only if you create your own firmware.
Beyond that, my personal style is to keep main.py short and mostly on import my bulk code there. So if my code is in e.g. my_main.py, main.poy would include a statement 'import mymain'.
That will not prevent file corruption, if that happens e.g. due to unfinished writes. -
@robert-hh Interesting Rob;
- So instead of machine.main('mycode.py') in your main.py you use import mycode.py instead? Are these not equivalent?
- You say that boot.py & main.py are independently tested for existence, presumably boot.py first then main.py?
- If we had import mycode.py in both boot.py and main.py would that double our chances of success? That is, if boot.py was missing or corrupted would it then load our code via main.py instead & only rebuild boot.py as the default (insert your code here) blank?
-
- machine.main('mycode.py') executes mycode.py instead of main.py, while importing mycode.py in main.py executes both.
- Funny enough, the test for main.py is first, then boot.py
- if mycode.py never terminates, then you can do that. Putting it into boot.py would result in main.py nerver being executed. The actual bott sequence is:
a) _boot.py
a.1) on Gpy and FiPy: start modem.
b) if not safeboot: boot.py
c) _main.py
d) if not safeboot: main.py or whatever is defined by machine.main()
That is related to the most recent master branch, file mptask.c, lines 280-330
-
- Currently we have machine.main('main.py') in our boot.py & the user code in main.py The thinking was if boot.py failed to run main.py then main.py should be the next thing it trys. Is this thinking correct in terms of getting 2 chances for the user code to run?
- If we had the user code in user.py and machine.main('user.py') in both boot.py & main.py, would that be a better option in terms of getting 2 chances for the user code to run?
- The last line in the user code is a machine.deepsleep, does that qualify as 'never terminates'?
-
- Running main.py is the default. So machine.main("main.py") will not change anything, if main.py is corrupted.
- Putting machine.main("user.py") into main.py has not effect, because the file named by machine.main() will be executed INSTEAD of main.py and has to be called, before main.py or whatever is named as replacement is called. You can put 'machine.main("user.py")' into boot.py, and 'import user.py' in main.py. Then you have a double chance.
- Yes. machine.deepsleep() qualifies as 'never terminates', because on wakeup from deepsleep the device reboots. Please take care of @jcaron's hint about closing open files before calling deepsleep().
-
@robert-hh Suppose we have 2 identical copies of the user code, user1.py & user2.py. In boot.py we have import user1.py and in main.py we have import user2.py, would the following be correct?
- It tries boot.py If all OK main.py never runs because the the user code is non terminating.
- If boot.py or usercode1.py are missing/corrupted it rebuilds boot.py to the default.
- It then tries main.py which should run the backup user2.py
We always close any open files so that's not the cause of our woes
-
-
- Not seeing evidence of a corrupted file system Robert, all nvs.sets and error.log files are OK. Just boot.py & main.py have been rebuilt to the 'put-your-code here defaults'. Might actually skip the imports & simply have 2 independent copies of the user code at boot.py & main.py
- Just checked the code, we don't actually close files, we use 'with open' which does not require file closure. Is that OK?
- What if I'm wrong & boot.py & main.py have been rebuilt due file system corruption. Is there a way of dealing with this?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login