0
0
FreeRTOSprogramming~30 mins

Why RTOS over bare-metal in FreeRTOS - See It in Action

Choose your learning style9 modes available
Why RTOS over bare-metal
📖 Scenario: You are working on a small embedded device that controls home appliances. You want to understand why using a Real-Time Operating System (RTOS) like FreeRTOS can be better than writing code directly on bare-metal hardware.
🎯 Goal: Learn the basic difference between RTOS and bare-metal programming by creating a simple FreeRTOS task and comparing it with a bare-metal loop.
📋 What You'll Learn
Create a simple task function that toggles an LED
Set up a FreeRTOS scheduler to run the task
Create a bare-metal infinite loop that toggles the LED
Print output to show which method is running
💡 Why This Matters
🌍 Real World
Embedded devices like home appliances, wearables, and IoT gadgets often use RTOS to handle multiple functions smoothly.
💼 Career
Understanding RTOS vs bare-metal is key for embedded software engineers working on real-time systems.
Progress0 / 4 steps
1
Create a bare-metal infinite loop
Write a main function with an infinite while loop that toggles an LED by calling toggleLED() and prints "Bare-metal loop running" once per loop.
FreeRTOS
Need a hint?

Use a while(1) loop inside main to run forever. Call toggleLED() and then print the message.

2
Create a FreeRTOS task function
Define a FreeRTOS task function called vLEDTask that toggles the LED by calling toggleLED() and prints "RTOS task running" inside an infinite loop with vTaskDelay(1000) to wait 1 second.
FreeRTOS
Need a hint?

Define a function with void vLEDTask(void *pvParameters). Inside, use an infinite loop to toggle the LED, print the message, and delay 1000 ticks.

3
Set up FreeRTOS scheduler and create the task
In main, create the FreeRTOS task vLEDTask using xTaskCreate and start the scheduler with vTaskStartScheduler(). Remove the bare-metal loop.
FreeRTOS
Need a hint?

Use xTaskCreate with vLEDTask and then call vTaskStartScheduler() to run the RTOS tasks.

4
Print comparison output
Add print statements before the bare-metal loop and before starting the FreeRTOS scheduler to show "Starting bare-metal loop" and "Starting RTOS scheduler" respectively. Run the program and observe the output.
FreeRTOS
Need a hint?

Print the message before creating the task and starting the scheduler. The output should show the RTOS messages.