Author | strongerHuang
xTaskCreate(LED_Task, "LED_Task", 128, NULL, 6, NULL);
This question involves many knowledge points, so let’s pick a few important related contents to answer this question.
Static and Dynamic Memory Allocation
Memory allocation generally divides into: static and dynamic allocation.
1. Static Memory Allocation
In simple terms, it is the memory allocated at compile time. You can understand it as when the chip is powered on, a specified area (address) of memory is occupied.
There are several situations, for example:
Startup allocation stack:
Stack_Size EQU 0x400
Defining a static variable, this is the easiest example to understand:
static int a;
Defining a global variable/array, etc:
int char;
2. Dynamic Memory Allocation
void UART_Send(char *p){ char buf[10]; //......}
Sorting Out FreeRTOS Memory Allocation
1. Global Array (Heap)
The memory of FreeRTOS is allocated in the FreeRTOSConfig.h file as a global array, and the size of this memory is allocated by the user according to the situation, for example:
#define configTOTAL_HEAP_SIZE ((size_t)(10 * 1024))
2. Creating Tasks
FreeRTOS creates tasks and allocates stack size, for example: 128 “words”
xTaskCreate(LED_Task, "LED_Task", 128, NULL, 6, NULL);
Reminder:Here, “word” is a unit, for example: uint32_t
3. Deleting Tasks
FreeRTOS deletes tasks and calls the “vPortFree()” function to release the corresponding memory.
Is FreeRTOS dynamically allocated memory?
Having seen this, can you answer the initial question?
The answer is: FreeRTOS is not dynamically allocated memory, it just simulates the way of dynamic allocation, and the actual memory is statically allocated.