【FreeRTOS】Arduino开发STM32

0.开发环境(工具)

Vscode 、platformio、arduino、STM32F103C8T6、USB-TTL

引脚连接:STM32直接设置为烧录模式即可,烧录完成后会自动运行程序。

   

1.点灯加串口输出调试

注意事项:每次上传程序前,需要按一下复位键。

#include <Arduino.h>
#define ledPin PC13

HardwareSerial Serial1(PA10, PA9); // 将串口1的管脚指定到PA10(RX),PA9(TX)引脚上
int i = 0;
void setup()
{
  Serial1.begin(115200);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  Serial1.println(i++);
}

platformio.ini文件配置

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_port = COM17
monitor_port = COM17
monitor_speed = 115200
upload_protocol = serial

2.FreeRTOS开发STM32

添加相关库函数

测试程序:板载LED闪烁,同时进行串口输出

#include <Arduino.h>
#include <STM32FreeRTOS.h>
#define ledPin PC13

HardwareSerial Serial1(PA10, PA9); // 将串口1的管脚指定到PA10(RX),PA9(TX)引脚上
int i = 0;

void test1(void *pt)
{
  pinMode(ledPin, OUTPUT);
  while (1)
  {
    digitalWrite(ledPin, HIGH);
    vTaskDelay(100);
    digitalWrite(ledPin, LOW);
    vTaskDelay(100);
    Serial1.println(i++);
  }
}

void setup()
{
  Serial1.begin(115200);

  xTaskCreate(test1, "", 1024, NULL, 1, NULL);
  vTaskStartScheduler(); // 开启任务调度,这条语句必须加,否则程序无法正常执行
  vTaskDelete(NULL);
}

void loop()
{
}

 vTaskStartScheduler()的作用

vTaskStartScheduler()是FreeRTOS实时操作系统中的一个函数,它的作用是启动任务调度器在FreeRTOS中,任务调度器负责按照任务的优先级和调度策略来调度任务的执行

具体而言,vTaskStartScheduler()函数会初始化FreeRTOS的内部数据结构,并开始任务调度器的运行。一旦调用了该函数,任务调度器会按照任务的优先级和调度策略开始调度任务的执行。它会根据每个任务的优先级,以抢占或协作的方式分配处理器时间片给不同的任务,从而实现任务的并发执行。

vTaskStartScheduler()函数通常是在系统初始化过程的最后被调用,它标志着系统进入多任务运行状态。在调用该函数之前,需要先创建并初始化好各个任务,并设置好任务的优先级。

需要注意的是,vTaskStartScheduler()函数是一个永不返回的函数,一旦任务调度器开始运行,它将控制整个系统的执行,直到发生严重错误或调用了特殊的函数来停止任务调度器的运行。

总结起来,vTaskStartScheduler()函数的作用是启动FreeRTOS任务调度器,让各个任务按照优先级和调度策略并发执行

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Using FreeRTOS and libopencm3 instead of the Arduino software environment, this book will help you develop multi-tasking applications that go beyond Arduino norms. In addition to the usual peripherals found in the typical Arduino device, the STM32 device includes a USB controller, RTC (Real Time Clock), DMA (Direct Memory Access controller), CAN bus and more. Each chapter contains clear explanations of the STM32 hardware capabilities to help get you started with the device, including GPIO and several other ST Microelectronics peripherals like USB and CAN bus controller. You’ll learn how to download and set up the libopencm3 + FreeRTOS development environment, using GCC. With everything set up, you’ll leverage FreeRTOS to create tasks, queues, and mutexes. You’ll also learn to work with the I2C bus to add GPIO using the PCF8574 chip. And how to create PWM output for RC control using hardware timers. You'll be introduced to new concepts that are necessary to master the STM32, such as how to extend code with GCC overlays using an external Winbond ?W25Q32 flash chip. Your knowledge is tested at the end of each chapter with exercises. Upon completing this book, you’ll be ready to work with any of the devices in the STM32 family. Beginning STM32 provides the professional, student, or hobbyist a way to learn about ARM without costing an arm! What You'll Learn Initialize and use the libopencm3 drivers and handle interrupts Use DMA to drive a SPI based OLED displaying an analog meter Read PWM from an RC control using hardware timers Who This Book Is For Experienced embedded engineers, students, hobbyists and makers wishing to explore the ARM architecture, going beyond Arduino limits.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值