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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,793 Views
fstrati
Contributor I

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

Labels (1)
Tags (2)
0 Kudos
3 Replies

1,493 Views
jayesh_joshi
Contributor IV

Hi,

I am facing the same issue my mcuexpresso version is v11.1.1. 

heap configuration is as per below for "MCUXpresso Style" in the Managed Linker Script.

/* Reserve and place Heap within memory map */
_HeapSize = 0x2e8;
.heap : ALIGN(4)
{
_pvHeapStart = .;
. += _HeapSize;
. = ALIGN(4);
_pvHeapLimit = .;
} > SRAM

I have also tried with default "LPCXpresso Style" in the Managed Linker Script. but I am getting "vApplicationMallocFailedHook" every time.

0 Kudos

1,496 Views
fstrati
Contributor I

It seems there is a bug in the MCUXpresso IDE 10.2 relating to the the "MCUXpresso Style" in the Managed Linker Script for the "Heap and Stack placement": the generated linker script should be modified manually to change:

_pvHeapStart = .;
[...]
_vStackTop = . + _StackSize;

in:

PROVIDE( _pvHeapStart = . );
[...]
PROVIDE( _vStackTop = . + _StackSize );

this way malloc sees correctly the exported symbols and works ok.

In fact, with the "LPCXpresso Style" in the linker script we have:

PROVIDE(_pvHeapStart = DEFINED(__user_heap_base) ? __user_heap_base : .);
PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_SRAM - 1528);

Support should raise an internal issue about this bug.

0 Kudos

1,496 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Federico Strati

Thanks for sharing this, your help is greatly appreciated. I can confirm that this issue happened when you use heap3 from FreeRtos and the linker with MCUXpresso Style

Best regards

Jorge Alcala

0 Kudos