Static allocation means reserving memory at compile time. The memory for tasks, queues, or other objects is fixed and does not change during program execution.
Click to reveal answer
beginner
What is dynamic allocation in FreeRTOS?
Dynamic allocation means reserving memory at runtime using functions like pvPortMalloc. Memory can be allocated and freed as the program runs.
Click to reveal answer
intermediate
What does the configSUPPORT_STATIC_ALLOCATION setting control?
It controls whether FreeRTOS allows creating tasks and other objects using static allocation. If set to 1, static allocation is supported; if 0, only dynamic allocation is allowed.
Click to reveal answer
intermediate
Name one advantage of static allocation over dynamic allocation in FreeRTOS.
Static allocation avoids fragmentation and runtime memory failures because memory is fixed and known at compile time.
Click to reveal answer
intermediate
Why might dynamic allocation be risky in embedded systems?
Dynamic allocation can cause memory fragmentation and allocation failures during runtime, which may lead to system instability or crashes.
Click to reveal answer
What happens if configSUPPORT_STATIC_ALLOCATION is set to 0 in FreeRTOS?
ABoth static and dynamic allocation are allowed.
BOnly static allocation is allowed.
COnly dynamic allocation is allowed for tasks and objects.
DMemory allocation is disabled.
✗ Incorrect
Setting configSUPPORT_STATIC_ALLOCATION to 0 disables static allocation, so only dynamic allocation can be used.
Which of the following is a benefit of static allocation?
AMemory size can change during execution.
BMemory is allocated and freed dynamically.
CRequires more CPU time to allocate memory.
DAvoids runtime memory fragmentation.
✗ Incorrect
Static allocation fixes memory size at compile time, avoiding fragmentation during runtime.
In FreeRTOS, which function is commonly used for dynamic memory allocation?
ApvPortMalloc
BmallocStatic
CxTaskCreateStatic
DvPortFreeStatic
✗ Incorrect
pvPortMalloc is the FreeRTOS wrapper for dynamic memory allocation.
What is a key difference between xTaskCreate and xTaskCreateStatic?
A. Function name is incorrect; should be xTaskCreate.
B. Task buffer pointer is NULL, causing invalid task control block.
C. Stack buffer pointer is NULL, causing invalid stack memory.
D. Task priority is invalid (should be zero).
Solution
Step 1: Check parameters passed to xTaskCreateStatic
The stack buffer pointer is NULL, which means no memory is provided for the task's stack.
Step 2: Understand consequences of NULL stack buffer
Without a valid stack buffer, the task cannot run properly and will cause errors.
Final Answer:
Stack buffer pointer is NULL, causing invalid stack memory. -> Option C
Quick Check:
Stack buffer must not be NULL [OK]
Hint: Stack buffer pointer must be valid, not NULL [OK]
Common Mistakes:
Passing NULL for stack buffer
Confusing task buffer with stack buffer
Incorrect function name usage
5. You want to create a FreeRTOS task that must never fail due to memory fragmentation or heap exhaustion. Which approach is best and why?
hard
A. Use static allocation with user-provided buffers for predictability.
B. Mix static and dynamic allocation to balance memory usage.
C. Use dynamic allocation with a large heap to avoid failures.
D. Disable task deletion to prevent memory leaks.
Solution
Step 1: Understand memory failure causes in FreeRTOS
Dynamic allocation can fail due to heap fragmentation or exhaustion, causing task creation failure.
Step 2: Evaluate static allocation benefits
Static allocation uses fixed buffers provided by the user, ensuring memory is reserved and predictable, preventing allocation failures.
Step 3: Compare other options
Using dynamic allocation with a large heap still risks fragmentation failures; mixing allocation methods adds unnecessary complexity; disabling task deletion is unrelated to allocation issues.
Final Answer:
Use static allocation with user-provided buffers for predictability. -> Option A