Storing data in flash memory is clashing.

Hi,

I'm using a Due in my project.

I'm using the DueFlashStorage library to read and write values to the Due's flash. I'm using the library to store and retrieve user configurable settings, status values that represent the result from last operation performed, and the like.

Read: dueFlashStorage.read(address, byte data);
Write: dueFlashStorage.write(address, byte data);

I'm also storing a couple of large images (322x184 & 444x85) to be displayed on a 480x320 tft screen.

Stored as:
static const uint16_t imageName = { (image data as uint16 pixels) };
static const uint16_t imageName2 = { (image data as uint16 pixels) };

I've found that the data stored by the DueFlashStorage library and the images are clashing. I first realised this because i can see the setting values as pixels in the middle of an image - i've confirmed this by sending each and every pixel color value to the serial monitor - the values of these pixels tallies up with the user configurable setting values. Not ideal. If i only store one image, this issue doesn't appear; it doesn't matter which image is stored.

The bodgy way of fixing is to use different addresses with DueFlashStorage to see when the issue goes away. But i'd like to understand why the two clash and know how to go about finding available space in the flash to use with the DueFlashStorage library.

The address inputted as a parameter for the read/write of the DueFlashStorage library appears to be an offset from what ever is considered to be the start of the flash.

byte DueFlashStorage::read(uint32_t address) {
return FLASH_START[address];
}

Digging in to the header:

#define FLASH_START ((byte *)IFLASH1_ADDR)

I can't seem to find IFLASH1_ADDR within the DueFlashStorage library. Does this mean it's predefined constant in the library for the Due?

Futhermore, i guess there is a IFLASH0_ADDR? And if so, does this mean the images i'm storing have completed filled one bank (let's call FLASH0 and FLASH1 banks) and overlapping in to the next bank?

The IDE states "Write 286484 bytes to flash (1120 pages)". I calculate the two images are 118496 and 75480 bytes in size.

arduino_user33:
I can't seem to find IFLASH1_ADDR within the DueFlashStorage library. Does this mean it's predefined constant in the library for the Due?

Yes it is.

void setup() {

Serial.begin(250000);
printf("IFLASH0_ADDR = 0x%X\n",IFLASH0_ADDR);
//IFLASH1_ADDR = IFLASH0_ADDR + IFLASH_SIZE / 2
printf("IFLASH1_ADDR = 0x%X\n",IFLASH1_ADDR);
}

void loop() {

}

See page 31 of Sam3x datasheet.

Thanks! Problem solved.

Not wanting to change the library just in case there is an update some time in the future, i decide to my alter my offsets. I now calculate the offset from the end of the flash storage; so it’s essentially filling from the end to the front.

I wonder why the author of the library chose not to fill the flash from end to front. hmm…