一、项目描述
在
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.烧录程序,
灯亮
。