Error when saving to flash

Posted on
Page
of 2
/ 2
Next
  • Hi @Gordon,

    one of my Pucks has started acting weird: Suddenly when saving code it crashed. Since then after typing reset() it will output the following:

    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v90.1890 Copyright 2016 G.Williams
    Uncaught SyntaxError: Got ?[255] expected EOF
     at line 1 col 1
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ­ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...
    ^
    >
    

    Also whenever I try to write to the flash memory it will crash. Either by typing save() or by using E.setBootCode(). My only theory is that either the flash memory is damaged or that it was somehow corrupted and the Puck firmware cannot deal with that.

    Note that except for those things it works fine. I also tried to replace the firmware with a new version, but that did not help. I am using the newest firmware. The self test is also okay, but I guess that really only checks for shorts between the exposed pins. Any idea how to check if the flash is damaged? If that's the case any idea how to fix / workaround that. Maybe by not using damaged pages?

    Thanks!

  • More information: When typing load (which I just learned about :-) ) it outputs the following:

    >load()
    =undefined
    Invalid saved code in flash!
    Uncaught SyntaxError: Got ?[255] expected EOF
     at line 1 col 1
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ­ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...
    

    Seems to support my thesis...

  • @stevie4711

    check section I saved some code and my Puck no longer works at

    http://www.espruino.com/Puck.js

    try a couple of times, if it does not work the first time.

  • Yes, I tried that but it does not change anything. The thing is, I can interact with it just fine. Just when trying to save to flash or trying to read from flash it acts up. I was thinking about using the Flash module to erase things, but don't really know the address to erase and what to write there.

  • check boards/PUCKJS.py - section 'saved_code' : {

  • Brilliant!!!! That did the trick. I did the following according to the location of the saved code:

    flash.erasePage((120 - 3) * 4096)
    flash.erasePage((120 - 2) * 4096)
    flash.erasePage((120 - 1) * 4096)

    And now everything is back to normal. Thanks a lot!

    Maybe some "eraseCode" function might be helpful. Unless it's there and I just overlooked it like the "load" function.

  • I'm pretty sure it's because you were using 'save on send' in the IDE as well as save().

    Basically 'save on send' writes the raw JS code straight into flash memory, and if you use a function it then references that memory rather than copying the code straight out. That's fine, but if you then type E.setBootCode() it'll clear what was in flash memory and will cause all the functions that were defined in flash to be erased. If you then type save() it'll save that state - including the dodgy references - to flash.

    E.setBootCode() should have cleared everything - however by itself it won't reset the interpreter state to you won't see the problem solved immediately. Probably E.setBootCode();reset() would work if you have the problem again.

  • Actually I never used the 'save on send'. So I don't think that was the reason for the corruption. Also 'E.setBootCode()' also crashed immediately, so I couldn't even type the reset(). But for now everything seems to be fine. I'll observe if the same thing happens again. But it's good to have a way out, should it ever happen again.

    Thanks!

  • Thanks!

    I actually had this issue just now, and as you say the following lines do fix it:

    var f = require("Flash");
    f.erasePage((120 - 3) * 4096);
    f.erasePage((120 - 2) * 4096);
    f.erasePage((120 - 1) * 4096);
    

    Both E.setBootCode() and reset() caused the Puck to drop the connection and restart as you say.

    Please, if anyone has this happen again, please can you post up what you did beforehand that may have made it happen? I'd really like to find a way to reproduce this so I can get to the bottom of it.

  • Hi, my Puck had the same thing happening again on the Puck which was showing it initially, just yesterday. Actually at some point I had it happening on all three. I think I did nothing special, just upload new code. Two things which are just impressions without being sure:

    • I think it never happened with 1.89, just with 1.90
    • I got the feeling that it happens after a number of uploads. Then if you erase it's gone for a while and then comes back.

    Just wanted to stress that there is no evidence about the impressions above. I was not able to reproduce it systematically.

    Thanks!

    One more things: Doing a dump() in that situation showed first the normal code and then an endless line of those Yen characters being dumped to the Web UI. It looks like a missing '\0' character at the end or so. Again, just an impression.

  • Thanks! Yes, I think I know the change that caused it (allowing dump() to write code contents set by E.setBootCode()), but I thought I'd fixed it in the recent 1.90.9 build - it still seems to be there though :(

    If you get it again, please could you run peek32(479232) and peek32(479236) and give me the results?

  • Okay, I will do that!

  • I had some similar issues here http://forum.espruino.com/conversations/­297205/

    Have looked at it again and have a 100% reproduction procedure:

    1. Setup WebIDE:

    • Reset before send [x] enabled
    • Save on send [yes, even after reset]

    2. copy into code pane (RHS) and click [^Send]

    setInterval(()=>{
      digitalPulse(LED1, 1, 100);
    }, 500 );
    

    Left console shows:

    [LOGO]
    1v90.5 Copyright 2016 G.Williams
    >Erasing Flash.....
    Writing...
    Compressed 32000 bytes to 66
    Checking...
    Done!
    =undefined
    Loading 66 bytes from flash...
    

    Result: red LED is flashing, dump shows this:

    >dump()
    setInterval(function (undefined) {digitalPulse(LED1, 1, 100);}, 500);
    // Code saved with E.setBootCode
    setInterval(()=>{
      digitalPulse(LED1, 1, 100);
    }, 500 );
    =undefined
    

    3. try reset(), but no effect: code is still there, LED is flashing

    >reset()
    =undefined
    [LOGO]
     1v90.5 Copyright 2016 G.Williams
    >dump()
    setInterval(function (undefined) {digitalPulse(LED1, 1, 100);}, 500);
    digitalWrite(D5, 1);
    // Code saved with E.setBootCode
    setInterval(()=>{
      digitalPulse(LED1, 1, 100);
    }, 500 );
    =undefined
    

    4. change code on the RHS pane to something trivial and click [^Send] again

    var x;
    

    Result some death-loop with corrupt data:

    >Erasing Flash.....
    Writing...
    Compressed 32000 bytes to 15
    Checking...
    Done!
    Loading 15 bytes from flash...
    Uncaught SyntaxError: Got ?[255] expected EOF
     at line 1 col 1
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ^
    in function called from system
    >
    =undefined
    Uncaught SyntaxError: Got ?[255] expected EOF
     at line 1 col 1
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    

    (tried on two different pucks now)
    Maybe someone else can test and confirm this.

  • I'm pretty sure that is because of what I said earlier: http://forum.espruino.com/conversations/­297591/#13376991

    I just tried this and it's easily fixed by typing reset(). I guess the IDE could just manually send a reset after E.setBootCode() to make it less likely you hit this.

    The thing @stevie4711 has is different though - it can't be recovered with reset() or any normal commands.

  • @ChristianW thanks - I just discovered a bug in how load() works. The IDE was adding load() to the end of the save to flash command, but it wasn't properly clearing out the old info.

    The next version of the firmware should have that fixed. There's a beta firmware with it fixed here: http://forum.espruino.com/conversations/­297615/

  • Hi @Gordon, would that only apply to @ChristianW's problem or also to mine?

  • This happened to me just a little while ago. Running 1v90.9. I think my device was idle. But I don't remember what it had exactly. I connected via BLE and uploaded code and got an error "processing BLE task, queueing task" or something like that. Tried upload again after a minute or so. Frozen, no response. Battery bump. Then this:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v90.9 Copyright 2016 G.Williams
    Uncaught SyntaxError: Got ?[255] expected EOF
     at line 1 col 1
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ­ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...
    ^
    >
    Disconnected
    

    So it looks like the same problem more or less. reset() worked but save() caused a restart. I reflashed with 1v90.9 but no change. I found @Gordon 's recent post and applied 1v90.12. Well the weird messages and characters are gone, and I can load a program and it runs, but save() still causes a restart. So we're not quite there yet. But I'm chill. Happy holidays everyone!

  • I never again got the weird display. But I got the disconnect on save():

    >save()
    =undefined
    Erasing Flash...
    Disconnected
    

    I then did the peeks and here is the result:

    >peek32(479232)
    =4294967295
    >peek32(479236)
    =4294967295
    

    I did nothing special, just uploaded code a couple of times.

  • Same here. I get the disconnects on save periodically, but without the characters. When it happens I have to go through the erasePage sequence, which lets save work again. But then I get the same problem again eventually. On one puck only so far. ( the one I use the most of course )

  • So I think we have a pattern here: It seems this happens at least on some pucks from time to time. The more you use save() the more often it happens.

  • I've been able to fairly consistently cause this problem on one of my pucks while I was troubleshooting some code. It occurs when I am uploading the attached file. Generally I would upload some new code, maybe save it, or not, disconnect so I can check the temperature service from my phone, then reconnect. So basically repeating the sequence. It doesn't happen frequently, but on occasion, I get the following on a save:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v90.12 Copyright 2016 G.Williams
    >
    =undefined
    >save()
    =undefined
    BLE Connected, so queueing service update for later
    Erasing Flash...
    Disconnected
    

    It seems to happen when that BLE message appears during the save. It's not unusual to see that message when the IDE console is connected. But normally it doesn't affect anything.

    At this point I have to pull the battery to get reconnected. I can upload code but I can't save it. If I try the puck disconnects. I apply the fix which is this:

    var f = require("Flash");
    f.erasePage((120 - 3) * 4096);
    f.erasePage((120 - 2) * 4096);
    f.erasePage((120 - 1) * 4096);
    

    and then I can reset() and save(), and everything is good again. Upload the code and save(), and back in business. When @Gordon gets back I'm sure he'll take a look at this scenario of the BLE message appearing during the save. If there was a way to disable services I could do that in the NRF.on("connect", ...) function. Maybe I'll try doing a reset 'on connect'. That will stop the services, and then I just need to type load() to get the code back. Services won't be running yet in this case. Or just try to remember to type reset() before uploading new code. Not really a solution though.


    1 Attachment

  • Argh! Happened to me again. Apparently reset() doesn't stop the bluetooth services after all.

    >reset()
    =undefined
    BLE Connected, so queueing service update for later
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v90.12 Copyright 2016 G.Williams
    >BLE Connected, so queueing service update for later
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v90.12 Copyright 2016 G.Williams
    >
    =undefined
    >save()
    =undefined
    BLE Connected, so queueing service update for later
    Erasing Flash...
    Disconnected
    
  • Well it happened once again but without the BLE message. Maybe a red herring there. Hmmm. New strategy. Don't save while troubleshooting/debugging.

    When I need to save options include:

    • go for it. it may work

    • pop the battery. services will not start until on-disconnect so should be safe

    • Use this technique added to on-connect from my PC addr. Connect, disconnect, then reconnect. Slightly less inconvenient than popping the battery. Verified works

  • For me it happens without the BLE message. I actually use a little cable between reset and GND to do the reset. More convenient than popping the battery. And maybe less stressful for the battery holder...

  • @stevie4711 Are you willing to share the code you are uploading/saving/running when you experience this? I'd love to see if there are similar elements. @Gordon probably has better eyes for it but I'm curious...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Error when saving to flash

Posted by Avatar for stevie4711 @stevie4711

Actions