AnsweredAssumed Answered

PN7462 with FreeRTOS, heap and stack, MCUXpresso 10.2 Managed linker script

Question asked by Federico Strati on Oct 8, 2018
Latest reply on Oct 22, 2018 by Jorge Antonio Alcala Vazquez

Hello,

 

we got a problem with stack overflow of the FreeRTOS tasks which sounds strange. Moreover it is unclear how the heap of the FreeRTOS and the managed linker script of MCUXpresso IDE 10.2 are related. The platform is the PN7462 chip.

 

The problem: for several reasons we had to refactor our code in libraries, having done that we found a strange problem that appears only the very first time we launch in debug mode our application: the system freezes because of a detected stack overflow of the FreeRTOS tasks (FreeRTOS internal check). The managed linker script settings uses the "LPCXpresso Style" for Heap and Stack placement, with a Stack offset of 1524. The FreeRTOS as shipped by NXP uses the "heap_3.c" algorithm for heap that is simply a wrapper of malloc/free as provided by the redlib. The problem appears only the very first time we run in debug mode the application and was not manifest before the refactoring in libraries of the code base.

 

As FreeRTOS uses its heap to allocate stacks for tasks, I first tried to simply increase the available stack size for our tasks stack: here we encounter a second problem: insufficient heap memory. But when you look at the output of the build the percentage of used SRAM is about 38%. Hence maybe we have space for increasing the heap used by FreeRTOS....

 

Thus, we in turn decided to look at the managed linker script: (Project Properties -> C/C++ build -> Settings -> Managed Linker Script): here for the "Heap and Stack placement" you may choose the "MCUXpresso Style" which gives you the freedom to define the Region, Location and Size of Heap and Stack.

 

We went with the default options of Region, Location and Size for the "MCUXpresso Style" and we now fails with a third problem that malloc miserably fails to allocate memory even the first time you call it for a size of 400 bytes...

 

Hence, my question is: has anyone used successfully the "MCUXpresso Style" in the Managed Linker Script with FreeRTOS heap3, standard malloc/free provided by redlib (for debug config. Redlib - semihost) ?

How to use it, How to configure the heap of FreeRTOS ?

...Whatever we try with this option "MCUXpresso Style", malloc is unable even to allocate the first 400 bytes...

 

If you need more details, please ask and we will provide them.

 

Thanks in advance

Outcomes