Newlib heap and stack usage monitoring?

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

Newlib heap and stack usage monitoring?

4,033 Views
keijolänsikunna
Contributor I

When I create a C++ project and do a simple dynamic allocation I can see the heap usage changing. If I do the same in a project with FreeRTOS the view gives me nothing. I did my tests in the main() before FreeRTOS scheduler was started. So FreeRTOS was not doing anything with stack or heap. The project is is set up to use MCUXpresso style stack and heap placement and I have checked that that the required symbols are present (_pvHeapStart, _pvHeapLimit, __end_of_heap).

I know I can't monitor stack usage through the standard MCUXpresso heap and stack monitoring with FreeRTOS.

But why doesn't heap monitoring work? I would like to configure freertos to use heap3.  Then freertos uses newlib malloc/free for allocation and FreeRTOS plugin can't show me heap usage.

When I set breakpoints before and after allocation I can see __end_of_heap changing in the global variable view so things get updated but there is no easy way to monitor heap usage.

3 Replies

3,728 Views
keijolänsikunna
Contributor I

The problem is that FreeRTOS heap & stack view is also disabled when using heap 3 (newlib malloc/free) so there is no way to monitor heap usage!

pastedImage_1.png

FreeRTOS TAD at least displays a message that tells why the view is disabled.

I don't see a point in disabling the standard Heap monitoring with freeRTOS. FreeRTOS memory management does not affect the way newlib allocates memory so even if I use HEAP4 with FreeRTOS newlib is still using standard malloc/free. With monitoring disabled I can't see how much heap newlib and my C++ code is using. I know I can easily override new/delete in cr_cpp_config.cpp but that does not affect newlib or third party libraries written in C.

Is there any way to enable standard heap monitoring when FreeRTOS is used?

0 Kudos

3,728 Views
ErichStyger
Senior Contributor V

Hi Keijo,

I faced the same thing. My solution is to monitor the heap is using the expressions view, with following expressions:


Used:
((unsigned int)__end_of_heap)-((unsigned int)&_pvHeapStart)

Free:
((unsigned int)&_pvHeapLimit)-((unsigned int)__end_of_heap)

Heap size:
(unsigned int)&_pvHeapLimit-(unsigned int)&_pvHeapStart

pastedImage_1.png

I agree that the view should be able to handle FreeRTOS case, but until then the above way works for me.

I hope this helps,

Erich

3,728 Views
lpcxpresso_supp
NXP Employee
NXP Employee

First of all, I confirm that the Heap and Stack Usage view is disabled during RTOS debugging session.

On the other hand, there's a dedicated Heap Usage (FreeRTOS) view that does exactly what you ask. Simply open the view by going to FreeRTOS => Heap Usage. Please note that you'll have to instruct the view with regards to the type of heap you use inside the app. I suggest you open Help => MCUXpresso IDE User Guide and then browse to Heap Usage View under the FreeRTOS debug guide for more details. 

pastedImage_1.png

Greetings,
MCUXpresso IDE Support

0 Kudos