0
0
FreeRTOSprogramming~30 mins

Stack size allocation in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Stack Size Allocation in FreeRTOS
📖 Scenario: You are working on a small embedded system using FreeRTOS. You need to create tasks with proper stack sizes to ensure they run correctly without wasting memory.
🎯 Goal: Learn how to allocate stack sizes for FreeRTOS tasks by creating tasks with specific stack sizes and then printing their stack size configuration.
📋 What You'll Learn
Create a FreeRTOS task with a specific stack size
Define a stack size constant
Use the stack size constant when creating the task
Print the stack size used for the task
💡 Why This Matters
🌍 Real World
Embedded systems often have limited memory. Allocating the right stack size for tasks prevents crashes and saves memory.
💼 Career
Understanding stack size allocation is essential for embedded software developers working with real-time operating systems like FreeRTOS.
Progress0 / 4 steps
1
Define a stack size constant
Create a constant called STACK_SIZE and set it to 256 to represent the stack size in words.
FreeRTOS
Need a hint?

Use #define STACK_SIZE 256 to create the constant.

2
Create a FreeRTOS task with the stack size
Create a task called vTaskFunction with the stack size STACK_SIZE using xTaskCreate. Use NULL for parameters you don't need, and priority 1.
FreeRTOS
Need a hint?

Use xTaskCreate(vTaskFunction, "Task1", STACK_SIZE, NULL, 1, NULL); inside main.

3
Add a variable to hold the stack size
Create a variable called taskStackSize and set it to STACK_SIZE to store the stack size value.
FreeRTOS
Need a hint?

Declare int taskStackSize = STACK_SIZE; inside main.

4
Print the stack size used for the task
Use printf to display the text "Task stack size: " followed by the value of taskStackSize.
FreeRTOS
Need a hint?

Use printf("Task stack size: %d\n", taskStackSize); to print the value.