I am working on Cortex M0. CCS under usage is 5.3.0.00090 and library is rtsv6M0_T_le_eabi.lib.
Linker command file as below:
------------------------------------------------------------
#define APP_BASE 0x00000000
#define RAM_BASE 0x20000000
/* System memory map */
MEMORY
{
/* Application stored in and executes from internal flash */
OTP (RX) : origin = APP_BASE, length = 0x00002000
/* Application uses internal RAM for data */
SRAM (RWX) : origin = 0x20000000, length = 0x00000400
/* Application can be stored in DRAM and executes from DRAM */
DRAM (RX) : origin = 0x21000000, length = 0x00002000
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > APP_BASE
.text : > OTP
.const : > OTP
.cinit : > OTP
.pinit : > OTP
.init_array : > OTP
.vtable : > RAM_BASE
.data : > SRAM
.bss : > SRAM
.sysmem : > SRAM
.stack : > SRAM
}
__STACK_TOP = 0x20000000;
------------------------------------------------------------
Stack size is 256bytes. Initially the stack was getting allocated to SRAM memory location @ 0x20000000 to 0x200000FF.
However the linker seems to be re-ordering the sections in the RAM (for example the .bss, .stack sections especially when the .bss gets large). This is causing issues.
Re-ordering contains are as below:
.bss 0 20000000 00000104 UNINITIALIZED
20000000 00000074 ee.obj (.bss)
20000074 00000070 app.obj (.bss)
200000e4 0000000c fir.obj (.bss)
200000f0 00000006 adc.obj (.bss)
200000f6 00000006 combuf.obj (.bss)
200000fc 00000006 uart.obj (.bss)
20000102 00000002 dac.obj (.bss)
.stack 0 20000104 00000100 UNINITIALIZED
20000104 00000100 --HOLE--
To resolve this problem, we updated linker command file to force .bss to a higher location.
#define APP_BASE 0x00000000
#define RAM_BASE 0x20000000
/* System memory map */
MEMORY
{
/* Application stored in and executes from internal flash */
OTP (RX) : origin = APP_BASE, length = 0x00002000
/* Application uses internal RAM for data */
SRAM (RWX) : origin = 0x20000000, length = 0x00000400
/*STACK_RAM (RWX) : origin = 0x20000000, length = 0x100*/
/* Application can be stored in DRAM and executes from DRAM */
DRAM (RX) : origin = 0x21000000, length = 0x00002000
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > APP_BASE
.text : > OTP
.const : > OTP
.cinit : > OTP
.pinit : > OTP
.init_array : > OTP
.vtable : > RAM_BASE
.data : > SRAM
.bss : > SRAM (HIGH)
.sysmem : > SRAM
.stack : > SRAM
}
__STACK_TOP = 0x20000000;
---------------------------------------------------------------------------
Is it a correct way? or please let me know if there is a better way to do this.
Thanks,
Tushar