2010-08-24 08:23 AM
trying to 'preinit' EEPROM data in C code with Cosmic STM8 compiler
2011-05-17 06:10 AM
Hi Vincent,
I have used variable in data eeprom. In my main.c I have declared it as following: @eeprom char my_var = 10; When I check the eeprom with view memory I can find it. I don't understand why you are using the linker file ? A+, MCU Lüfter2011-05-17 06:10 AM
2011-05-17 06:10 AM
2011-05-17 06:10 AM
Hi ubiali,
I am using eeprom to minimize using ram and flash and since my variable is constant I would like to profit from eeprom availabilty in the device. Otherwise when I should use the epprom ? and why it is implemented in the device ? Regards, MCU Lüfter2011-05-17 06:10 AM
Hi,
I have to set my EEPROM to default values when producing my electronic devices. As already mentioned, it would be very helpful to set the EEPROM all in one, when programming the µC. All known programming tools will supply this feature when the linker will bring out the specific EEPROM datas. Some known compiler/linker tools are able to satisfy it. How can we do this with Cosmic tools? Regards, WoRo2011-05-17 06:10 AM
2011-05-17 06:10 AM
Hi Luca,
I have understood the difference between initializing variable using compiler and using linker but there is still one point. How through the linker which isn't loaded in the MCU will detect after reset that the eeprom has been already initialized ? I hope I am clear. MCU Lüfter2011-05-17 06:10 AM
I use EEprom because data can be change by the user during the running of the program.
Also, I figured that I was doing everithing correctly... except that I needed to directly access the variable in the code to have the linker set the pre init data in the s19 file.
What I was doing, for code portability was using the Readflash function.
First off, I declare the variable in the myeeprom section :
#pragma section @eeprom @near {myeeprom}
#pragma space @eeprom
UBYTE_8 ubyConfigByte;
...
#pragma space
#pragma section {}
I then define a function that read the data that I use in my code ( ADD_CFGBYTE is also a define and need to be at the correct address, it's easy to find since the linker will assigned the adress in the order they appear in the declaration segment)
#define CONFIG_BYTE (FLASH_ReadByte(ADD_CFGBYTE)) // Read CONFIG BYTE
Then in the code, I simply use CONFIG_BYTE to get the value
example : if ((CONFIG_BYTE & BITS_ERR) == ERR_TEMP) ...
By doing that, it seems that the linker will flush the variable declaration because it think it's not used. In order to ''enable'' the linker to pre init the section, I simply had to put it in the code like that :
volatile unsigned char tmpData = CONFIG_BYTE;
even if I have a lot of other variable, only this previous line will permit the linker to set the preinit value for all the data in the section.
If someone has an idea on how not to use the line before.. i'll take it ;)
regards.