-->
Page 1 of 2

Where in the flash map can I safely store configuration info

PostPosted: Wed Nov 30, 2016 4:37 pm
by RexBrown
Not sure if this is the right place for this but if not let know and I will try another area.
I have a need to be able to store configuration data in flash. I also have a need to be able to do updates via a web server (i.e.ESPhttpUpdate.update()) . I have written code to manage the flash which works and finally got the OTA update to work. However, the update seems to be overwriting at least part of the area where my configuration data is stored.
I read another post where the 0x80 - 4 sector was used. That is near the top of the 512 K boundary and I expect it would get overwritten. However in the esp12e we are using there is 4 Meg of flash, where the top 3 meg is used by SPIFFS. I don't need the SPIFFS and my code is below the 512K boundary. I tried setting the flash area at the 4 Meg - 4 sector location but it seems to be getting overwritten when I do an OTA update using ESPhttpUpdate.update(). Is there a place where I can locate the config data that will not be overwritten? (I have allocated 512 bytes because that is the size of the RTC user mem which I use for dynamic storage of the config data).
Thanks for your help.

Re: Where in the flash map can I safely store configuration

PostPosted: Thu Dec 01, 2016 9:31 am
by martinayotte
This doc should help : http://esp8266.github.io/Arduino/versio ... ystem.html

Assuming you choose 4M/1M config, since the OTA will use location just below SPIFFS and sketch size is limited, knowing that Flash start at 0x40200000 and SPIFFS at 0x40500000, I would presume that 0x40300000 is the best location where nothing will overwrite your configs.

Re: Where in the flash map can I safely store configuration

PostPosted: Thu Dec 01, 2016 11:19 am
by RexBrown
Thanks. Actually I had selected the 4M/3M option, not really knowing which was better. According to the doc you referenced the SPIFFS part of the FLASH is not modified during an OTA update which is a little confusing since the configuration space I chose should have been just below the WiFi config (4 sectors down) at the top of the FLASH (highest location) just above the SPIFFS.

However, I will use your recommendation to set the configuration to 4M/1M and locate my configuration information at the 4030 0000 address. Thanks very much for your help! :D

Re: Where in the flash map can I safely store configuration

PostPosted: Thu Dec 01, 2016 12:22 pm
by RexBrown
I need to clarify one additional point related to writing to Flash. In my code I use the following to access FLASH:
piFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);

where I expected the src_addr parameter to be the byte address in the FLASH (i.e. not offset from 0x40200000).
for instance the address I used for a byte at the beginning of the second sector would be 4096 since the sector size is 4096. So, which is the correct method of specifying the address?

NOTE: Using the method I gave above I have been able to read and write the flash successfully up to now.
Thanks again for your help.