0
0
FreeRTOSprogramming~30 mins

Multiple tasks running concurrently in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple tasks running concurrently
📖 Scenario: You are working on a small embedded system that needs to perform two tasks at the same time: blinking an LED and sending a message over a serial port. To do this, you will create two FreeRTOS tasks that run concurrently.
🎯 Goal: Create two FreeRTOS tasks: one that blinks an LED every 500 milliseconds and another that sends a message "Hello from Task 2" every 1000 milliseconds. Both tasks should run concurrently.
📋 What You'll Learn
Create a task called Task1 that toggles an LED every 500 ms
Create a task called Task2 that sends the message "Hello from Task 2" every 1000 ms
Use FreeRTOS API functions to create and start the tasks
Use vTaskDelay for timing delays
Start the FreeRTOS scheduler to run the tasks concurrently
💡 Why This Matters
🌍 Real World
Embedded systems often need to perform multiple operations at the same time, like blinking LEDs, reading sensors, and communicating. FreeRTOS tasks let you do this easily.
💼 Career
Understanding how to create and manage concurrent tasks is essential for embedded software developers working with real-time operating systems.
Progress0 / 4 steps
1
DATA SETUP: Define the LED pin and include FreeRTOS headers
Write the code to include FreeRTOS.h and task.h headers. Define a macro LED_PIN with the value 13 representing the LED pin number.
FreeRTOS
Need a hint?

Use #include "FreeRTOS.h" and #include "task.h" to include FreeRTOS headers. Define LED_PIN as 13 using #define.

2
CONFIGURATION: Create task function prototypes and stack sizes
Declare two task functions: void Task1(void *pvParameters) and void Task2(void *pvParameters). Also, define two constants: TASK1_DELAY_MS as 500 and TASK2_DELAY_MS as 1000 for the delay times in milliseconds.
FreeRTOS
Need a hint?

Declare the two task functions with the correct signature. Define the delay constants using #define.

3
CORE LOGIC: Implement the two tasks and create them in main
Implement Task1 to toggle the LED pin and delay for TASK1_DELAY_MS milliseconds using vTaskDelay. Implement Task2 to print "Hello from Task 2" and delay for TASK2_DELAY_MS milliseconds. In main, create both tasks with priority 1 and start the scheduler.
FreeRTOS
Need a hint?

Use infinite loops in each task. Use vTaskDelay(pdMS_TO_TICKS(...)) for delays. Create tasks with xTaskCreate and start the scheduler with vTaskStartScheduler().

4
OUTPUT: Run the program and observe the concurrent task output
Run the program and observe the output. The LED state should toggle every 500 ms and the message "Hello from Task 2" should print every 1000 ms, showing both tasks running concurrently.
FreeRTOS
Need a hint?

Look at the console output. You should see the LED toggling messages every 500 ms and the "Hello from Task 2" message every 1000 ms, interleaved.