Challenge - 5 Problems
FreeRTOS Timer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this FreeRTOS timer callback?
Consider a FreeRTOS software timer set to trigger every 1000 ms. The callback function increments a counter and prints it. What will be printed after the timer triggers 3 times?
FreeRTOS
static int count = 0; void vTimerCallback(TimerHandle_t xTimer) { count++; printf("Count: %d\n", count); } // Timer created with xTimerCreate("StatusTimer", pdMS_TO_TICKS(1000), pdTRUE, NULL, vTimerCallback); // Timer started with xTimerStart(timer, 0);
Attempts:
2 left
💡 Hint
Remember the timer callback increments the count each time it runs.
✗ Incorrect
The timer callback runs every 1000 ms, incrementing the count from 0 to 1, then 2, then 3, printing each value.
🧠 Conceptual
intermediateWhich FreeRTOS timer type is best for periodic status reporting?
You want to report system status every 5 seconds automatically. Which timer type should you use in FreeRTOS?
Attempts:
2 left
💡 Hint
Think about repeating actions without manual restart.
✗ Incorrect
A periodic timer automatically triggers repeatedly at the set interval, ideal for periodic status reporting.
🔧 Debug
advancedWhy does this FreeRTOS timer callback not print anything?
Given this code snippet, why is there no output from the timer callback?
FreeRTOS
void vTimerCallback(TimerHandle_t xTimer) {
printf("Timer triggered\n");
}
void main() {
TimerHandle_t timer = xTimerCreate("MyTimer", pdMS_TO_TICKS(1000), pdTRUE, NULL, vTimerCallback);
// Missing xTimerStart call
vTaskStartScheduler();
}Attempts:
2 left
💡 Hint
Check if the timer was activated after creation.
✗ Incorrect
Creating a timer does not start it. Without calling xTimerStart, the timer callback will never be called.
📝 Syntax
advancedIdentify the syntax error in this FreeRTOS timer callback declaration
Which option contains the correct syntax for a FreeRTOS timer callback function?
Attempts:
2 left
💡 Hint
Check the parameter type and return type required by FreeRTOS.
✗ Incorrect
The callback must return void and accept a TimerHandle_t parameter. Option C matches this exactly.
🚀 Application
expertHow to safely update a shared variable in a FreeRTOS timer callback?
You have a global variable 'statusCount' updated in a timer callback and read in a task. How should you protect 'statusCount' to avoid data corruption?
FreeRTOS
volatile int statusCount = 0; void vTimerCallback(TimerHandle_t xTimer) { statusCount++; } void vStatusTask(void *pvParameters) { while(1) { printf("Status count: %d\n", statusCount); vTaskDelay(pdMS_TO_TICKS(1000)); } }
Attempts:
2 left
💡 Hint
Think about how to prevent race conditions when multiple contexts access the same variable.
✗ Incorrect
Using a mutex or critical section ensures atomic access to 'statusCount', preventing data corruption.
