- 前言
- 一、项目创建
- 二、修改Keil里面的文件
- 三、运行结果
- 提示
- 参考文章
本次实验需要提前安装好RT-thread Nano。教程如下
https://blog.csdn.net/qq_36075612/article/details/107309750
获取RT-Thread Nano软件包
https://www.rt-thread.org/download/cube/RealThread.RT-Thread.pdsc
-
配置SYS:
-
配置RT-Thread
先选择Select Components
勾选如下
-
配置NVIC:
-
RCC配置
-
配置使USART1(此处使用PA3和PA4)
-
项目配置
- 新建名为app_rt_thread的文件
代码如下
#include "rtthread.h"
#include "main.h"
#include "stdio.h"
struct rt_thread led1_thread;
rt_uint8_t rt_led1_thread_stack[128];
void led1_task_entry(void *parameter);
//初始化线程函数
void MX_RT_Thread_Init(void)
{
//初始化LED1线程
rt_thread_init(&led1_thread,"led1",led1_task_entry,RT_NULL,&rt_led1_thread_stack[0],sizeof(rt_led1_thread_stack),3,20);
//开启线程调度
rt_thread_startup(&led1_thread);
}
//主任务
void MX_RT_Thread_Process(void)
{
printf("Hello RT_Thread!!!");
rt_thread_delay(2000);
}
//LED1任务
void led1_task_entry(void *parameter)
{
while(1)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_RESET);
rt_thread_delay(500);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_SET);
rt_thread_delay(500);
}
}
编译后,修改rtconfig.h中的注释
- 修改board.c中uart_init函数里的USART2为USART1
- 修改main
添加
extern void MX_RT_Thread_Init(void); extern void MX_RT_Thread_Process(void);
在while中添加
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_4); rt_thread_delay(1000); HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_3); rt_thread_delay(1000);三、运行结果 提示
烧录时Boot0置1
查看结果时Boot0置0,并Reset
https://blog.csdn.net/YouthBlood9/article/details/122248262?spm=1001.2014.3001.5501



