I'm playing around with scatter-loading in Keil 5.25 with armcc compiler. Now I have a dummy project that allocates stack and heap in 'default' startup assembly file:
Stack_Size EQU 0x00000400 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp ; <h> Heap Configuration ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; </h> Heap_Size EQU 0x00000200 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit PRESERVE8 THUMB
I'm trying to use scatter file to place stack and heap at some specific memory regions. I do it like this:
LR_IROM1 0x8000000 0x4000 { ; load region size_region ER_IROM1 0x8000000 0x4000 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) } ARM_LIB_STACK 0x20000000 { *(STACK) } ARM_LIB_HEAP 0x20004000 { *(HEAP) } RW_IRAM1 0x20006000 { *(+RW +ZI) } }
And in main I call malloc to allocate some memory.
When I build the project, linker gives me this warning: "./dummy.sct(34): warning: L6329W: Pattern *(HEAP) only matches removed unused sections."
But I use malloc, so I should be using heap memory. In debugger I can see that memory that I allocated by malloc was already taken by some global variable, which I presume means that heap region is indeed removed by the linker.
But why is it happening? What am I doing wrong?
I was able to force linker not to remove heap by --keep option but I still want to know what is wrong.
Robert McNamara that's interesting because right now I define stack size in the assembly file and ARM_LIB_STACK is created without me specifying it's size in the scatter file.
Although www.keil.com/.../ARMLINK_pge1362065977713.htm says that "Only one ARM_LIB_STACK or ARM_LIB_HEAP region can be specified, and you must allocate a size".
So this should not work at all and only works by accident?
I also forgot to make this regions EMTPY, maybe that's the case why it works at all. Although that link from above doesn't explicitly say that they must be EMPTY...
Sorry. For me, I like to put all the stack and heap details in a single file (the scatter file). If you want part of it in the startup file and part in the scatter file that does seem to also work.
It's just that I already have a lot of startup files for different processors and I don't like the idea of rewriting them all.
Nevermind. What if I leave my scatter file almost as it is now but won't call regions for stack and heap with this special names?
Yes, apparently if I name my linker sections differently (i.e. won't use special Keil names) - it will place stack and heap as I need and no warning will be generated.