Initializing the eeprom at program download

Technical Note 32477






2015-11-06 13:05


This Technical Note discusses IAR Embedded Workbench for STM8 and EEPROM initialization. An assignment like:

__eeprom char array[] = {0X1C,0X1F,0X9F,0XFF};

.. generates the compiler error message

Error[Ta004]: __eeprom variable must be __no_init

.. which means that eeprom variables can't be assigned a value at compile time.


Declare the variable as a static char. Place it in eeprom section "my_eeprom".

char array[]@ "my_eeprom" = {0X1C,0X1F,0X9F,0XFF};

and update the linker configuration file for example:

place in Eeprom             { rw section .eeprom.noinit,
rw section my_eeprom };

Note that

The 'array' variable does not get the __eeprom memory attribute. This means reading from 'array' will be ok, but the compiler will generate ordinary __near memory writes for any assignments (usually with no effect at all). You have to call your own routines for writing to the eeprom, and it is up to you to ensure that there are no ordinary C assignments.


The __eeprom variables must be __no_init.
The reason for this is that initialized __eeprom variables would require different initialization routines from normal variables.
We presumed that the EEPROM memory would be used for persistent storage, so there would be no need for automatic initialization.
It is up to the application (or system) to initialize the EEPROM memory.
Nevertheless, support for initialized __eeprom variables is planned in a future release of IAR Embedded Workbench for STM8.

All product names are trademarks or registered trademarks of their respective owners.

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.