环境介绍:
- win10
- vscode
- platformio
- arduino框架:stm32duino(https://github.com/stm32duino)
- freertos:stm32duino-freertos(https://github.com/stm32duino/STM32FreeRTOS)
- 硬件开发板:NUCLEO-F767ZI
文档和教程
- 官网文档:https://www.freertos.org/FreeRTOS-quick-start-guide.html
- 百问网文档(中文):http://rtos.100ask.net/freeRTOS%E6%95%99%E7%A8%8B/index.html
步骤:
新建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:
}
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
走着的小站
本文地址: STM32在Arduino下运行FREERTOS的详细记录(基于VSCode+PlatformIO)
本文地址: STM32在Arduino下运行FREERTOS的详细记录(基于VSCode+PlatformIO)