Posted on June 21, 2015 at 09:13 Hi,
I experiment an issue while writing data on flash.
For testing purpose, I made an app that writes several sequence of 'a' to 'z' char to
flash. Each uint_32 data contains 4 chars (a-d, e-h, ...).
I use :
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, eeAddress, data);
I use an array to access the data :
#define EEPROM_SIZE 14 *1024
__attribute__((__section__(''.eeprom''))) uint32_t eepromZone[EEPROM_SIZE / sizeof(uint32_t)] = { value1, value2, value3 };
Everithing works fine, except for the values which are pre-initialized in the declaration.
Reading the pre-initialized values is ok.
Writing on those values gives odd results while reading.
If I initialize value1, value2 and value3 with 0, it works : I read abcdefghijklmno after writing 'abcd' in the first uint32, 'efgh' in the second, 'ijkl' in the third and 'mno' in the fourth.
If I initialize value1=0xFFFFFFFF, value2=0, value3=0, I read 0xFF FF FB FF has the first uint32, 'efgh' in the second, 'ijkl' in the third and 'mno' in the fourth after writing ''abcdefghijklmno''
If I initialize value1=0x00FFFFFF, value2=0, value3=0, I read 0x64 FF FE FF has the first uint32, 0xFFFFFFFF in the second, 'ijkl' in the third and 'mno' in the fourth after writing ''abcdefghijklmno''
If I initialize value1=0xFFFFFFFF, value2=0xFFFFFFFF, value3=0, I read 0xFFFF FB FF has the first uint32, 0xFFFFFFFF in the second, 'ijkl' in the third and 'mno' in the fourth after writing ''abcdefghijklmno''
What could happen ? What should I do to be able to pre-populated the array at flash time and modify the values after ?
If needed, here's the beginning of th ld file :
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x2000BFFF; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 384K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
.eeprom :
{
. = ALIGN(4);
*(.eeprom)
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
Thanks
Julien