stm32f103 标准库移植rt-thread nano

参考资料:RT-Thread 文档中心

环境:1、stm32f103开发板    2、keil     3、rt-thread nano pack

步骤:

1、添加rt-thread nano到keil工程,步骤参见 基于 Keil MDK 移植 RT-Thread Nano

2、stm32f10x_it.c文件下删除异常处理函数 HardFault_Handler() 和悬挂处理函数 PendSV_Handler(),这两个函数已由 RT-Thread 实现,所以需要删除工程里中断服务例程文件中的这两个函数,避免在编译时产生重复定义。

3、SysTick_Handler() 中断服务例程由用户在 board.c 中重新实现,stm32f10x_it.c文件下删除 SysTick_Handler() ,避免在编译时产生重复定义。

4、board.c文件下配置rt_hw_board_init函数,屏蔽掉 #error "TODO 1: OS Tick Configuration.",重新定义函数SysTick_Handler,添加系统时钟配置 SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);

void SysTick_Handler()
{
	 rt_interrupt_enter();
	  rt_tick_increase();
	  rt_interrupt_leave();
}


void rt_hw_board_init(void){
	
    /* 
     * TODO 1: OS Tick Configuration
     * Enable the hardware timer and call the rt_os_tick_callback function
     * periodically with the frequency RT_TICK_PER_SECOND. 
     */
   
		SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
		
    /* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
    rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}

5、board.c文件下 添加头文件#include "stm32f10x.h",main.c文件下添加头文件                #include

6、编写测试例程

void thread01_entry( void *parameter);
static rt_thread_t thread01 = RT_NULL;

int main(void)
{	
	 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
	 uart_init(115200);	 //串口初始化为115200
 	 LED_Init();			     //LED端口初始化
	
	 thread01 = rt_thread_create( "thread01",thread01_entry,RT_NULL,512,3,20);  
		
	 rt_thread_startup(thread01);
}

void thread01_entry( void *parameter)
{
	while(1)
	{
		LED0=!LED0;
		rt_thread_delay(2000);
	}
}


//void thread01_entry( void *parameter)
//{
//	u16 t;  
//	u16 len;	
//	u16 times=0;
//	while(1)
//	{
//		if(USART_RX_STA&0x8000)
//		{					   
//			len=USART_RX_STA&0x3fff;//得到此次接收到的数据长度
//			printf("\r\n您发送的消息为:\r\n\r\n");
//			for(t=0;t

你可能感兴趣的:(单片机调试,stm32,嵌入式硬件,单片机)