环境介绍:

文档和教程

步骤:

新建stm32工程

在pio库中搜索并安装:STM32duino FreeRTOS

然后在主程序中写如下代码即可

#include "Arduino.h"
#include "FreeRTOS.h"
#include "task.h"

void TaskReady(void);
void myappcreate(void);

static TaskHandle_t myHandleTask_led1=NULL;
static TaskHandle_t myHandleTask_led2=NULL;
static TaskHandle_t myHandleTask_led3=NULL;
void myTask_led1(void *pvParameters)
{
  while(1)
  {
    digitalWrite(LED_BLUE,HIGH);
    vTaskDelay(1500);
    digitalWrite(LED_BLUE,LOW);
    vTaskDelay(1500);
  }
}
void myTask_led2(void *pvParameters)
{
  while(1)
  {
    digitalWrite(LED_GREEN,HIGH);
    vTaskDelay(1000);
    digitalWrite(LED_GREEN,LOW);
    vTaskDelay(1000);
  }
}
void myTask_led3(void *pvParameters)
{
  while(1)
  {
    digitalWrite(LED_RED,HIGH);
    vTaskDelay(500);
    digitalWrite(LED_RED,LOW);
    vTaskDelay(500);
  }
}
void TaskReady(void)
{
    pinMode(LED_BLUE,OUTPUT);
    pinMode(LED_GREEN,OUTPUT);
    pinMode(LED_RED,OUTPUT);
}
void myappcreate(void)
{
    TaskReady();
    xTaskCreate(
        myTask_led1,
        "myTask_led1",
        configMINIMAL_STACK_SIZE,
        NULL,
        tskIDLE_PRIORITY + 1,
        &myHandleTask_led1);
    xTaskCreate(
        myTask_led2,
        "myTask_led2",
        configMINIMAL_STACK_SIZE,
        NULL,
        tskIDLE_PRIORITY + 1,
        &myHandleTask_led2);
    xTaskCreate(
        myTask_led3,
        "myTask_led3",
        configMINIMAL_STACK_SIZE,
        NULL,
        tskIDLE_PRIORITY + 1,
        &myHandleTask_led3);

    vTaskStartScheduler();//任务开始调度
}

void setup() {
  // put your setup code here, to run once:

  myappcreate();
}
void loop() {
  // put your main code here, to run repeatedly:
}