#include "FreeRTOS.h"
#include "task.h"
// Task function for LED 1 (Pin 8)
void taskLED1(void *pvParameters) {
while (1) {
digitalWrite(8, HIGH);
delay(500); // Non-blocking FreeRTOS delay (500ms)
digitalWrite(8, LOW);
delay(500);
}
}
// Task function for LED 2 (Pin 7)
void taskLED2(void *pvParameters) {
while (1) {
digitalWrite(7, HIGH);
delay(500); // Non-blocking FreeRTOS delay (500ms)
digitalWrite(7, LOW);
delay(500);
}
}
void setup() {
Serial.begin(115200);
Serial.println("Hello, STM32 FreeRTOS!");
// Initialize both LED pins as outputs
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
// Create Task 1 for Pin 8
xTaskCreate(
taskLED1, // Pointer to the function
"LED1_Task", // Text name for the task
configMINIMAL_STACK_SIZE,
NULL, // Task input parameters
1, // Priority
NULL // Task handle
);
// Create Task 2 for Pin 7
xTaskCreate(
taskLED2, // Pointer to the function
"LED2_Task", // Text name for the task
configMINIMAL_STACK_SIZE,
NULL, // Task input parameters
2, // Priority
NULL // Task handle
);
// Start the FreeRTOS scheduler
vTaskStartScheduler();
}
void loop() {
// When using FreeRTOS, execution hands over to the scheduler.
// The loop() function is rarely reached or utilized.
delay(10);
}