Cannot write to EEPROM by using DATA_SEG definition

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

Cannot write to EEPROM by using DATA_SEG definition

ソリューションへジャンプ
932件の閲覧回数
Allem77
Contributor I

Hello,

I m trying to write a value in the EEPROM at the address 0xFC0800. It functions with the following code:

/* Definition */
uint16 u16_bootloaderFlag @ 0xFC0800;

/* changing the value */
u16_bootloaderFlag = 0xABCD;


But the following code won't work:

/* prm file */
...
EEPROM_FC_BOOT = READ_ONLY DATA_FAR IBCC_FAR 0xFC0800 TO 0xFC081F; /* 32 Bytes used for the bootloader variables */
...


/* Definition in .c the file*/
#pragma DATA_SEG BOOTLOADER_FLAG
uint16 u16_bootloaderFlag; /* Located in the banked EEEPROM see .prm file */
#pragma DATA_SEG DEFAULT

/* changing the value */
u16_bootloaderFlag = 0xABCD;

After this line, the bootloaderFlag is equal to 0. By the way, the map file confirms me that the u16_bootloaderFlag variable is located at 0xFC0800.

Am I missing something in the declaration of the prm file to get write access?

Thanks for your help!

PS: uC = HCS12X

ラベル(1)
0 件の賞賛
返信
1 解決策
672件の閲覧回数
sebasira
Senior Contributor I

Hello Allem77!

 

EEPROM is non-valotile memory and In order to write/erase it you need special routines.... Some tips:

- An EEPROM address is erased when its value is 0xFF

- In order to re-write EEPROM, you first need to erased it and then write the new value.

- You should also know that it is dword aligned (4bytes) and that's the minimmun erase size... If  you're trying to erase a single byte, the other 3bytes from that "block" would also be erased. See the next graphic:

 

                       4bytes                            4bytes              

     +---------------+---------------+

     | x | x | x | x | x | x | x | x |

               ^

               If tryng to erase this byte, the other from the same block would also be erased

 

 

                       4bytes                                                        4bytes              

     +---------------------------+---------------+

     | 0xFF | 0xFF | 0xFF | 0xFF | x | x | x | x |

 

 

Take a look at page 1039 for 2k EEPROM or page 1073 for 4k EEPROM, from MC9S12XD family reference manual. And you may also find some examples routines.

 

Best Regards!

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
673件の閲覧回数
sebasira
Senior Contributor I

Hello Allem77!

 

EEPROM is non-valotile memory and In order to write/erase it you need special routines.... Some tips:

- An EEPROM address is erased when its value is 0xFF

- In order to re-write EEPROM, you first need to erased it and then write the new value.

- You should also know that it is dword aligned (4bytes) and that's the minimmun erase size... If  you're trying to erase a single byte, the other 3bytes from that "block" would also be erased. See the next graphic:

 

                       4bytes                            4bytes              

     +---------------+---------------+

     | x | x | x | x | x | x | x | x |

               ^

               If tryng to erase this byte, the other from the same block would also be erased

 

 

                       4bytes                                                        4bytes              

     +---------------------------+---------------+

     | 0xFF | 0xFF | 0xFF | 0xFF | x | x | x | x |

 

 

Take a look at page 1039 for 2k EEPROM or page 1073 for 4k EEPROM, from MC9S12XD family reference manual. And you may also find some examples routines.

 

Best Regards!

0 件の賞賛
返信
672件の閲覧回数
Allem77
Contributor I

Thank you for the fast answer!

0 件の賞賛
返信