创建一个固件库项目 参考:野火固件库创建 >下载RT-Thread
>安装RT-Thread >https://www.keil.com/dd2/pack/ >
移植开始
- 将packs文件夹中的RealThread复制到刚创建的固件库项目中
复制
####
粘贴
粘贴到项目文件夹后然后根据项目进行移植
其他文件夹都可以删除
> 管理的头文件
>####
RTT内核代码移植
>####
芯片文件
> # 整理完项目结构
多层目录添加–> 直接输入rtt/ports
> ###
添加环境变量
修改
rtconfig.h
该头文件对裁剪整个 RT-Thread 所需的功能的宏均做了定义,有些宏定义被使能,有些宏定义被失能,一开始我们只需要配置最简单的功能即可。要想随心所欲的配置 RT- Thread 的功能,我们必须对这些宏定义的功能有所掌握,下面我们先简单的介绍下这些宏定义的含义,然后再对这些宏定义进行修改。(摘自野火RTT)
: 移植 RTT-1 (1) :头文件 RTE_Components.h 是在 MDK 中添加 RT-Thead Package
• 代码清单-Thread 的 Package,所以这
时由 MDK 自动生成的,目前我们没有使用 MDK 中自带的 RT.h 的时候需
个头文件不存在,如果包含了该头文件,编译的时候会报错,等下修改 rtconfig
要注释掉该头文件。
[ 修改4处如下 ]
//#include "RTE_Components.h"
#define RT_THREAD_PRIORITY_MAX 8
#define RT_TICK_PER_SECOND 1000
#define RT_MAIN_THREAD_STACK_SIZE 512
修改
board.c
在user下创建
board.h
/*
* File : board.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-07-24 Tanek the first version
*/
"board.h" // 修改
#include <rthw.h>
#include <rtthread.h>
#include
#if 0 // 修改
#define _SCB_BASE (0xE000E010UL)
#define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0))
#define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4))
#define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8))
#define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC))
#define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL))
// Updates the variable SystemCoreClock and must be called
// whenever the core clock is changed during program execution.
/* 外部时钟和函数声明 */
extern void
SystemCoreClockUpdate(void);
// Holds the system core clock, which is the system clock
// frequency supplied to the SysTick timer and the processor
// core clock.
extern uint32_t SystemCoreClock;
static uint32_t _SysTick_Config(rt_uint32_t ticks)
{
if ((ticks - 1) > 0xFFFFFF)
{
return 1;
}
= ticks - 1;
_SYSTICK_LOAD = 0xFF;
_SYSTICK_PRI = 0;
_SYSTICK_VAL = 0x07;
_SYSTICK_CTRL
return 0;
}
#endif // 修改
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE 1024
static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
void *rt_heap_begin_get(void)
RT_WEAK {
return rt_heap;
}
void *rt_heap_end_get(void)
RT_WEAK {
return rt_heap + RT_HEAP_SIZE;
}
#endif
/**
* This function will initial your board.
*/
void rt_hw_board_init()
{
#if 0 // 修改
/* System Clock Update */
SystemCoreClockUpdate();
/* System Tick Configuration */
_SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
#endif // 修改
/* 初始化 SysTick */
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); // 修改
/* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INITrt_components_board_init();
#endif
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
PendSV_Handler,HardFault_Handler…重复定义错误 > 屏蔽即可, 推荐直接将stm32f10x_it.h
和stm32f10x_it.c
清空,如下!!!!
stm32f10x_it.c
/* 存放终端函数 */
"stm32f10x_it.h" #include
stm32f10x_it.h
#ifndef __STM32F10x_IT_H#define __STM32F10x_IT_H
"stm32f10x.h"
#include
#endif /* __STM32F10x_IT_H */