cancel
Showing results for 
Search instead for 
Did you mean: 

Store variable in EEPROM STM32L011

SHDK2000
Associate

I am experiencing an issue when I try to store arrays of data in EEPROM. My intention is to define these arrays in code and have the compiler store them in EEPROM memory space.

I am using an STM32L011E4 device which has 512 bytes of EEPROM at memory location 8080000h. 

I  have adjusted the .ld-file so that the EPROM memory  and a segment called .eep are added.

 

MEMORY
{
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 2K
  FLASH    (rx)    : ORIGIN = 0x8000000,   LENGTH = 16K
  EEPROM    (rx)    : ORIGIN = 0x8080000,   LENGTH = 512
}

.eep :
    {
    	. = ALIGN(4);
        *(.eep)
    } >EEPROM

 

Then I define an array eepromvars in main.c to contain the array data.

 

const __attribute__ ((section(".eep"))) __IO uint16_t eepromvars[] = {
		0x52FD, 
		0x0C15, 
		0x4001, 
		0x4421, 
		0x0ee0, 
		0x2023, 
		0x5400, 
		0x5104, 
		0x0603, 
		0x0582, 
		0x5083
};

 

However, the array is never defined, and the associated memory is never reserved. The program compiles without error, but the variable eepromvars is not pointing to the right location.

Any suggestions on what I am doing wrong?

4 REPLIES 4

Check symbol names and section in the .MAP file. Fix the pattern match in the .LD file if necessary. 

There tools might not write to EEPROM. I typically check and initialize EEPROM content from my app, writing defaults if the memory is empty or corrupt. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

> but the variable eepromvars is not pointing to the right location.

So what is the address of eepromvars in the map file or in debugger? Or the address is OK but there's no data?

SHDK2000
Associate

It does seem, that I actually need to use the variable eepromvars and read/modify the variables in order for the compiler to store the array. Although I could use the knowledge of the location of the variables to address them without using the array directly. Seems like a bug.

Piranha
Chief II

First, your attribute placement is wrong - you are trying to apply it to a type, not to the variable. Second, obviously, that removing an unreferenced variable and code is not a bug, but a compiler feature. Otherwise we would have a bunch of bloat or messy code full of even more preprocessor macros. For exceptions, one should either use the used attribute in C code, or the KEEP() command in linker script.