mcf 5223 initializing non volatile register  with values from non volatile memory

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

mcf 5223 initializing non volatile register  with values from non volatile memory

1,141件の閲覧回数
PEGE
Contributor I

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 ?

ラベル(1)
0 件の賞賛
返信
4 返答(返信)

938件の閲覧回数
angelo_d
Senior Contributor I

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

0 件の賞賛
返信

938件の閲覧回数
JimDon
Senior Contributor III

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.

 

0 件の賞賛
返信

938件の閲覧回数
angelo_d
Senior Contributor I

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.

 

 

0 件の賞賛
返信

938件の閲覧回数
JimDon
Senior Contributor III

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

 

 

0 件の賞賛
返信