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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

2,204件の閲覧回数
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

ラベル(1)
タグ(2)
0 件の賞賛
返信
3 返答(返信)

1,904件の閲覧回数
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 件の賞賛
返信

1,907件の閲覧回数
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 件の賞賛
返信

1,907件の閲覧回数
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 件の賞賛
返信