Calculate the remaining heap space of FreeRTOS

FreeRTOS takes up memory

Macro definition in Freeconfig.h

宏  #define configTOTAL_HEAP_SIZE        ( ( size_t ) ( 30 * 1024 ) ) 

The memory space defined by this macro belongs to the ZI-data range (ZI-data refers to uninitialized global variables and global variables with an initial value of 0)

FreeRTOS comes with the application memory API pvPortMalloc to apply from the memory defined by configTOTAL_HEAP_SIZE;

The malloc function in the file <stdio.h> applies for memory directly from the SRAM heap, which is equivalent to global variables

FreeRTOS creates tasks, message queues and FreeRTOS API functions all apply for memory from configTOTAL_HEAP_SIZE

Global variable
Initialized to a non-zero value, not quoted Occupy RW-Data segment
Initialize to 0 or not initialize, reference Occupy ZI-Data segment
Not initialized, not referenced Does not take up any space

FreeRTOS heap space

Insert picture description here

Tasks, queues, and space allocated by users using pvPortMalloc() are all divided from the heap heap

API function to calculate memory space

xPortGetFreeHeapSize()  

Get the size of free memory in the call heap, using Byte as the unit (heap_3 scheme cannot use this API) to
find the minimum free storage space of FreeRTOS heap space:

xPortGetMinimumEverFreeHeapSize()  

Return the minimum number of bytes of unallocated storage space that has ever existed after the FreeRTOS application starts running. This API is only an API that effectively calculates the size of the task stack space when using heap_4 and heap_5
:

Prerequisite : Configure INCLUDE_uxTaskGetStackHighWaterMark to 1 in FreertosConfig.h

uxTaskGetStackHighWaterMark()  

This function returns the minimum task stack space size of the task in which it is started, in words (calculate the number of bytes and then × 4)
. Call this API in a task:

printf(" the min free stack size is %d \r\n",(int32_t)uxTaskGetStackHighWaterMark(NULL));  

Function function : print out the minimum remaining stack space size of the task since it is started

Guess you like

Origin blog.csdn.net/weixin_44333597/article/details/108028963