Bird
Raised Fist0
FreeRTOSprogramming~20 mins

FreeRTOS architecture overview - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Architecture Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Core components of FreeRTOS

Which of the following is NOT a core component of the FreeRTOS architecture?

AMemory management unit (MMU)
BTask scheduler
CQueues for inter-task communication
DSoftware timers
Attempts:
2 left
💡 Hint

Think about what FreeRTOS provides for multitasking and communication, and what hardware features it does not include.

❓ Predict Output
intermediate
2:00remaining
FreeRTOS task states output

Given the following FreeRTOS task state code snippet, what will be the output?

FreeRTOS
eTaskState state = eRunning;

switch(state) {
    case eRunning:
        printf("Task is running\n");
        break;
    case eReady:
        printf("Task is ready\n");
        break;
    case eBlocked:
        printf("Task is blocked\n");
        break;
    default:
        printf("Unknown state\n");
}
AUnknown state
BTask is ready
CTask is blocked
DTask is running
Attempts:
2 left
💡 Hint

Look at the value assigned to state and which case it matches.

🔧 Debug
advanced
2:00remaining
Diagnosing priority inversion in FreeRTOS

Consider a FreeRTOS system where a low priority task holds a mutex, and a high priority task is blocked waiting for it. What problem is this an example of?

APriority inversion
BDeadlock
CStarvation
DRace condition
Attempts:
2 left
💡 Hint

Think about what happens when a higher priority task waits for a resource held by a lower priority task.

📝 Syntax
advanced
2:00remaining
Correct FreeRTOS task creation syntax

Which of the following code snippets correctly creates a FreeRTOS task?

AxTaskCreate(TaskFunction, Task1, 1000, NULL, 2, NULL);
BxTaskCreate(TaskFunction, "Task1", 1000, NULL, 2, NULL);
CxTaskCreate(TaskFunction, "Task1", 1000, NULL, "2", NULL);
DxTaskCreate(TaskFunction, "Task1", 1000, NULL);
Attempts:
2 left
💡 Hint

Check the function parameters and their types carefully.

🚀 Application
expert
2:00remaining
Determining FreeRTOS queue length after operations

A FreeRTOS queue is created with length 3. The following operations occur in order:

  1. Send one item to the queue
  2. Receive one item from the queue
  3. Send two items to the queue
  4. Receive one item from the queue

How many items remain in the queue after these operations?

A3
B2
C1
D0
Attempts:
2 left
💡 Hint

Track the queue count step-by-step after each send and receive.

Practice

(1/5)
1. What is the main role of the FreeRTOS scheduler in its architecture?
easy
A. To store data permanently
B. To decide which task runs and when
C. To compile the code
D. To manage hardware interrupts only

Solution

  1. Step 1: Understand the scheduler's purpose

    The scheduler controls task execution order and timing in FreeRTOS.
  2. Step 2: Compare with other options

    Storing data, compiling code, or only managing interrupts are not scheduler roles.
  3. Final Answer:

    To decide which task runs and when -> Option B
  4. Quick Check:

    Scheduler controls task timing = To decide which task runs and when [OK]
Hint: Scheduler manages task timing and switching [OK]
Common Mistakes:
  • Confusing scheduler with memory storage
  • Thinking scheduler compiles code
  • Assuming scheduler only handles interrupts
2. Which of the following is the correct way to create a task in FreeRTOS?
easy
A. task_create(TaskFunction, StackSize);
B. CreateTask(TaskFunction, Priority);
C. xTaskCreate(TaskFunction, "TaskName", StackSize, NULL, Priority, &TaskHandle);
D. StartTask(TaskFunction, "TaskName");

Solution

  1. Step 1: Recall FreeRTOS task creation syntax

    The correct function is xTaskCreate with parameters: function, name, stack size, parameters, priority, and handle.
  2. Step 2: Check options for exact match

    Only xTaskCreate(TaskFunction, "TaskName", StackSize, NULL, Priority, &TaskHandle); matches the correct FreeRTOS API call syntax.
  3. Final Answer:

    xTaskCreate(TaskFunction, "TaskName", StackSize, NULL, Priority, &TaskHandle); -> Option C
  4. Quick Check:

    Use xTaskCreate with full parameters = xTaskCreate(TaskFunction, "TaskName", StackSize, NULL, Priority, &TaskHandle); [OK]
Hint: Remember xTaskCreate needs 6 parameters [OK]
Common Mistakes:
  • Using incorrect function names
  • Omitting required parameters
  • Confusing task creation with starting tasks
3. Given the following FreeRTOS code snippet, what will be the output on the serial console?
void vTask1(void *pvParameters) {
    for (;;) {
        printf("Task 1 running\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

void vTask2(void *pvParameters) {
    for (;;) {
        printf("Task 2 running\n");
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

int main() {
    xTaskCreate(vTask1, "Task1", 1000, NULL, 1, NULL);
    xTaskCreate(vTask2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
medium
A. Task 1 running every 1 second, Task 2 running every 0.5 seconds
B. Task 1 and Task 2 run simultaneously without delay
C. Only Task 1 runs, Task 2 never runs
D. No output because scheduler is not started

Solution

  1. Step 1: Analyze task delays

    Task 1 delays 1000 ms (1 second), Task 2 delays 500 ms (0.5 seconds) between prints.
  2. Step 2: Understand scheduler behavior

    Both tasks have same priority and run repeatedly with their delays, so Task 2 prints twice as often.
  3. Final Answer:

    Task 1 running every 1 second, Task 2 running every 0.5 seconds -> Option A
  4. Quick Check:

    Delays control print frequency = Task 1 running every 1 second, Task 2 running every 0.5 seconds [OK]
Hint: Check vTaskDelay times to predict print frequency [OK]
Common Mistakes:
  • Assuming tasks run simultaneously without delay
  • Thinking only one task runs
  • Ignoring vTaskStartScheduler call
4. Identify the error in this FreeRTOS task creation code snippet:
void vTask(void *pvParameters) {
    for (;;) {
        // Task code
    }
}

int main() {
    xTaskCreate(vTask, "Task", 1000, NULL, 2);
    vTaskStartScheduler();
    return 0;
}
medium
A. Missing task handle parameter in xTaskCreate
B. Task function should not have an infinite loop
C. Priority value 2 is invalid
D. vTaskStartScheduler() should be called before xTaskCreate

Solution

  1. Step 1: Check xTaskCreate parameters

    xTaskCreate requires 6 parameters; here only 5 are provided, missing the task handle pointer.
  2. Step 2: Verify other parts

    Infinite loop in task is normal, priority 2 is valid, scheduler must start after task creation.
  3. Final Answer:

    Missing task handle parameter in xTaskCreate -> Option A
  4. Quick Check:

    xTaskCreate needs 6 params = Missing handle param [OK]
Hint: Count xTaskCreate parameters; must be six [OK]
Common Mistakes:
  • Omitting task handle parameter
  • Misunderstanding infinite loops in tasks
  • Incorrect order of scheduler start
5. You want to design a FreeRTOS system where a high-priority task waits for data from a low-priority task without wasting CPU time. Which FreeRTOS feature best supports this design?
hard
A. Running both tasks at the same priority to share CPU equally
B. Using vTaskDelay in the high-priority task to wait
C. Using global variables with busy-wait loops
D. Using a queue to send data and block the high-priority task until data arrives

Solution

  1. Step 1: Understand task synchronization needs

    The high-priority task must wait efficiently without wasting CPU cycles.
  2. Step 2: Evaluate FreeRTOS features

    Queues allow blocking the high-priority task until data is available, avoiding busy-waiting.
  3. Step 3: Rule out other options

    vTaskDelay wastes time, busy-wait loops waste CPU, equal priority doesn't guarantee waiting.
  4. Final Answer:

    Using a queue to send data and block the high-priority task until data arrives -> Option D
  5. Quick Check:

    Queue blocks task efficiently = Using a queue to send data and block the high-priority task until data arrives [OK]
Hint: Use queues to block and wait without CPU waste [OK]
Common Mistakes:
  • Using delays instead of blocking
  • Busy-waiting wastes CPU
  • Ignoring priority differences
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard