Follow+Star Public Account Number, don’t miss wonderful content
Author | strongerHuang
WeChat Public Account | Embedded Column
xTaskCreate(LED_Task, "LED_Task", 128, NULL, 6, NULL);
If this question is to be elaborated, it involves many knowledge points, below I will pick a few important related content to answer this question.
Static and Dynamic Memory Allocation
Memory allocation is generally divided into: static and dynamic allocation.
1.Static Memory Allocation
In simple terms, it is 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 generally several situations, such as:
Startup allocation stack:
Stack_Size EQU 0x400
Defining a static variable, this is the easiest 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 (Stack)
The memory of FreeRTOS is allocated in the FreeRTOSConfig.h file as a global array, 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 the 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 question at the beginning?
The answer is: FreeRTOS does not dynamically allocate memory, it only simulates the way of dynamic allocation, and the actual memory is statically allocated.
Click “Read the original text” to see more shares.