专注电子技术学习与研究
当前位置:单片机教程网 >> STM32 >> 浏览文章

ucos ii 移植到stm32f103ze上

作者:佚名   来源:转自追风空间   点击数:  更新时间:2014年08月29日   【字体:

采用别人移植好的代码。即所需函数已写好。

准备工作:
1、ucos ii源码
2、stm32库
步骤:
1、建工程。
工程目录为:
2、配置ucos ii
在os_cfg.h中配置相关功能
3、修改相关函数
ucos ii需要一个定时器,在stm32中采用systick定时器,因此需要配置systick定时器
void SysTick_Configuration(void)
{
//关计数
    SysTick_CounterCmd(SysTick_Counter_Disable); 
    //关中断
    SysTick_ITConfig(DISABLE);
//配置SysTick的时钟源  此时为AHB时钟
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
//配置指系统句柄的优先级(Systick句柄  3号抢占优先级,0号子优先级)
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0);
//设置重载值1ms中断 HCLK=8M时
SysTick_SetReload(800000);  
//使能Systick中断
SysTick_ITConfig(ENABLE);
    //使能Systick计数即启动计数
SysTick_CounterCmd(SysTick_Counter_Enable);
}
需要systick定时器中断,在中断里面调用ucos的相关函数,以此来作为ucos的时钟。
void SysTickHandler(void)
{
OS_CPU_SR  cpu_sr;
// OS_ENTER_CRITICAL();  //保存全局中断标志,关总中断
//   OSIntNesting++;
//   OS_EXIT_CRITICAL();  //恢复全局中断标志
OSIntEnter();
OSTimeTick();
OSIntExit();        
}
 
配置pendsv函数
ucos通过pendsv来实现任务调试,因此需要在启动代码中更改pendsv
将原来的PendSV改为
OSPendSV
否则,系统会卡在
OSStartHang
    B       OSStartHang                                         ; Should never get here
处。
4、includes.h的编写
 
 
#ifndef  __INCLUDES_H__
#define  __INCLUDES_H__
 
#define   DEF_FALSE 0
#define   DEF_TRUE  1
 
#include    "ucos_ii.h"
#include "os_cpu.h"
#include "bsp.h"
#include    "app.h"
#include    "app_cfg.h"
 
#include    "stm32f10x_conf.h"
#include    
 
 
 
#if (uC_PROBE_OS_PLUGIN > 0)
#include    
#endif
 
#if (uC_PROBE_COM_MODULE > 0)
#include    
 
#if (PROBE_COM_METHOD_RS232 > 0)
#include    
#endif
#endif
 
 
 
#endif
 
5、bsp函数配置
stm32的相关硬件配置包括RCC、systick、NVIC、等,需要注意的是,systick定时器必须在OS启动后才能启动,否则,系统会崩溃。(这里有疑问,在OSStart执行前使能systick中断,系统 还是能运行)
6、编写相关任务函数。
 
 
总结,在移植UCOS时,需要编写的函数文件有includes.h、os_cpu.c、os_cpu_a.asm、os_cpu.h、需要配置的文件有os_cgf.h、中断和启动代码。
关闭窗口