Hey guys ihave a question about saving data to flash memory.
In my task i define variables
#define var1 (*(vuint8 *)(0x8002))
after that i want to load var1 with values from the flash memory
const var1fl = 0xFF;
var1 = var1fl ;
please could someone tell me if i am on the right way ?
hi, there is some confusion in your request
to write a value in the flash memory, you have to proceed in several steps, there are specilized flash commands for this, see your flash chip datasheet.
You can just read from the flash like another memory, as:
{
volatile unsigned short *FLASH_ADDR= (volatile unsigned short *)0xffc00000;
unsigned short read_value= *FLASH_ADDR;
}
regards
I am not why you need to use hard coded addresses.
const int varFL=0xff; // this is in Flash because it is constint var1; // this is SRAM because it is NOT const......var1 = varFL; // Done, initialized from flash.
My example was hardcoding the flash base address, to be sure it is understood to be in flash.
The fact a variable is "const" don't mean it is in the flash. Code can be relocated to ram.
Angelo,
Actaully I was refering to the OP mention of:
#define var1 (*(vuint8 *)(0x8002))
It's true that depending on your lcf file, it might not be in flash, as you could be loading everything into ram.
However, normally consts are put in to flash.
Here is a snippit from and lcf file, showing that .rodata goes into flash
{ *(.text) . = ALIGN (0x4); *(.rodata) . = ALIGN (0x4); ___ROM_AT = .; ___DATA_ROM = .; } >> code