Go to the official website of Zhengdian Atoms to download the corresponding materials. Anyone who sees this should know it. Here is mainly to supplement the details of my own learning.
In D:\Explorer F4 data disk (disk A)\[Punctual Atom] STM32F103 minimum system board data\4, program source code\4, extended routines\5, FreeRTOS routines\5, FreeRTOS routines\FreeRTOS experiment 2 -1 FreeRTOS porting experiment\USER open
The files in it correspond to where they are transplanted from and how they work. There is a development manual
Corresponding directory: D:\Explorer F4 Data Disk (Disk A)\[Punctual Atom]STM32F103 Minimum System Board Data\STM32F1 FreeRTOS Development Manual_V1.1\STM32F1 FreeRTOS Development Manual_V1.1
Understanding in FreeRTOSConfig.h
You can also see it by directly clicking on the corresponding header file
Then modify the corresponding led.c and led.h in the routine. When I am here, the smallest system board is only one ledPA8
so
#include "led.h"
//初始化PA8为输出口.并使能这个口的时钟
//LED IO初始化
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_SetBits(GPIOA,GPIO_Pin_8);
}
#ifndef __LED_H
#define __LED_H
#include "sys.h"
#define LED0 PAout(8)// PA8
void LED_Init(void);//初始化
#endif
The main function does not need to be modified
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "FreeRTOS.h"
#include "task.h"
/************************************************
ALIENTEK 战舰STM32F103开发板 FreeRTOS实验2-1
FreeRTOS移植实验-库函数版本
技术支持:www.openedv.com
淘宝店铺:http://eboard.taobao.com
关注微信公众平台微信号:"正点原子",免费获取STM32资料。
广州市星翼电子科技有限公司
作者:正点原子 @ALIENTEK
************************************************/
//任务优先级
#define START_TASK_PRIO 1
//任务堆栈大小
#define START_STK_SIZE 128
//任务句柄
TaskHandle_t StartTask_Handler;
//任务函数
void start_task(void *pvParameters);
//任务优先级
#define LED0_TASK_PRIO 2
//任务堆栈大小
#define LED0_STK_SIZE 50
//任务句柄
TaskHandle_t LED0Task_Handler;
//任务函数
void led0_task(void *pvParameters);
//任务优先级
#define LED1_TASK_PRIO 3
//任务堆栈大小
#define LED1_STK_SIZE 50
//任务句柄
TaskHandle_t LED1Task_Handler;
//任务函数
void led1_task(void *pvParameters);
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4
delay_init(); //延时函数初始化
uart_init(115200); //初始化串口
LED_Init(); //初始化LED
//创建开始任务
xTaskCreate((TaskFunction_t )start_task, //任务函数
(const char* )"start_task", //任务名称
(uint16_t )START_STK_SIZE, //任务堆栈大小
(void* )NULL, //传递给任务函数的参数
(UBaseType_t )START_TASK_PRIO, //任务优先级
(TaskHandle_t* )&StartTask_Handler); //任务句柄
vTaskStartScheduler(); //开启任务调度
}
//开始任务任务函数
void start_task(void *pvParameters)
{
taskENTER_CRITICAL(); //进入临界区
//创建LED0任务
xTaskCreate((TaskFunction_t )led0_task,
(const char* )"led0_task",
(uint16_t )LED0_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED0_TASK_PRIO,
(TaskHandle_t* )&LED0Task_Handler);
//创建LED1任务
xTaskCreate((TaskFunction_t )led1_task,
(const char* )"led1_task",
(uint16_t )LED1_STK_SIZE,
(void* )NULL,
(UBaseType_t )LED1_TASK_PRIO,
(TaskHandle_t* )&LED1Task_Handler);
vTaskDelete(StartTask_Handler); //删除开始任务
taskEXIT_CRITICAL(); //退出临界区
}
//LED0任务函数
void led0_task(void *pvParameters)
{
static float float_num=0.01;
while(1)
{
float_num+=0.01f;
taskENTER_CRITICAL(); //进入临界区
printf("111\r\n");
printf("float_num的值为: %.4f\r\n",float_num); /*串口打印结果*/
taskEXIT_CRITICAL(); //退出临界区
printf("222\r\n");
vTaskDelay(1000);
}
}
//LED1任务函数
void led1_task(void *pvParameters)
{
while(1)
{ printf("333\r\n");
LED0=0;
vTaskDelay(200);
LED0=1;
vTaskDelay(800);
}
}
When the phenomenon is realized, the led flickers, and the serial port can be seen
That's it. The development board used is STM32F103RCT6 of Lushen Electronics