Bird
Raised Fist0
FreeRTOSprogramming~10 mins

Trace hooks and FreeRTOS+Trace - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a trace hook function that runs when a task is switched in.

FreeRTOS
void traceTASK_SWITCHED_IN(void) {
    [1];
}
Drag options to blanks, or click blank then click option'
Aprintf("Task switched in\n")
BvTaskDelay(10)
CxTaskCreate()
DvTaskDelete(NULL)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to create or delete tasks inside the trace hook.
Using delay functions inside trace hooks.
2fill in blank
medium

Complete the code to enable FreeRTOS+Trace recording in the configuration.

FreeRTOS
#define configUSE_TRACE_FACILITY [1]
Drag options to blanks, or click blank then click option'
A0
B2
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the value to 0 disables tracing.
Using values greater than 1 which are not valid.
3fill in blank
hard

Fix the error in the trace hook function to correctly record a task switch event.

FreeRTOS
void traceTASK_SWITCHED_OUT(void) {
    [1](pxCurrentTCB->pxTaskTag);
}
Drag options to blanks, or click blank then click option'
AvTraceStart
BvTraceStoreTaskSwitchedOut
CxTaskCreate
DvTaskDelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using delay or task creation functions inside trace hooks.
Calling functions unrelated to tracing.
4fill in blank
hard

Fill both blanks to create a dictionary of task names and their run times using FreeRTOS+Trace API.

FreeRTOS
for (int i = 0; i < uxTaskGetNumberOfTasks(); i++) {
    char* name = pcTaskGetName([1]);
    uint32_t time = ulTaskGetRunTimeCounter([2]);
    taskTimes[name] = time;
}
Drag options to blanks, or click blank then click option'
Ai
BpxCurrentTCB
CNULL
DxTaskGetHandle(NULL)
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL or current task handle instead of the loop index.
Mixing task handles and indexes incorrectly.
5fill in blank
hard

Fill all three blanks to start trace recording, record a task switch, and stop recording.

FreeRTOS
vTrace[1]();
vTrace[2](pxCurrentTCB->pxTaskTag);
vTrace[3]();
Drag options to blanks, or click blank then click option'
AStart
BStoreTaskSwitchedIn
CStop
DReset
Attempts:
3 left
💡 Hint
Common Mistakes
Using reset instead of stop to end trace.
Not calling the store function for task switch.

Practice

(1/5)
1. What is the main purpose of trace hooks in FreeRTOS?
easy
A. To reduce memory usage of the FreeRTOS kernel
B. To increase the speed of task switching
C. To monitor tasks and events as they happen in the system
D. To automatically fix bugs in the code

Solution

  1. Step 1: Understand what trace hooks do

    Trace hooks are special points in FreeRTOS code that let you watch tasks and events when they occur.
  2. Step 2: Identify the main purpose

    The main use is to monitor and record system behavior for debugging or learning.
  3. Final Answer:

    To monitor tasks and events as they happen in the system -> Option C
  4. Quick Check:

    Trace hooks = monitor tasks/events [OK]
Hint: Trace hooks watch events live in FreeRTOS [OK]
Common Mistakes:
  • Thinking trace hooks speed up tasks
  • Confusing trace hooks with memory optimization
  • Believing trace hooks fix bugs automatically
2. Which configuration option must be enabled to use trace hooks in FreeRTOS?
easy
A. configTRACE_TASK_EVENTS
B. configENABLE_TASK_SWITCH
C. configUSE_FREERTOS_TRACE
D. configUSE_TRACE_HOOKS

Solution

  1. Step 1: Identify the config option for trace hooks

    The FreeRTOS configuration option to enable trace hooks is named configUSE_TRACE_HOOKS.
  2. Step 2: Confirm other options are incorrect

    Other options like configENABLE_TASK_SWITCH or configUSE_FREERTOS_TRACE do not exist or are unrelated.
  3. Final Answer:

    configUSE_TRACE_HOOKS -> Option D
  4. Quick Check:

    Enable trace hooks = configUSE_TRACE_HOOKS [OK]
Hint: Look for configUSE_TRACE_HOOKS to enable hooks [OK]
Common Mistakes:
  • Choosing options that sound similar but don't exist
  • Confusing trace hooks with task switching configs
  • Assuming FreeRTOS+Trace needs a different config
3. Given this snippet enabling trace hooks and starting FreeRTOS+Trace recording:
vTraceEnable(TRC_START);
vTaskStartScheduler();

What is the expected result?
medium
A. Trace recording starts and scheduler runs tasks
B. Scheduler starts but trace recording is disabled
C. Trace recording starts but scheduler does not run
D. Compilation error due to wrong function call

Solution

  1. Step 1: Understand vTraceEnable(TRC_START)

    This function call starts the FreeRTOS+Trace recording of events.
  2. Step 2: Understand vTaskStartScheduler()

    This function starts the FreeRTOS scheduler to run tasks.
  3. Final Answer:

    Trace recording starts and scheduler runs tasks -> Option A
  4. Quick Check:

    vTraceEnable + vTaskStartScheduler = recording + running [OK]
Hint: vTraceEnable(TRC_START) starts recording before scheduler [OK]
Common Mistakes:
  • Thinking scheduler won't run after vTraceEnable
  • Assuming trace recording is off by default
  • Confusing function names causing compile errors
4. You added trace hooks but see no data in FreeRTOS+Trace viewer. What is a likely cause?
medium
A. configUSE_TRACE_HOOKS is not set to 1 in FreeRTOSConfig.h
B. vTraceEnable(TRC_START) was called twice
C. FreeRTOS+Trace viewer is not installed
D. Scheduler was started before enabling trace hooks

Solution

  1. Step 1: Check configUSE_TRACE_HOOKS setting

    If this is not set to 1, trace hooks do not run, so no data is recorded.
  2. Step 2: Verify other options

    Calling vTraceEnable twice or starting scheduler early usually does not prevent data. Viewer missing is unrelated to data generation.
  3. Final Answer:

    configUSE_TRACE_HOOKS is not set to 1 in FreeRTOSConfig.h -> Option A
  4. Quick Check:

    Trace hooks disabled = no data [OK]
Hint: Always enable configUSE_TRACE_HOOKS = 1 [OK]
Common Mistakes:
  • Forgetting to enable trace hooks in config
  • Blaming viewer instead of config settings
  • Assuming multiple vTraceEnable calls cause issues
5. You want to record only task switch events using FreeRTOS+Trace. Which approach is best?
hard
A. Use configUSE_TRACE_HOOKS = 0 and enable task switch trace only
B. Enable trace hooks and filter events in FreeRTOS+Trace viewer
C. Disable trace hooks and use printf in task switch hook
D. Modify FreeRTOS kernel to record only task switches

Solution

  1. Step 1: Understand trace hooks and filtering

    Trace hooks record many events; filtering in the viewer lets you see only task switches easily.
  2. Step 2: Evaluate other options

    Modifying kernel is complex and error-prone. Using printf is inefficient. Disabling trace hooks stops all tracing.
  3. Final Answer:

    Enable trace hooks and filter events in FreeRTOS+Trace viewer -> Option B
  4. Quick Check:

    Filter in viewer = easiest selective trace [OK]
Hint: Filter events in viewer instead of changing kernel [OK]
Common Mistakes:
  • Trying to modify kernel for selective tracing
  • Disabling trace hooks disables all tracing
  • Using printf slows system and is not trace hook
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