0
0
FreeRTOSprogramming~20 mins

Common RTOS bugs and debugging strategies in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RTOS Debugging Master
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 task scheduling code?

Consider two tasks with different priorities. What will be printed when both tasks run?

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

void Task1(void *pvParameters) {
    printf("Task1 start\n");
    vTaskDelay(pdMS_TO_TICKS(100));
    printf("Task1 end\n");
    vTaskDelete(NULL);
}

void Task2(void *pvParameters) {
    printf("Task2 start\n");
    vTaskDelay(pdMS_TO_TICKS(50));
    printf("Task2 end\n");
    vTaskDelete(NULL);
}

int main() {
    xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL);
    xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
ATask1 start\nTask1 end\nTask2 start\nTask2 end\n
BTask1 start\nTask2 start\nTask2 end\nTask1 end\n
CTask2 start\nTask1 start\nTask1 end\nTask2 end\n
DTask2 start\nTask2 end\nTask1 start\nTask1 end\n
Attempts:
2 left
💡 Hint

Remember that higher priority tasks preempt lower priority ones, and vTaskDelay causes the task to block for the specified time.

🧠 Conceptual
intermediate
1:30remaining
Which common RTOS bug causes a system to freeze due to tasks waiting forever?

In FreeRTOS, what is the typical cause of a system freeze when tasks never resume?

AIncorrect task notification value
BPriority inversion without priority inheritance
CStack overflow in a task
DDeadlock caused by improper mutex usage
Attempts:
2 left
💡 Hint

Think about tasks waiting on each other indefinitely.

🔧 Debug
advanced
2:00remaining
Identify the bug causing stack overflow in this FreeRTOS task

Examine the task code below. What causes the stack overflow?

FreeRTOS
void TaskExample(void *pvParameters) {
    char buffer[1024];
    while(1) {
        // Do some work
        vTaskDelay(pdMS_TO_TICKS(10));
    }
}
AvTaskDelay is called inside the loop causing stack to grow
BMissing vTaskDelete causes stack overflow
CThe large local buffer uses too much stack space causing overflow
DInfinite loop without break causes stack overflow
Attempts:
2 left
💡 Hint

Consider how much memory the stack has and what local variables consume.

📝 Syntax
advanced
1:30remaining
What error does this FreeRTOS queue code produce?

What error occurs when running this code snippet?

FreeRTOS
QueueHandle_t queue = xQueueCreate(5, sizeof(int));
int value = 10;
xQueueSend(queue, &value, 0);
xQueueSend(queue, NULL, 0);
ARuntime error due to NULL pointer passed to xQueueSend
BCompile-time error due to wrong argument type
CNo error, both sends succeed
DDeadlock because queue is full
Attempts:
2 left
💡 Hint

Check the parameters passed to xQueueSend carefully.

🚀 Application
expert
2:00remaining
How many items are in the queue after this sequence?

Given a FreeRTOS queue created with length 3, what is the number of items in the queue after these operations?

QueueHandle_t q = xQueueCreate(3, sizeof(int));
int a=1,b=2,c=3,d=4;
xQueueSend(q, &a, 0);
xQueueSend(q, &b, 0);
xQueueSend(q, &c, 0);
xQueueSend(q, &d, 0);
A3 items, last send fails because queue is full
B4 items, queue expands automatically
C2 items, first send overwritten
D0 items, all sends fail
Attempts:
2 left
💡 Hint

Remember the fixed size of FreeRTOS queues and behavior when full.