Static and dynamic allocation of FreeRTOS primitives
Details on creating tasks were covered in Chapter 7, Running the FreeRTOS Scheduler. For the API xTaskCreate(), storage for the task’s stack and TCB are taken from the FreeRTOS heap. For xTaskCreateStatic(), the caller provides pointers to the storage for the stack and TCB, respectively, and the stack’s length is provided.
Many FreeRTOS APIs have versions for both static and dynamic allocation of stack space, such as xTaskCreateStatic() and xQueueCreate(). All FreeRTOS API functions with *CreateStatic in their names take additional arguments for specifying the pre-allocated memory. The memory passed to *CreateStatic variants will typically be statically allocated buffers, which are present for the entire program’s lifetime.
In this section, we’ll look at static and dynamic allocation of the stack used by FreeRTOS primitives. We’ll focus on the differences in where the memory is coming from...