-->
Page 1 of 2

writing to flash without using SPIFFS

PostPosted: Mon Nov 21, 2016 8:12 am
by mph070770
I'm using a NodeMCU and the arduino IDE and want to write data to flash...

I assume using SPIFFS with a file system etc means that it's not a quick to write data as writing to the flash directly?

I want to be able to write data to flash (up to 200KB as 1 "file") and read it back later - it's never going to leave the device so it doesn't need to be a specific file format.

If I use ESP.flashRead / ESP.flashWrite and ESP.flashSectorErase and handle byte alignment myself, can I assume it will be quicker than using SPIFFS? If so, how do I determine where in the flash is safe to write? How do I swap flash banks if that's necessary and do I need to select a module configuration that doesn't include a reserved area for SPIFFS?

I'd really appreciate any guidance...

Re: writing to flash without using SPIFFS

PostPosted: Mon Nov 21, 2016 10:11 am
by martinayotte
Yes, using direct flash sectors would be faster than SPIFFS.
If you don't mind loosing your Raw data when doing an OTA, I would recommend using the Flash space just above the SPIFFS.

Re: writing to flash without using SPIFFS

PostPosted: Mon Nov 21, 2016 2:09 pm
by mph070770
Hi Martin,

Thanks for confirming that it should be faster. If I can assume this is the correct place to get the official memory map:

http://www.espressif.com/en/support/exp ... ted-guide#

where is SPIFFS located and how can I tell where it ends? I assume to use it I'll need to swap flash banks or does ESP.flashWrite work on physical sectors of the SPI memory?

Thanks

Re: writing to flash without using SPIFFS

PostPosted: Mon Nov 21, 2016 3:37 pm
by martinayotte
SPIFFS and other memory mapping are described here : https://github.com/esp8266/Arduino/blob ... esystem.md
For specific SPIFFS address locations, you need to look in LD scripts depending of your Flash configs, for example, if you have a 4M module and use 1M SPIFFS, the script is https://github.com/esp8266/Arduino/blob ... sh.4m1m.ld.
This LD script shows _SPIFFS_start = 0x40500000 and _SPIFFS_end = 0x405FB000.
Knowing that OTA will use the space just above _SPIFFS_start with size of the sketch, you can assume that writing your raw data somewhere like 0x40300000, it is pretty safe that even OTA won't overwrite it.