Init Value EEprom

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

Init Value EEprom

8,044 Views
CCandido
Contributor V
Hi,
to initiate the EEPROM with some values,  I use the DP256.
 
Tab_EEp = {00,08,...............}
 
 
 
 
 
 
 
Edited by Carlos Candido from Brasil.
 
 
 
Labels (1)
0 Kudos
8 Replies

723 Views
Technoman64
Contributor III
First thing you need to define the EEPROM segment in the prm file so the linker knows the location of the EEPROM in the memory map
 
/* Add this in the prm file above the RAM section */
EEPROM = READ_ONLY 0x0C00 TO 0x0FFF;
 
/* Add this to the prm file after the DEFAULT_RAM section *\
EEPROMDATA INTO EEPROM;
 
Now on to declaring the array in c code
 
/* We first need to tell the compiler which segment we want to use */
#pragma CONST_SEG EEPROMDATA
 
/* Now declare an array in the EEPROM segment with initialized values */
const int MyIntegerArray[5] = {1,2,3,4,5};
 
/* Return to default constant segment */
#pragma CONST_SEG DEFAULT
 
You can now declare this as extern const data in an include file so the array can be used by other code.
 

Message Edited by Technoman64 on 05-18-200608:43 AM

0 Kudos

723 Views
CCandido
Contributor V

Not, programing........

prm

 EEPROM = READ_ONLY 0x0400 TO 0x0FFF;

 DEFAULT_RAM                  INTO  RAM;
  EEPROMDATA                 INTO   EEPROM;

--------------

in my code main.

#pragma CONST_SEG EEPROMDATA
 const int MyIntegerArray[6] = {0,1,2,3,4,5};
#pragma CONST_SEG DEFAULT

-------------------------

progammer Staus:

Block Module Name      Address Range   Status
  0  EEPROM             400 -   FFF   Enabled/Blank/Unprotected - Selected <<<<<?
  1  FLASH_4000        4000 -  7FFF   Enabled/Blank/Unprotected - Selected
  2  FLASH_C000        C000 -  FFFF   Enabled/Programmed/Unprotected - Selected
  3  FLASH_3         308000 -33BFFF   Enabled/Blank/Unprotected - Selected
  4  FLASH_2         348000 -37BFFF   Enabled/Blank/Unprotected - Selected
  5  FLASH_1         388000 -3BBFFF   Enabled/Blank/Unprotected - Selected
  6  FLASH_0         3C8000 -3FBFFF   Enabled/Programmed/Unprotected - Selected

congratulation........t+

 

 

 

0 Kudos

723 Views
Technoman64
Contributor III
You must referance the Array some where in your code or the compiler will optimize the array out because it is never used.
 
Try in the main() function,
 
int Test;
 
Test = MyIntArray[0];
 
 
 
 
0 Kudos

723 Views
imajeff
Contributor III
I don't think global vars should be optimized out.
I'm wondering if the utility can handle programming both EEPROM and Flash at the same time. I used GCC to test this global:

const int __attribute__((section(".eeprom"))) MyIntegerArray[6] = {0,1,2,3,4,5};

It looks good in the ELF output from GCC, but the S19 can't hold both memory regions because it outputs linear Flash addresses (i.e. 0xc0000 is start of PPAGE 0x30). Thing is, it should be able to work if the S19 is generated in banked format (i.e. 0x000400 eeprom and 0x308000 flash) like it probably does in CW.
0 Kudos

723 Views
Technoman64
Contributor III

I have done this more than once with Codewarrior and a HCS12DJ256. The EEPROM is erased and programmed with no issues on my system.

Try moving the Test int out of the main() function and into global address. Also look at the Map file to determine if the compiler optimized the array out.

0 Kudos

723 Views
Lundin
Senior Contributor IV
A better way to do this in Codewarrior is at the bottom of the prm file:

ENTRIES

myVariable

END


And then somewhere in the program

const int myVariable = 123;

Though you can only do this with global const variables, I don't think it works with static since they are limited to the file they are placed in.


I'm not sure if I would trust
int Test;
Test = MyIntArray[0];

You never know what crazy things the optimizer might do with that. Maybe it will detect that Test is never used and remove it from the program. I suppose you could do something like

Type includeVar(Type t)
{
return t;
}

main()
{
(void) includeVar(myVariable);
}


But I think it is better to include it in ENTRIES as I mentioned first.
0 Kudos

723 Views
imajeff
Contributor III
wouldn't it also stick if marked static or something like that?
0 Kudos

723 Views
CCandido
Contributor V
 test in debug_only OK,
$0400 = 00 01,00,02,..........00,05 ok,
 
programing........
 
Block Module Name      Address Range   Status
  0  EEPROM             400 -   FFF   Enabled/Blank/Unprotected - Selected !!(not)

  1  FLASH_4000        4000 -  7FFF   Enabled/Blank/Unprotected - Selected
  2  FLASH_C000        C000 -  FFFF   Enabled/Programmed/Unprotected - Selected
  3  FLASH_3         308000 -33BFFF   Enabled/Blank/Unprotected - Selected
  4  FLASH_2         348000 -37BFFF   Enabled/Blank/Unprotected - Selected
  5  FLASH_1         388000 -3BBFFF   Enabled/Blank/Unprotected - Selected
  6  FLASH_0         3C8000 -3FBFFF   Enabled/Programmed/Unprotected - Selected
 
not, programmer   EEprom !!
status eeprom = Blank
0 Kudos