cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding TOTAL_HEAP_SIZE calculation by FREERTOS in CubeMX utility.

dean
Associate II
Posted on February 04, 2016 at 00:16

Hi, I am trying to find a description or guidelines for how CubeMX determines the TOTAL_HEAP_SIZE value under the FreeRTOS Config parameters.  I am using the Heap 4 scheme.

It is my observation that no matter what type of controller I specify (L151R8 w/10K RAM vs L151RE w/80K RAM), the same value is used in the FreeRTOS settings (3072).  

I am inferring this mean it is not a calculated value based on the device I'm using at all, but is merely a general starting point that will work even with the R8 chip's limited resources.  However, that leads me to want to know how can I determine, after FreeRTOS has loaded and allocated enough RAM for it's needs, what is left over for the heap space that will be consumed when I spawn threads w/ stacks, and create queues and semaphores.

Is there a way to determine this after say, loading a project with just FreeRTOS running without spawning any tasks w/stacks, queues, semaphores and other such resources?

I'm sure this has been asked already, but I have been so far unable to find any discussion or document that sheds light on this.

Thanks in advance for any help!

#freertos #hal
2 REPLIES 2
Walid FTITI_O
Senior II
Posted on February 04, 2016 at 18:31

Hi lopez.dean,

Thanks for your feedback and contribution.

“Hi, I am trying to find a description or guidelines for how CubeMX determines the TOTAL_HEAP_SIZE value under the FreeRTOS Config parameters. I am using the Heap 4 scheme.�

  • In a coming version of CubeMx,  TOTAL_HEAP_SIZE will automatically calculated to optimize and adjust application.

“

However, that leads me to want to know how can I determine, after FreeRTOS has loaded and allocated enough RAM for it's needs, what is left over for the heap space that will be consumed when I spawn threads w/ stacks, and create queues and semaphores.�

  • The total amount of available heap space is set by configTOTAL_HEAP_SIZE  which is defined in FreeRTOSConfig.h.

  • The xPortGetFreeHeapSize() API function returns the total amount of heap space that remains unallocated (allowing the configTOTAL_HEAP_SIZE setting to be optimized).

  • The total amount of heap space that remains unallocated is also available with xFreeBytesRemaining variable for heap management schemes 2 to 5.

  • configMINIMAL_STACK_SIZE defines the minimum stack size that can be used in words. the idle task stack size takes automatically this value.

  • Optimize stack allocation for each task :

    • uxTaskGetStackHighWaterMark() . This API returns the minimum number of free bytes (ever encountered) in the task stack

    • vApplicationStackOverflowHook(). This API is a stack overflow callback called when a stack overflow is detected (available when activating the define configCHECK_FOR_STACK_OVERFLOW)

  • Adjust heap dimensioning :

    • xPortGetFreeHeapSize(). API that returns the total amount of heap space that remains unallocated. Must be used after created all tasks, message queues, semaphores, mutextes in order to check the heap consumption and eventually re-adjust the application define â€� configTOTAL_HEAP_SIZEâ€�.

    • The total amount of heap space that remains unallocated is also available with xFreeBytesRemaining variable for heap management schemes 2 to 5

You can refer ,also, to the User manual 

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105262.pdf?s_searchtype=keyword

''Developing Applications on STM32Cube with RTOS'' > section FreeRTOS memory managemant.

Hope these information help you in your FreeRTOS based project .

-Hannibal-

dean
Associate II
Posted on February 04, 2016 at 20:54

Thank you Hannibal for replying.  The link you pointed me to for the document is precisely what I have been looking for.  I think this will help me understand this part of the FreeRTOS immensely.

Also, looking forward to seeing the newer version of CubeMX!