Over a million developers have joined DZone.

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.

· IoT Zone

Access the survey results 'State of Industrial Internet Application Development' to learn about latest challenges, trends and opportunities with Industrial IoT, brought to you in partnership with GE Digital.

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:

Heap and Stack Size with Processor Expert

Heap and Stack Size with Processor Expert

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:

Linker File

Linker File


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):

Heap and Stack Size used in Linker Map File

Heap and Stack Size used in Linker Map File

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:

-Xlinker -defsym=__heap_size__=0x600

So I can add the following to adjust the stack and heap size:

-Xlinker -defsym=__heap_size__=0x1000 -Xlinker -defsym=__stack_size__=0x100
Custom Linker Settings

Custom Linker Settings

Checking now the .map shows that the value is taken into account:

Custom heap and stack size

Custom heap and stack size

And that the new size is indeed used:

Linker Heap and Stack Size

Linker Heap and Stack Size


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!

The IoT Zone is brought to you in partnership with GE Digital.  Discover how IoT developers are using Predix to disrupt traditional industrial development models.


Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}