This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global Variables are not being initialized

I am switching from using GNU ARM toolchain to using the ARM DS-5 compiler toolchain. The microcontroller I am programming has flash memory starting at 0x08000000, and RAM starting at 0x20000000. My application contains a main() function that just increments a global variable. I set the initial value of the global variable to 0xaa, however it seems that the scatterload function does not copy the initial value to the variable's execution address. When I debug the code the initial value is 0xFFFFFFFF(the default value of the flash memory). I think what is happening is that the scatterload function is accessing where the initial value should have been in flash and copying it to RAM. The problem is that the data was not loaded to the flash. When I print out the map of the elf file, I see the variable in the .data.var section.

Here is what my scatter file looks like:

LOAD_ROM_1 0x08000000 0x100000 {

  FLASH 0x08000000 {
    startup_stm32l476xx.o (RESET, +FIRST)
    * (InRoot$$Sections)
    .ANY (+RO)
  }

  SRAM1 0x20000000 0x18000 {
    .ANY (+RW, +ZI)
  }

}

I am debugging my code using arm gdb from the GNU toolchain. One think that looks odd to me is when I load the program it displays:

(gdb) load
Loading section FLASH, size 0x5a8 lma 0x8000000
Loading section SRAM1, size 0x8 lma 0x20000000
Start address 0x8000188, load size 1456
Transfer rate: 6 KB/sec, 728 bytes/write.
(gdb)

It seems like the SRAM region is being loaded directly to the microcontroller RAM. I intended it to be loaded into flash after the read-only memory and then be copied into RAM by the scatterload function.

There seems to be something I don't understand about the scatterloading process. Anyone else see what I am doing wrong?

Thanks