-->
Page 1 of 1

Flash sector calculations

PostPosted: Tue Sep 29, 2015 11:15 am
by mvdbro
Giving this calculation inside EEPROM class and the documentation stating that EEPROM start right after SPIFFS:

EEPROMClass EEPROM((((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE);)

is it true that _SPIFFS_end points to the first sector after SPIFFS area?

Or is EEPROM emulation actually using the last sector of SPIFFS area?

I'm planning to use the 32kB SPiFFS area for custom purposes and i'm not sure about the proper calculations...

Would this be safe:

uint32_t _firstsector = ((uint32_t)&_SPIFFS_start - 0x40200000) / SPI_FLASH_SEC_SIZE;
uint32_t _lastsector = ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE;

Or would it wipe EEPROM emulation area?

Re: Flash sector calculations

PostPosted: Tue Sep 29, 2015 4:51 pm
by igrr
SPIFFS resides in the address range from _SPIFFS_start to _SPIFFS_end, last address not included.
So if _SPIFFS_start is 0x40300000 and _SPIFFS_end is 0x40400000, the final dword used by spiffs would be located at 0x403ffffc.

With _firstsector and _lastsector calculated as in your post, you would iterate over them as follows:

for (uint32_t sector = _firstsector; sector < _lastsector; ++sector) { ...

i.e. as in an open-ended range.

Re: Flash sector calculations

PostPosted: Wed Sep 30, 2015 4:47 am
by mvdbro
Thanks for your reply! It's clear to me now.

Just finished the code and I can now save and load a bunch of data structs to 32kB flash area without using EEPROM emulation and without using SPIFFS. Saves a lot of valuable RAM and program storage!