#include <STM32FreeRTOS.h>
SemaphoreHandle_t mutex;
// Print a sequence one character at a time
void printSeq(const char *seq) {
xSemaphoreTake(mutex, portMAX_DELAY);
for (int i = 0; seq[i] != '\0'; i++) {
Serial.print(seq[i]);
vTaskDelay(pdMS_TO_TICKS(2)); // hand off mid-sequence
}
Serial.println();
xSemaphoreGive(mutex);
}
void taskA(void *pv) {
for (;;) { printSeq("abcdefg"); vTaskDelay(pdMS_TO_TICKS(20)); }
}
void taskB(void *pv) {
for (;;) { printSeq("1234567"); vTaskDelay(pdMS_TO_TICKS(20)); }
}
void setup() {
Serial.begin(115200);
mutex = xSemaphoreCreateMutex();
xTaskCreate(taskA, "A", 256, NULL, 1, NULL);
xTaskCreate(taskB, "B", 256, NULL, 1, NULL);
vTaskStartScheduler();
}
void loop() {}