在网上有很多关于ucosii移植的资料,介绍也很详细。但是,按照他们方法自己去实践,往往会出现很多问题,却找不出来问题所在。以至于ucosii操作系统不能在自己的cpu上运行起来,甚是恼人,郁闷。我今天就教给大家一种有效方法,先让ucosii操作系统在你的cpu上跑起来,跑起来,你才有兴趣去专研它,我说的不错吧?反正我是这样,呵呵!!闲话不多说,开始我们移植工作,如下:
首先看一下我建立的工程( @version V3.0.0,)如下:
然后,再看一下我们移植需要修改到的文件有,如下:
具体修改如下:
(1)对startup_STM32f103x_hd.s的修改(这点一定要注意),修改的地方如下:
DCD __intial_sp
DCD __iar_program_start
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD OS_CPU_PendSVHandler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1 & ADC2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
DCD RTCAlARM_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
DCD TIM8_BRK_IRQHandler ; TIM8 Break
DCD TIM8_UP_IRQHandler ; TIM8 Update
DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation
DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare
DCD ADC3_IRQHandler ; ADC3
DCD FSMC_IRQHandler ; FSMC
DCD SDIO_IRQHandler ; SDIO
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_IRQHandler ; TIM6
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
(2)对os_cpu.h的修改如下:
(3)对os_cpu-a.asm的修改如下:
(6)对stm32f10x_it.c的修改如下:
在这里偷懒了,大家自己可以补齐(2)(3)(6),另外大家可以向我索要完整的工程,和我交流!!
(4)bsp.c 如下:
#include "stm32f10x.h"
#include "ucos_ii.h"
#include "bsp.h"
void GPIO_configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// 打开控制端口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
void BSP_init()
{
SystemInit();//系统时钟设置,72M
SysTick_Configuration();
}
void SysTick_Configuration(void)
{
if (SysTick_Config(72000000 / OS_TICKS_PER_SEC)) // Initialize the uC/OS-II tick interrupt
{
while (1);
}
//SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);//时钟源HCLK_Div8
//NVIC_SetPriority(SysTick_IRQn, 0x0);//SysTick中断优先级设置
}
(5)我们main.c:
#define OS_GLOBALS
#include "include.h"
#define APP_TASK_START_STK_SIZE 64 //堆栈总尺寸
#define APP_TASK_START_PRIO 5 //任务优先级
#define APP_TASK_START_ID APP_TASK_START_PRIO //任务ID
#define Task1_LED1_Stk_Size 64
#define Task2_LED2_Stk_Size 64
#define Task1_LED1_Prio 11 //任务1优先级
#define Task2_LED2_Prio 12 //任务2优先级
OS_STK APP_TaskStartStk[APP_TASK_START_STK_SIZE]; //任务堆栈
OS_STK Task1_LED1_Stk[Task1_LED1_Stk_Size]; //任务1堆栈
OS_STK Task2_LED2_Stk[Task2_LED2_Stk_Size]; //任务2堆栈
static void Task1_LED1(void *pdata);
static void Task2_LED2(void *pdata);
//==========================================================================================
static void APP_TaskStart(void *pdata)
{
pdata = pdata; //防止编译器警告
BSP_init(); //目标板初始化
//OS_CPU_SysTickInit();
#if OS_TASK_STAT_EN > 0
OSStatInit(); //统计任务初始化
#endif
//OSTaskSuspend(OS_PRIO_SELF);//开始任务自动挂起
while(1)
{
INT8U err;// 测试
OSTaskCreateExt(Task1_LED1,
(void *)0,
&Task1_LED1_Stk[Task1_LED1_Stk_Size - 1],
Task1_LED1_Prio,
Task1_LED1_Prio,
&Task1_LED1_Stk[0],
Task1_LED1_Stk_Size,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskNameSet(Task1_LED1_Prio, "Task1-LED1", &err);
OSTaskCreateExt(Task2_LED2,
(void *)0,
&Task2_LED2_Stk[Task2_LED2_Stk_Size - 1],
Task2_LED2_Prio,
Task2_LED2_Prio,
&Task2_LED2_Stk[0],
Task2_LED2_Stk_Size,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskNameSet(Task2_LED2_Prio, "Task2-LED2", &err);
OSTimeDly(OS_TICKS_PER_SEC); //系统延时函数
OSTaskSuspend(OS_PRIO_SELF); //开始任务自动挂起
}
}
//==========================================================================================
static void Task1_LED1(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOF, GPIO_Pin_6);
OSTimeDlyHMSM(0,0,0,200); //系统延时函数
GPIO_SetBits(GPIOF, GPIO_Pin_6);
OSTimeDlyHMSM(0,0,0,200); //系统延时函数
}
}
//==========================================================================================
static void Task2_LED2(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOF, GPIO_Pin_7); //系统延时函数
OSTimeDlyHMSM(0,0,2,0);
GPIO_SetBits(GPIOF, GPIO_Pin_7); //系统延时函数
OSTimeDlyHMSM(0,0,2,0);
}
}
//==========================================================================================
int main()
{
#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
INT8U err;
#endif
GPIO_configuration();
OSInit(); //初始化ucosii
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(OS_TASK_IDLE_PRIO, "uC/OS-II Idle", &err);//设置空闲任务名称
#endif
#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
OSTaskNameSet(OS_TASK_STAT_PRIO, "uC/OS-II Stat", &err); //设置统计任务名称
#endif
//用任务建立任务
OSTaskCreateExt(APP_TaskStart, //void (*task)(void *pd) 任务首地址
(void *)0, //void *pdata 数据指针
&APP_TaskStartStk[APP_TASK_START_STK_SIZE - 1], //OS_STK *ptos 指向任务堆栈栈顶的指针
(INT8U)APP_TASK_START_PRIO, //INT8U prio 任务优先级
(INT16U)APP_TASK_START_ID, //INT16U id 任务的ID号
&APP_TaskStartStk[0], //OS_STK *pbos 指向任务堆栈栈底的指针
(INT32U)APP_TASK_START_STK_SIZE, //INT32U stk_size 堆栈容量
(void *)0, //void *pnext 数据指针
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); //INT16U opt 设定OSTaskCreateExt的选项
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(APP_TASK_START_PRIO, "Task-Start", &err);
#endif
OSStart();
return (0);
//启动多任务管理
}
做完以上工作,ucosii一定可以在你cpu上跑起来,不然我想你负责,呵呵!!
如果想要完整工程,问我索要QQ:420055855 大量原创ucosii,ucgui工程等着你!!
|