Cannot write to EEPROM by using DATA_SEG definition

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Cannot write to EEPROM by using DATA_SEG definition

跳至解决方案
884 次查看
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 解答
624 次查看
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 回复数
625 次查看
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 项奖励
回复
624 次查看
Allem77
Contributor I

Thank you for the fast answer!

0 项奖励
回复