With Processor Expert projects it is very easy to change the heap and stack size: There is a setting for this in the Cpu component settings, under the ‘Build options’ tab:
As there is no Processor Expert in the NXP Kinetis SDK V2.0 (see “First NXP Kinetis SDK Release: SDK V2.0 with Online On-Demand Package Builder“), how to do the same in a SDK V2.0 project?
GNU Linker File
The Kinetis SDK approach is to have some optional settings in the source files which are used in the linker (.ld) file. Open the linker file, and there should be something like this:
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x100; STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
So if in the project settings there is a symbol __heap_size__ or __stack_size__ defined, then it will use these values. If not, it uses the default value (0x100 or 0x400 in above example).
Linker Map File
If I want to check what is actually used, I can check the linker map file (.map, usually located in the output (debug) folder):
In the above example I can see that 0x100 for the heap and 0x400 for the stack is used.
Defining Linker Symbols
So how to define the linker symbols?
I can use the following linker option (see “Overwriting Symbols in the GNU Linker File“) for example to specify the heap size:
So I can add the following to adjust the stack and heap size:
-Xlinker -defsym=__heap_size__=0x1000 -Xlinker -defsym=__stack_size__=0x100
Checking now the .map shows that the value is taken into account:
And that the new size is indeed used:
With the linker files used in the NXP Kinetis SDK V2.0 project, I can use the
Linker command line option to overwrite symbols in the linker script, for example to configure the heap and stack size. That way I can keep the same linker file for multiple projects, and the command line to the linker is used for custom settings.
Happy stacking and heaping 🙂