AnsweredAssumed Answered

Write data on flash memory at execution time

Question asked by colla.ivan on Feb 3, 2016
Latest reply on Feb 22, 2016 by Erwan Y
Hello everyone,

in the past day I tried to save some data on the flash memory of the micro controller, but without results.

Reading the documentation, I cannot understand exactly how I can write data on a specific address of the flash memory and retrieve it.

I want to write 3 int 32 starting from 0x0008_0000, the High Address Space. My application is loaded on 0x0 of the flash, so I have space.

At first I tried

*(ULONG*)0x00080000 = ulConfigValueTimeCrc;
*(ULONG*)0x00080004 = ulConfigValueStatCrc;
*(ULONG*)0x00080008 = ulConfigValueFlashCrc;

where the three values aare unsigned int (32 bit).

I tried to retrieve them with 

ulConfigValueTimeCrcLoaded = (*(ULONG*)0x00080000);
ulConfigValueStatCrcLoaded = (*(ULONG*)0x00080004);
ulConfigValueFlashCrcLoaded = (*(ULONG*)0x00080008);

The strange thing is that at 0x00080000 is written the correct value, but the other memory area remain to 0xFFFFFFFF.
Another strange thing is that if I try other addresses in that address space (0x0008_0032, for example), the micro go in error.

I tried, reading the manual, this procedure:

CFLASH.MCR.B.PGM = 1;
 
*(ULONG*)0x00080000 = ulConfigValueTimeCrc;
*(ULONG*)0x00080004 = ulConfigValueStatCrc;
*(ULONG*)0x00080008 = ulConfigValueFlashCrc;
 
CFLASH.MCR.B.EHV = 1;
while (CFLASH.MCR.B.DONE == 0)
{
    /* Wait until the MCR DONE = 1 */
}
 
if (CFLASH.MCR.B.PEG == 0)
{
    systemStatus->ubSystemStatus = IN_ERROR;
}
 
CFLASH.MCR.B.EHV = 0;
CFLASH.MCR.B.PGM = 0;

but with no results.

Can someone see where the problem is with the examples above? Maybe someone can explain me better how writing on flash at execution time can be done.

Thank you,
     Ivan 

Outcomes