【RT-thread】STM32F103C8T6手动移植RT-thread。

一、项目描述

STM32F103C8T6标准库下,手动移植嵌入式实时操作系统rt-thread-v3.0.3


二、操作步骤:

1.官网https://www.rt-thread.org/download.html下载压缩包。用百度网盘可以下载历史版本
在这里插入图片描述
在这里插入图片描述

2.解压后,文件夹内目录如下。其中红框内的是移植过程中需要用到的文件夹。
① components 包含rt-threadde 许多组件
② include 包含rt-thread头文件
③ libcpu 包含着各种CPU体系结构下的相关移植
④ src 包含rt-thread的源码
在这里插入图片描述

3.复制stm32f103c8t6的点灯程序,添加文件夹RTthread,将上述4个文件夹复制过来。
在这里插入图片描述
在这里插入图片描述

4.在bsp文件夹中找到stm32f1的例程,将例程中的3个文件复制到User文件夹中。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5.将stm32f10x_it.h,stm32f10x_it.c中这下面3个函数屏蔽掉。
在这里插入图片描述

6.在main()函数中包含rt-thread必要的头文件,然后就开始使用rt-thread写程序了。

#include "board.h"
#include "rtthread.h"
//定义和初始化一个线程控制块
static rt_thread_t led_content = RT_NULL;

// 点灯程序
void led_light(void *arg);

//主函数
int main(void)
{
	/**
	 * This function will create a thread object and allocate thread object memory
	 * and stack.
	 *
	 * @param name the name of thread, which shall be unique
	 * @param entry the entry function of thread
	 * @param parameter the parameter of thread enter function
	 * @param stack_size the size of thread stack
	 * @param priority the priority of thread
	 * @param tick the time slice if there are same priority thread
	 *
	 * @return the created thread object
	 */
	led_content = rt_thread_create("led",		
						 			led_light, 
									RT_NULL,	
									512,		
						 			3,			
						 			20);		

	/**
	 * This function will start a thread and put it to system ready queue
	 *
	 * @param thread the thread to be started
	 *
	 * @return the operation status, RT_EOK on OK, -RT_ERROR on error
	 */
	if (led_content != RT_NULL)
		rt_thread_startup(led_content);
	else
		return -1;
}

7.烧录程序,灯亮

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值