What is the purpose of the xTaskCreate() function in FreeRTOS?
The xTaskCreate() function is used to create a new task and add it to the list of tasks that are ready to run in FreeRTOS.
Click to reveal answer
beginner
What are the main parameters of xTaskCreate()?
The main parameters are: the task function pointer, a name for the task, stack size in words, a pointer to parameters passed to the task, task priority, and a handle to the created task.
Click to reveal answer
beginner
What does the return value of xTaskCreate() indicate?
It returns pdPASS if the task was created successfully, or errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY if the task creation failed (usually due to insufficient memory).
Click to reveal answer
intermediate
Why is the stack size parameter important in xTaskCreate()?
The stack size defines how much memory the task has for its local variables and function calls. Too small a stack can cause crashes, too large wastes memory.
Click to reveal answer
intermediate
Can xTaskCreate() be called from an interrupt service routine (ISR)?
No, xTaskCreate() must be called from a task context, not from an ISR. For creating tasks from ISRs, other mechanisms are needed.
Click to reveal answer
What does xTaskCreate() return when a task is created successfully?
ApdPASS
BpdFAIL
CNULL
D0
✗ Incorrect
xTaskCreate() returns pdPASS to indicate success.
Which parameter of xTaskCreate() specifies the task's priority?
ATask function pointer
BTask priority
CStack size
DTask name
✗ Incorrect
The task priority parameter sets the priority level of the created task.
Is it safe to call xTaskCreate() inside an interrupt service routine (ISR)?
AOnly if interrupts are disabled
BYes, always
CNo, never
DOnly for low priority tasks
✗ Incorrect
xTaskCreate() must be called from a task context, not from an ISR.
What happens if the stack size given to xTaskCreate() is too small?
ATask runs faster
BTask priority increases
CTask uses less CPU
DTask may crash or behave unpredictably
✗ Incorrect
A too small stack can cause crashes or unpredictable behavior due to stack overflow.
Which of these is NOT a parameter of xTaskCreate()?
ATask timeout
BTask name
CTask function pointer
DTask handle pointer
✗ Incorrect
xTaskCreate() does not take a task timeout parameter.
Explain how to use xTaskCreate() to create a new task in FreeRTOS.
Think about what each parameter means and what the function returns.
You got /7 concepts.
Describe why choosing the correct stack size is important when creating a task with xTaskCreate().
Consider what happens if the stack is too small or too big.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of the xTaskCreate() function in FreeRTOS?
easy
A. To start a new task that runs concurrently with others
B. To delete an existing task
C. To pause the scheduler temporarily
D. To allocate memory for variables
Solution
Step 1: Understand the role of xTaskCreate()
This function is designed to create and start a new task in FreeRTOS, allowing multitasking.
Step 2: Compare with other options
Deleting tasks, pausing the scheduler, or allocating memory are handled by different functions, not xTaskCreate().
Final Answer:
To start a new task that runs concurrently with others -> Option A
Quick Check:
Task creation = start new task [OK]
Hint: xTaskCreate always starts a new task [OK]
Common Mistakes:
Confusing task creation with task deletion
Thinking it pauses the scheduler
Assuming it allocates general memory
2. Which of the following is the correct syntax for xTaskCreate() in FreeRTOS?
easy
A. xTaskCreate(TaskFunction, "Name", StackSize, Parameters, Priority);
B. xTaskCreate(TaskFunction, Name, StackSize, Parameters, Priority, TaskHandle);
C. xTaskCreate(TaskFunction, "Name", StackSize, Parameters, Priority, TaskHandle);
D. xTaskCreate(TaskFunction, "Name", StackSize, Parameters, Priority, &TaskHandle);
Solution
Step 1: Recall the correct parameter list
The correct syntax requires the task function, a string name in quotes, stack size, parameters, priority, and a pointer to the task handle.
Step 2: Check each option carefully
xTaskCreate(TaskFunction, "Name", StackSize, Parameters, Priority, &TaskHandle); matches the correct syntax exactly, including quotes around the name and the address-of operator for the task handle.
Final Answer:
xTaskCreate(TaskFunction, "Name", StackSize, Parameters, Priority, &TaskHandle); -> Option D
Quick Check:
Correct syntax includes &TaskHandle [OK]
Hint: Task name must be a string and handle passed by address [OK]
The last parameter must be a pointer to the task handle variable, so it requires the address operator &.
Step 2: Verify other parameters
The task name is correctly a string in quotes, stack size 500 is valid, and priority 1 is allowed.
Final Answer:
Missing & before xHandle in last parameter -> Option C
Quick Check:
Task handle needs & operator [OK]
Hint: Always pass &TaskHandle, not TaskHandle alone [OK]
Common Mistakes:
Passing task handle without &
Removing quotes from task name
Incorrect assumptions about stack size or priority
5. You want to create two tasks with different priorities using xTaskCreate(). Which code snippet correctly creates both tasks and stores their handles?
Each task handle must be passed by address using &. TaskHandle_t handle1, handle2;
xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1);
xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); correctly does this for both handles.
Step 2: Check task names and priorities
Task names are strings in quotes. Priorities differ (3 and 5) as required. TaskHandle_t handle1, handle2;
xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1);
xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); matches this correctly.