Clear a MDBT42Q module from all code?

Posted on
  • So, after a lot of debugging I have now realised how the "Flash (always)" works and what a "reset()" actually means. It's not a reset or reboot, it's a system clear. And my broken code is now written with "Flash (always)" so my two dev modules are now bricked.

    So how do I get them back? A DFU update does nothing.
    Is there any other way to program the module and clear the flash???

  • How 'bricked' they are? you cannot access Espruino console over serial or bluetooth - wherever the active console is? You cannot press ctrl+c on the console (left side in web ide or over serial teminal) to get debug prompt debug>? see https://www.espruino.com/Debugger

    If you can break into debugger after startup to see the debug> prompt then your running code is stopped and you could hopefully run print require("Storage").eraseAll() from debugger to clear the storage.

    With serial console it may be easier - reset or poweron the module with serial already open and immediately try ctr+c

  • If you have a MDBT42Q Breakout

    • remove power
    • press button
    • power up
    • release button when red led is switched off

    this procedure will startup the firmware without loading your code and give you the possibility to connect and remove the code.

  • Oh, maybe that will work too when there is original espruino bootloader which clears it before jumping into Espruino?

    Otherwise when BTN1 is held at startup time the code is skipped except the code marked as "flash always", that one still runs even with button held. This was confimed by some unlucky guys and is also described here https://www.espruino.com/Saving - Boot Process - holding button is exactly like running reset() (sets hasBeenReset) so .bootrst still runs.

  • First of it turns out the webIDE had gotten it self in some state, closing the browser and opening it again allowed me to connect and get a prompt, at least long enough to run reset() to clear out the bad code.
    So at least one of the modules are now running again, will check on the other one later.

    I have now installed the chrome app, and that seam to be more stable and works better.

  • so you can run require("Storage").eraseAll() that will clear everything - the .bootrst one and also one possibly created by running save()

  • Tried it, this is the output..

    >require("Storage").eraseAll()
    =undefined
    Uncaught SyntaxError: Got [ERASED] expected EOF
     at line 1 col 1
    [ERASED]...
           ^
    in function called from system
    Uncaught SyntaxError: Got [ERASED] expected EOF
     at line 1 col 1
    [ERASED]...
           ^
    in function called from system
    Uncaught SyntaxError: Got [ERASED] expected EOF
     at line 1 col 1
    [ERASED]...
           ^
    

    And it goes on and on like that.

  • well yes, so just reboot/powercycle it, if you had code running from flash this was all erased at the point of calling eraseAll so code inside setWatch, setInterval is suddenly hitting empty flash where it expected javascript program to be

  • what is the result of

    require("Storage").list()

  • here is the information about startpoint and size of the save code

    https://github.com/espruino/Espruino/blo­b/eca6aae8104ddaca66dfe317d3b76243962f43­32/boards/MDBT42Q.py#L66

    maybe you can use the flash lib to clear the pages

    http://www.espruino.com/Reference#Flash

  • you shouldn't need to, that's what Storage.eraseAll does

  • As @fanoush says, require("Storage").eraseAll() will get rid of everything - but if you had stuff in RAM then that will still run, and if it references stuff that was in flash you'll get the Got [ERASED] expected EOF error - a simple reboot will fix it permanently.

    The easiest fix for that is actually just to do this to clear the device:

    require("Storage").eraseAll();reset()
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Clear a MDBT42Q module from all code?

Posted by Avatar for JohanWinas @JohanWinas

Actions