Consider the following FreeRTOS task creation snippet. What is the stack size allocated to the task in bytes?
xTaskCreate( vTaskCode, // Task function "Task1", // Task name 100, // Stack size NULL, // Parameters 1, // Priority NULL // Task handle );
Remember that FreeRTOS stack size is specified in words, not bytes.
FreeRTOS stack size parameter is the number of words, not bytes. On a 32-bit system, one word is 4 bytes, so 100 words equal 400 bytes.
FreeRTOS stack size is given in words, not bytes. Why is this design choice made?
Think about how the CPU accesses memory and stack alignment.
Stack memory is accessed in word-sized chunks (e.g., 4 bytes on 32-bit systems). Counting stack size in words matches CPU architecture and is efficient.
What is wrong with this task creation code regarding stack size?
xTaskCreate( vTaskCode, "Task2", 512, // Stack size NULL, 2, NULL );
Consider the meaning of the stack size parameter and typical stack sizes.
The stack size parameter is in words. 512 words is a valid stack size (2048 bytes on 32-bit system). This is not an error.
Given a task with stack size set to 10 words, what is the most likely outcome when the task runs?
Think about what happens if the stack is too small for task needs.
If the stack size is too small, the task will overflow its stack, causing memory corruption and unpredictable behavior or system crash.
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?
Remember to convert words to bytes and sum all stacks.
Total words = 50 + 100 + 150 = 300 words. On 32-bit system, 1 word = 4 bytes. Total bytes = 300 * 4 = 1200 bytes.