Topic : Array of char in EEPROM

Forum : ST7/STM8

Original Post
Post Information Post
April 9, 2009 - 3:08am
Guest

I've got a curly eeprom issue porting from the Cosmic Compiler to Raisonance...

I have an array of char defined within the eeprom to hold the parameter data, it is currenly using the following COSMIC expression

#pragma section @near [eeprom_var] //const {eeprom_var}
u8 eeprom_variable[125];

Within the linker file the section eeprom_var is overlayed on top of the eeprom address space 0x1000. Now unless I miss my guess using the Raisonance compiler I should be able to change the above to

unsigned char eeprom eeprom_variable[125];

Letting the compiler and linker take care of the rest. So far so good. Now I can write parameters to this array setting the relevant bits in EECSR first like so

void E2_ResetEEPROM(void)
{
EEP_Wait_Finished();
EEP_Set_Writing();
eeprom_variable[0] = 'T'; //"TG80" is written in the EEPROM
eeprom_variable[1] = 'G'; //This allows to check later that the EEPROM content is valid.
eeprom_variable[2] = 8;
eeprom_variable[3] = 0x00;
EEP_Start_Write();
EEP_Wait_Finished();
EEP_Set_Reading();
}

However if I try to use an regular expression for the array address then the compliler baulks e.g.

void E2_WriteMem(u8 addr, u8 dt)
{
unsigned char j;

EEP_Wait_Finished();
EEP_Set_Writing();
for(j=0; j<3; j++)
ee_parameter[j] = dt;
EEP_Start_Write();
EEP_Wait_Finished();
EEP_Set_Reading();
}

*** FATAL ERROR C041 IN LINE 94 OF eeprom.c : (null) (00,00,00,00,00,00,90)

So I'm at a loss why the compiler balks. For the interim I've defined the array like so;

at 0x1000 data unsigned char ee_eeprom_variable[125]; /* HACK */

Which effectively does the same thing but I now have to allocate the address of each eeprom variable to prevent over runs etc... Cludgy hack but it works. It would be an advantage to get the linker to do this for me...

So am I missing something or have I barked up the wrong tree ?

Regards

/M.

Replies
Post Information Post
+1
0
-1
April 9, 2009 - 11:05am
Raisonance Support Team

Hi M.,

Thanks for your report, we reproduced the problem in our labs.

It will be fixed in the next release (around mid-June) of the RKit-STM8.

What you can do to workaround the issue is to declare you arrray as a RAM glbal variable, located absolutely at the EEPROM address you want:

Instead of writing:
unsigned char eeprom eeprom_variable[125];

Replace by (as you know EEPROM is at address 0x1000 on ST7DALI):
at 0x1000 unsigned char data eeprom_variable[125];

Let us know if you still have any problems.
Regards,
Bruno