0
0
FreeRTOSprogramming~20 mins

Stack size allocation in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stack Size Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS stack size allocation code?

Consider the following FreeRTOS task creation snippet. What is the stack size allocated to the task in bytes?

FreeRTOS
xTaskCreate(
  vTaskCode,       // Task function
  "Task1",        // Task name
  100,             // Stack size
  NULL,            // Parameters
  1,               // Priority
  NULL             // Task handle
);
A400 bytes
B100 bytes
C100 words (400 bytes on 32-bit system)
D100 bits
Attempts:
2 left
💡 Hint

Remember that FreeRTOS stack size is specified in words, not bytes.

🧠 Conceptual
intermediate
1:30remaining
Why is stack size specified in words in FreeRTOS?

FreeRTOS stack size is given in words, not bytes. Why is this design choice made?

ABecause the stack grows in word-sized units and it is more efficient to count words
BBecause bytes are not supported in embedded systems
CBecause FreeRTOS only supports 16-bit processors
DBecause specifying bytes would cause stack overflow errors
Attempts:
2 left
💡 Hint

Think about how the CPU accesses memory and stack alignment.

🔧 Debug
advanced
2:00remaining
Identify the error in this FreeRTOS stack size allocation

What is wrong with this task creation code regarding stack size?

FreeRTOS
xTaskCreate(
  vTaskCode,
  "Task2",
  512,  // Stack size
  NULL,
  2,
  NULL
);
AStack size is too large and causes memory overflow
BStack size is specified in bytes but FreeRTOS expects words
CStack size is specified in words but the value is too small
DNo error, this is a valid stack size allocation
Attempts:
2 left
💡 Hint

Consider the meaning of the stack size parameter and typical stack sizes.

Predict Output
advanced
1:30remaining
What happens if stack size is set too small in FreeRTOS?

Given a task with stack size set to 10 words, what is the most likely outcome when the task runs?

AStack overflow occurs causing unpredictable behavior or crash
BThe task runs normally without issues
CThe task stack automatically expands to fit needs
DThe task is rejected by the scheduler at creation
Attempts:
2 left
💡 Hint

Think about what happens if the stack is too small for task needs.

🚀 Application
expert
3:00remaining
Calculate total RAM used by three FreeRTOS tasks with different stack sizes

You create three tasks with stack sizes 50, 100, and 150 words respectively on a 32-bit system. How much total RAM in bytes is allocated for their stacks?

A12000 bytes
B1200 bytes
C120 bytes
D1200 words
Attempts:
2 left
💡 Hint

Remember to convert words to bytes and sum all stacks.