Initializing the eeprom at program download

Technical Note 32477

Targets:
STM8

Component:
Compiler

Updated:
4/1/2011 2:02 PM

Introduction

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.

Solution

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.

Background

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.

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.