下面对μC/OSII移植到STM32F103的步骤进行总结。
选择stm32f103相关工程点击进行下载
将下载文件解压后的uCOS-II文件拷贝到裸机工程目录下
另外将Micrium\Software\EvalBoards\ST\STM32F103ZE-SK\IAR\OS-Probe-LCD下的os_cfg.h拷贝到工程文件下。
(1)将os_cpu_c.c的#include "app_cfg.h"注释
(2)将os_dbg.c的#define OS_COMPILER_OPT __root 改为#define OS_COMPILER_OPT
(3)修改启动文件startup_stm32f10x_hd.s
(4)修改UCOSII-Ports\os_cpu_a.asm文件
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : stm32f10x_systick.c
* Author : MCD Application Team
* Version : V2.0
* Date : 05/23/2008
* Description : This file provides all the SysTick firmware functions.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
* IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_systick.h"
#include "os_cpu.h"
#include "ucos_ii.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* ---------------------- SysTick registers bit mask -------------------- */
/* CTRL TICKINT Mask */
#define CTRL_TICKINT_Set ((u32)0x00000002)
#define CTRL_TICKINT_Reset ((u32)0xFFFFFFFD)
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : SysTick_CLKSourceConfig
* Description : Configures the SysTick clock source.
* Input : - SysTick_CLKSource: specifies the SysTick clock source.
* This parameter can be one of the following values:
* - SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8
* selected as SysTick clock source.
* - SysTick_CLKSource_HCLK: AHB clock selected as
* SysTick clock source.
* Output : None
* Return : None
* ¹¦ÄÜ : ÉèÖÃSysTickʱÖÓÔ´ £»
*******************************************************************************/
//void SysTick_CLKSourceConfig(u32 SysTick_CLKSource)
//{
// /* Check the parameters */
// assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
// if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
// {
// SysTick->CTRL |= SysTick_CLKSource_HCLK;
// }
// else
// {
// SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
// }
//}
/*******************************************************************************
* Function Name : SysTick_SetReload
* Description : Sets SysTick Reload value.
* Input : - Reload: SysTick Reload new value.
* This parameter must be a number between 1 and 0xFFFFFF.
* Output : None
* Return : None
* ¹¦ÄÜ : ÉèÖÃSysTickÖØ×°ÔØÖµ £»
*******************************************************************************/
void SysTick_SetReload(u32 Reload)
{
/* Check the parameters */
assert_param(IS_SYSTICK_RELOAD(Reload));
SysTick->LOAD = Reload;
}
/*******************************************************************************
* Function Name : SysTick_CounterCmd
* Description : Enables or disables the SysTick counter.
* Input : - SysTick_Counter: new state of the SysTick counter.
* This parameter can be one of the following values:
* - SysTick_Counter_Disable: Disable counter
* - SysTick_Counter_Enable: Enable counter
* - SysTick_Counter_Clear: Clear counter value to 0
* Output : None
* Return : None
* ¹¦ÄÜ : ʹÄÜ»òÕßʧÄÜSysTick¼ÆÊýÆ÷ £»
*******************************************************************************/
void SysTick_CounterCmd(u32 SysTick_Counter)
{
/* Check the parameters */
assert_param(IS_SYSTICK_COUNTER(SysTick_Counter));
if (SysTick_Counter == SysTick_Counter_Enable)
{
SysTick->CTRL |= SysTick_Counter_Enable;
}
else if (SysTick_Counter == SysTick_Counter_Disable)
{
SysTick->CTRL &= SysTick_Counter_Disable;
}
else /* SysTick_Counter == SysTick_Counter_Clear */
{
SysTick->VAL = SysTick_Counter_Clear;
}
}
/*******************************************************************************
* Function Name : SysTick_ITConfig
* Description : Enables or disables the SysTick Interrupt.
* Input : - NewState: new state of the SysTick Interrupt.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
* ¹¦ÄÜ : ʹÄÜ»òÕßʧÄÜSysTickÖÐ¶Ï £»
*******************************************************************************/
void SysTick_ITConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
SysTick->CTRL |= CTRL_TICKINT_Set;
}
else
{
SysTick->CTRL &= CTRL_TICKINT_Reset;
}
}
/*******************************************************************************
* Function Name : SysTick_GetCounter
* Description : Gets SysTick counter value.
* Input : None
* Output : None
* Return : SysTick current value
* ¹¦ÄÜ : »ñÈ¡SysTick¼ÆÊýÆ÷µÄÖµ £»
*******************************************************************************/
u32 SysTick_GetCounter(void)
{
return(SysTick->VAL);
}
/*******************************************************************************
* Function Name : SysTick_GetFlagStatus
* Description : Checks whether the specified SysTick flag is set or not.
* Input : - SysTick_FLAG: specifies the flag to check.
* This parameter can be one of the following values:
* - SysTick_FLAG_COUNT
* - SysTick_FLAG_SKEW
* - SysTick_FLAG_NOREF
* Output : None
* Return : None
* ¹¦ÄÜ : ¼ì²éÖ¸¶¨µÄSysTick±ê־λÉèÖÃÓë·ñ £»
*******************************************************************************/
FlagStatus SysTick_GetFlagStatus(u8 SysTick_FLAG)
{
u32 statusreg = 0, tmp = 0 ;
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_SYSTICK_FLAG(SysTick_FLAG));
/* Get the SysTick register index */
tmp = SysTick_FLAG >> 3;
if (tmp == 2) /* The flag to check is in CTRL register */
{
statusreg = SysTick->CTRL;
}
else /* The flag to check is in CALIB register */
{
statusreg = SysTick->CALIB;
}
if ((statusreg & ((u32)1 << SysTick_FLAG)) != (u32)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
void SysTickHandler(void)
{
//OSPendSV
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL(); //±£´æÈ«¾ÖÖжϱêÖ¾,¹Ø×ÜÖжÏ/* Tell uC/OS-II that we are starting an ISR*/
OSIntNesting++;
OS_EXIT_CRITICAL(); //»Ö¸´È«¾ÖÖжϱêÖ¾
OSTimeTick(); /* Call uC/OS-II's OSTimeTick(),ÔÚos_core.cÎļþÀﶨÒå,Ö÷ÒªÅжÏÑÓʱµÄÈÎÎñÊÇ·ñ¼Æʱµ½*/
OSIntExit(); //ÔÚos_core.cÎļþÀﶨÒå,Èç¹ûÓиü¸ßÓÅÏȼ¶µÄÈÎÎñ¾ÍÐ÷ÁË,ÔòÖ´ÐÐÒ»´ÎÈÎÎñÇл»
}
void OS_CPU_SysTickInit(void)
{
RCC_ClocksTypeDef rcc_clocks;
INT32U cnts;
RCC_GetClocksFreq(&rcc_clocks);
cnts = (INT32U)rcc_clocks.HCLK_Frequency/OS_TICKS_PER_SEC;
SysTick_SetReload(cnts);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
SysTick_CounterCmd(SysTick_Counter_Enable);
SysTick_ITConfig(ENABLE);
}
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
创建两个控制IO引脚定时变化的任务,结果运行正常。
int main()
{
OSInit();
OSTaskCreate((void (*) (void *))LE0_task, (void *) 0,(OS_STK *)&LD0stk[63], 3);
OSTaskCreate((void (*) (void *))LE1_task, (void *) 0,(OS_STK *)&LD1stk[63], 4);
OS_CPU_SysTickInit();
OSStart();
while(1)
{
}
}