Cannot write to EEPROM by using DATA_SEG definition

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cannot write to EEPROM by using DATA_SEG definition

Jump to solution
918 Views
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

Labels (1)
0 Kudos
Reply
1 Solution
658 Views
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!

View solution in original post

0 Kudos
Reply
2 Replies
659 Views
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 Kudos
Reply
658 Views
Allem77
Contributor I

Thank you for the fast answer!

0 Kudos
Reply