Changing Heap and Stack Size for NXP Kinetis SDK v2.0 GCC Projects
With no Processor Expert available, configuring linking behavior for NXP Kinetis SDK 2.0 requires getting a little deeper into settings and command line options.
Join the DZone community and get the full member experience.Join For Free
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 do we 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 this linker command line option:
This will 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!
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.