Storage not able to write, but Flash can?

Posted on
  • I am running the P8 SPIFLASH version of Espruino by @fanoush on a similar smart watch, but I have managed to get the Flash memory into a strange state whereby I cannot write to it with the Storage class.

    The Flash is writeable - I can update the bootloader and flash Espruino builds to it. I can also erase, read and write flash pages, but any attempt to write a file fails with a timeout. Rebooting doesn't help. This device has been working well, and I had been reading and writing to Storage, but it seems that something is out of alignment!

    process.memory()
    ={ free: 2490, usage: 75, total: 2565, history: 50,
    gc: 0, gctime: 3.69262695312, blocksize: 16, stackEndAddress: 536928984, flash_start: 0,
    flash_binary_end: 396828, flash_code_start: 1610612736, flash_length: 524288 }
    require("Flash").getFree()
    =[
    { addr: 397312, length: 86016 }
    ]
    require("Storage").getFree()
    =4194304
    require("Flash").read(8,397312)
    =new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255])
    require("Flash").write("hello",397312)
    =undefined
    require("Flash").read(8,397312)
    =new Uint8Array([104, 101, 108, 108, 111, 255, 255, 255])
    require("Storage").list()
    =[ ]
    require("Storage").write("test.dat","hel­lo")
    Uncaught InternalError: Timeout on jshFlashWrite
    at line 1 col 44
    require("Storage").write("test.dat","hel­lo")


    1 Attachment

    • Espruino.png
  • at least P8 watch has SPI shared with display, didn't you try writing to display? also the flash chip can be sleeping, you can try something like

    FCS=D5;
    var fc=new SPI();fc.setup({sck:D2,miso:D4,mosi:D3,m­ode:0});
    fc.send([0xab],FCS);//wake flash from deep sleep
    fc.send([0x90,0,0,1,0,0],FCS) // get flash id
    fc.send([0x9f,0,0,0],FCS); //get flash id
    

    hopefully it should print something else than all zeroes or all FFs

  • Thanks @fanoush. The flash module appears to work, so I doubt anything is wrong with SPI interface. I know storage module does wear levelling, so I assume it caches its state somewhere, and maybe that has become corrupted. Is there a way to wipe the storage entirely and start again? I tried, but managed to wipe the bootloader instead!

  • Sorry, worked it out - I had misunderstood the process.memory readout! It reads: flash_code_start: 1610612736, flash_length: 524288

    So I just did this and everything works:

    f=require("Flash");
    for (i=0;i<524288;i+=4096) {
      print("erasing:",i);
      E.kickWatchdog();
      f.erasePage(1610612736+i);
    }
    
  • oh, there is require("Storage").eraseAll(), a bit more straightforward :-)

  • I tried that several times, but it didn't help. I'm not sure why, I've looked at the code, and it does erase the same area.

  • The flash module appears to work, so I doubt anything is wrong with SPI interface.

    The code above that worked is writing internal nrf52 flash, not SPI flash. Something was probably wrong with SPI flash at that time - you got the " InternalError: Timeout on jshFlashWrite at line 1 col 44" which looks like bad communication over SPI. Anyway, looks like it is working now.

  • Thanks for the help, and explaining the difference between internal and external flash. I'm glad it started working, but I'm at a loss to work out what made it better. It's possible the battery ran down and it restarted.

  • Flash API was previously only for internal nrf52 flash, with Bangle.js Gordon added virtual mapping of SPI flash to 0x60000000 so now it does both based on address, see https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/jshardware.c#L228­9

    the require("Flash").getFree() gives you flash area that is unused and safe to write. Writing outside it overwrites espruino firmware binary or DFU bootloader. Or Storage as you found out.

    but I'm at a loss to work out what made it better. It's possible the battery ran down and it restarted.

    the SPI code I pasted could wake it up from sleep or setup SPI pins again, but if it worked before then I don't know, power cycling could help of course too

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

Storage not able to write, but Flash can?

Posted by Avatar for Mark_wllms @Mark_wllms

Actions