How do I progaram default values into eeprom?

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

How do I progaram default values into eeprom?

Jump to solution
2,040 Views
btbhass
Contributor II
I am trying to program the eeprom in a MC9S08 micro but with no success.
It has something to do with the Linker file?

/* This is a linker parameter file for the mc9s08sl8 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
Z_RAM = READ_WRITE 0x0080 TO 0x00FF;
RAM = READ_WRITE 0x0100 TO 0x027F;
ROM = READ_ONLY 0xE000 TO 0xFFAD;
EEPROM = READ_WRITE 0x1780 TO 0x17FF;
/* INTVECTS = READ_ONLY 0xFFC0 TO 0xFFFF; Reserved for Interrupt Vectors */
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
DEFAULT_RAM /* non-zero page variables */
INTO RAM;

_PRESTART, /* startup code */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
DEFAULT_ROM,
COPY /* copy down information: how to initialize variables */
INTO ROM;

_DATA_ZEROPAGE, /* zero page variables */
MY_ZEROPAGE INTO Z_RAM;
EEPROM_DATA INTO EEPROM;
END


STACKSIZE 0x50



This is my code.

/*--- Default parameter values ---*/

#pragma CONST_SEG EEPROM_DATA

uint8_t Defaults[16] = {24,24,24,24,24,0,10,5,27,30,5,0,0,0,0,0};

#pragma CONST_SEG DEFAULT



Can anybody help me solve this problem?
Labels (1)
0 Kudos
Reply
1 Solution
884 Views
btbhass
Contributor II

Thank you for your help. Adding the lines ENTRIES EEPROM_DATA END to the the end of the linker file solved the problem. It now programs the eeprom with the default values.

 

Message Edited by btbhass on 2010-02-04 09:26 PM

View solution in original post

3 Replies
884 Views
CompilerGuru
NXP Employee
NXP Employee

"#pragma CONST_SEG" applies to constants only, so make the array constant or use #pragma DATA_SEG".

 

#pragma CONST_SEG EEPROM_DATA

const uint8_t Defaults[16] = {24,24,24,24,24,0,10,5,27,30,5,0,0,0,0,0};

#pragma CONST_SEG DEFAULT

 

Also in the prm, READ_WRITE segments are initialized during startup, so it should be used for RAM only. For flash or eeprom use READ_ONLY instead, that means that the content gets stored in there during programming time.

 

 

EEPROM = READ_ONLY 0x1780 TO 0x17FF;

 

 

Daniel

 

 

0 Kudos
Reply
884 Views
ok2ucx
Contributor IV

Your setup is correct, it works here, if copied to one of my test project. It generates following line into S19 file:

 

S11317801818181818000A051B1E05000000000090

 

Since my code does not use EEPROM_DATA, I just needed to assure the linker includes that object into the final binary:

 

ENTRIES  EEPROM_DATAEND

which I don't think would be an issue with your setup. Just in case.

 

Pavel


 

 

 

0 Kudos
Reply
885 Views
btbhass
Contributor II

Thank you for your help. Adding the lines ENTRIES EEPROM_DATA END to the the end of the linker file solved the problem. It now programs the eeprom with the default values.

 

Message Edited by btbhass on 2010-02-04 09:26 PM