Skip to content

Overview

Part 4 Memory Management

Memory Allocation

General

Volatile memory (e.g. RAM) in most micro-controller systems is divided up into 3 sections:

  1. Stack - Used for dynamic memory allocation and function call management.
  2. Heap - Dynamic memory allocation during runtime by programmer.
  3. Static - Used for global and static variables.

alt text

freeRTOS

when I run the xTaskCreate() create dynamic memory

  • TCB (Task Control Block) - Key information about task such as state, priority, stack pointer, and other context information.

  • Stack - store local variables, function parameters, and return addresses.

alt text

For more details See the FreeRTOS Memory Management Guide

vanilla FreeRTOS

To enable static task memory allocation(only machine critical application), set the following configuration option in FreeRTOSConfig.h:

#define configSUPPORT_STATIC_ALLOCATION    1

Heap Allocation

Why Heap Allocation?

  • Flexibility: Dynamic memory allocation allows tasks to request memory as needed during runtime, which is particularly useful in applications where memory requirements can vary significantly.

For more details FreeRTOS Heap Management Schemes

heap_4.c - used in most applications.

Vanilla FreeRTOS

ESP Vanilla freeRTOS Memory Management