firstly,the global variable are configured to flash address which i defined; i hope the variable copy to RAM address which i defined when workspace start running;
can offer me sample code?
thanks!
Hi,
here is the example:
In linker file I added myROM and myRAM segment:
MEMORY
{
resetvector: org = 0x00000000, len = 0x00000008
init: org = 0x00000020, len = 0x00000FE0
exception_handlers: org = 0x00001000, len = 0x00001000
internal_flash: org = 0x00002000, len = 0x000FD000
myROM: org = 0x000FF000, len = 0x00001000
internal_ram: org = 0x40000000, len = 0x00011000
myRAM: org = 0x40011000, len = 0x00001000
heap : org = 0x40012000, len = 0x00001000
stack : org = 0x40013000, len = 0x00001000
}
Then use this syntax in SECTION:
SECTIONS
{
...
.myRAM BIND(ADDR(myRAM)) LOAD (ADDR(myROM)): {} > myRAM
...
}
And then in *.c file:
#pragma push
#pragma section sdata_type ".myRAM" ".myRAM"
unsigned int my_var1 = 0x11223344;
unsigned int my_var2 = 0xAABBCCDD;
unsigned int my_var3 = 0x55556666;
#pragma pop
The initial values will be copied during startup from myROM to variables in myRAM.
Regards,
Lukas
the two question is not same! In fact,for exampel:
i define a variable in flash as follow:
MEMORY
{
...
my_flash: | org = 0x003FF000, len = 0x00001000 |
...
}
SECTIONS
{
...
.__my_flash LOAD (0x003FF000): {} > my_flash
...
}
In *.c file:
#pragma push
#pragma section all_types ".__my_flash" ".__my_flash "
uint32_t test = 0x1234;
#pragma pop
if it is OK,i want the variable "test" initial values can be copied during startup from my_flash to variables in myRAM.
so how to configure the myRAM in *.c file:?? thanks! can offer me a sample code?
thanks verry verry much!!!!
Hi,
you have to do it exactly in the same way as I showed in my previous post if you want to have variable in RAM that is initialized during startup.
The above can be used only for constant in flash.
Regards,
Lukas
Hi,
I know,thanks.
but i also have a question,the variable is configured in Flash,i want the variable copy to ram address which i defined before MCU run?
Hi,
that's what it does. In the example above, the startup files will copy the initial values stored in myROM to myRAM.
Lukas
thanks! the problem is OK!