0
0
FreeRTOSprogramming~30 mins

Stack high water mark monitoring in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Stack High Water Mark Monitoring in FreeRTOS
📖 Scenario: You are working on a FreeRTOS-based embedded system. To ensure your tasks have enough stack memory, you want to monitor the stack high water mark for a specific task. This helps prevent stack overflow and system crashes.
🎯 Goal: Build a simple FreeRTOS program that creates a task and monitors its stack high water mark using the uxTaskGetStackHighWaterMark API. You will print the high water mark value to check how much stack space remains unused.
📋 What You'll Learn
Create a FreeRTOS task function named vExampleTask.
Create a task handle variable named xExampleTaskHandle.
Create the task with xTaskCreate using vExampleTask and store the handle in xExampleTaskHandle.
Declare a variable uxHighWaterMark to hold the stack high water mark.
Use uxTaskGetStackHighWaterMark(xExampleTaskHandle) to get the high water mark.
Print the high water mark value using printf.
💡 Why This Matters
🌍 Real World
Embedded developers use stack high water mark monitoring to ensure tasks have enough memory and avoid crashes.
💼 Career
Understanding FreeRTOS stack monitoring is essential for embedded systems engineers and IoT developers to build reliable applications.
Progress0 / 4 steps
1
Create the example task and task handle
Create a task function called vExampleTask that runs an infinite loop with vTaskDelay(1000 / portTICK_PERIOD_MS). Also, declare a task handle variable called xExampleTaskHandle initialized to NULL.
FreeRTOS
Need a hint?

Define the task function with an infinite loop and delay. Declare the task handle variable outside the function.

2
Create the task and store its handle
Use xTaskCreate to create the task vExampleTask with name "ExampleTask", stack size configMINIMAL_STACK_SIZE, no parameters, priority tskIDLE_PRIORITY + 1, and store the task handle in xExampleTaskHandle.
FreeRTOS
Need a hint?

Use xTaskCreate with the exact parameters and start the scheduler with vTaskStartScheduler().

3
Get the stack high water mark
Declare a variable uxHighWaterMark of type UBaseType_t. Assign it the value returned by uxTaskGetStackHighWaterMark(xExampleTaskHandle).
FreeRTOS
Need a hint?

Use the FreeRTOS API uxTaskGetStackHighWaterMark with the task handle to get the high water mark.

4
Print the stack high water mark
Add a printf statement to print the text "Stack high water mark: " followed by the value of uxHighWaterMark inside main_app before vTaskStartScheduler().
FreeRTOS
Need a hint?

Use printf with %u to print the unsigned integer value of uxHighWaterMark.