Program doesn't execute the same after save() in flash #5453
Replies: 1 comment
-
Posted at 2016-10-14 by @yerpj I cannot give you an answer but I can maybe give you a workaround. Instead of using onInit(), maybe try to make your own init function, with some delay before execution:
Without knowing exactly why, with this trick, I was able to let most of my scripts work even when invoked from flash. FYI, I had the same behaviour with some I2C displays . Posted at 2016-10-15 by @allObjects There are things (1) that are initialized/executed at upload of the code, and there are things (2) that have to be re-initialized on power up. The Configurations/settings - for example pin modes - get saved AND are then restored before Post your code, then we can do an analysis. Take also a look at simple explanation how to save code that espruino run on start? conversation. Posted at 2016-10-15 by GeekBot Gents, thanks a lot, I think I have to study the post you mention before asking dumb questions! I think my problem is reinit at power up. So, I study and come back to you. Posted at 2016-10-15 by GeekBot Hello Experts, May be there are other ideas I have not reported. I think my code follow these rules, but it doesn't work! (yet). Thanks a lot for your help. GeekBot Posted at 2016-10-16 by @allObjects Pretty much sums up the application part... Regarding the restore from FLASH: it is everything as it was at the moment when Think of One thing you left out in your list: BEFORE a) happens, chip configs - most importantly, port configs - are restored... And to be accureate, Good practice is not to save something dynamic, such as a timeout or interval. Therefore (Personally - and in general - I do not like the fact that hardware initialization/restore - such as port modes - is part of the power up; but with well defined power-on behavior and resource strapped Espruino, it is very helpful - in various ways... Btw, you are thinking 'Arduino' style - no offense to be taken here... The coding model is totally different... (Espruino almost bents itself over, because it has now an option in the setting that lets it almost behave the same: after upload completion, the upload makes a save, and then behaves like the invocation of onInit() or invocations of E.on("init",...). Posted at 2016-10-16 by GeekBot @allObjects, thank you for these detailed explanations, I understand how it works. What happens when I click on the connection icon in the IDE? Posted at 2016-10-16 by @allObjects There was a time when USB was unplugged and console.log() was used, the console.log (serial) buffer was filled and Espruino hanged... But as said, this was a while ago... There is something else you need to know: if you use a string variable with the module name in require(), such as
instead of a string literal in require(), such as
then the upload cannot (recursively) discover ***in the source code by string search for 'require("...")' the required modules and does not upload them into the cache (before uploading that particular source code); and when it comes to the runtime - the actual execution of the require(...) - Espruino cannot find the module in the cache and then tries to find it in THE (or A) connected SD card... But that error shows in a very distinctive error message about no (SD card) file system mounted where the module could be found... The option to use a variable instead of string literal for requiring a module and prevent loading of the module into the cache at upload time is intentional, because this allows to enable runtime/dynamic module selection, but it requires the module to be accessible in runtime available - mounted - file system. Again, have to make this point: Espruino/JavaScript is a totally different runtime concept! When for modules the cache concept is used, it does not mean that actual code (bytes of)(virtual) machine or source code is moved around (from cache space into execution space) - like from a file cache, as you have in, for example a PC operating system. The cache caches the object - like an interpreted/executed function definition, which is just referenced... nothing is moved around (like in virtual machine memory cache of objects of the virtual machine). For Espruino, this means that
shows that the things left and right of the === are one of the same thing: identical. What are the symptoms you get of this not starting correctly? Posted at 2016-10-16 by GeekBot I have found the problem. It's a mix up between Serial1 and USB console. Forcing the console on USB did the trick. So now the system is working in the same way, connected to IDE or disconnected. Thanks for your help and explanations. Posted at 2016-10-16 by @allObjects There you go... and that answers your questions: the difference is that console is connected differently... (I interpret it that if USB data connectivity - IDE conneted - is discovered, console is routed/forced to USB, otherwise not and has all kinds of adverse effects... on serial1(?)). Posted at 2016-10-17 by @gfwilliams Just to add - if you call |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-10-14 by GeekBot
Hello,
My program works like a charm when I click on the download button and type onInit().
If I download and type save(), the program is copied to the flash memory (no error, everything ok (apparently)).
But it doesn't execute the same. Symptoms are linked to timing, for instance I get timeout on AT commands.
What can be different between IDE (ram) execution and flash execution ?
Any clue ?
Thanks a lot
GeekBot
Beta Was this translation helpful? Give feedback.
All reactions