uCos-III移植到STM32F10x

         最近在百度上看了uCOS-III 的介绍后,诸多功能有很大的提升和改进,感觉有必要升级一下开发环境。百度介绍:http://baike.baidu.com/view/8531313.htm

环境:

  1. STM32F10x 3.5固件库。
  2. MDK4.23 编译器
  3. uCos-III v3.03

         1. uCos-III 源文件KRN-K3XX-000000.zip

                   官网http://micrium.com/page/downloads/source_code  

         我的网盘:http://115.com/file/anr4r6a8#

2.uCos-III 官网 移植程序

         Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO.zip

官网http://micrium.com/download/Micrium-Book-uCOS-III-STM32F107.exe

网盘http://115.com/file/dpuyusej#

一、第一步新建工程(在上一篇文章中有详解)

二、新建文件夹uCOS_III。在此文件下新建四个文件夹uC-CPU,uC-LIB, uCOS-III。

1.uCOS-III下新建三个文件 Source, Ports, Cfg

复制KRN-K3XX-000000\Micrium\Software\uCOS-III\Source下所有文件到Source;

复制KRN-K3XX-000000\Micrium\Software\uCOS-III\Cfg\Template下所有文件到Cfg;

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uCOS-III\Ports\ARM-Cortex-M3\Generic\RealVie下所有文件到 Ports。

 

2. uC-LIB下新建三个文件 Source, Ports, Cfg

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB文本文件到Source

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB\Cfg\Template下 lib_cfg.h 到Cfg

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB\Ports\ARM-Cortex-M3\RealView 下lib_mem_a.asm 到Ports

 

3. uC-CPU下新建三个文件 Source, Ports,Cfg

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-CPU下三个文本文件到Source

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-CPU\ARM-Cortex-M3\GNU下三个文件到 Ports

复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\EvalBoards\Micrium\uC-Eval-STM32F107\Atollic\uCOS-III\APP下cpu_cfg.h 到Cfg

 

4.复制Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\EvalBoards\Micrium\uC-Eval-STM32F107\Atollic\uCOS-III\APP下app_cfg.h 到Main中。

 

好了, 到这里工程文件以复制完了。

1.把工程引用文件路径指定 参图:

2.添加工程文件:

 

Main.c, Kernel.c,Kernel.h,Config.c,Config.h代码如下提供。

Main.c
 1 #include "os.h"
 2 #include "Kernel.h"
 3 #include "Config.h"
 4 
 5 int main()
 6 {
 7     SystemConfigInit();    
 8     KeranlTask();
 9     
10     return 0;
11 }
Kernel.c
  1 /*-------------------------------------------------------------------------
  2 
  3                             软件主体
  4 
  5     
  6 -------------------------------------------------------------------------*/
  7 
  8 #include "os.h"
  9 #include "kernel.h"
 10 #include "config.h"
 11 
 12 extern void SysTickInit(void);
 13 
 14 static OS_TCB taskStartTCB;
 15 static CPU_STK startTaskStk[STARTUP_TASK_STK_SIZE];         //启动任务的程序空间
 16 
 17 static OS_TCB task1TCB;
 18 static CPU_STK task1_stk[TASK1_STK_SIZE];
 19 
 20 static OS_TCB task2TCB;
 21 static CPU_STK task2_stk[TASK2_STK_SIZE];
 22 
 23 static OS_TCB task3TCB;
 24 static CPU_STK task3_stk[TASK3_STK_SIZE];
 25 
 26 static volatile OS_SEM taskSem;
 27 static volatile OS_ERR err;
 28 
 29 /*******************************************************************************
 30 * Function Name :void StartTask(void)
 31 * Description   :启动任务
 32 * Input         :
 33 * Output        :
 34 * Other         :
 35 * Date          :2012.04.18  11:48:23
 36 *******************************************************************************/
 37 void StartTask(void)
 38 {
 39     
 40     led_init();
 41     SysTickInit();
 42     
 43     OSTaskCreate(    (OS_TCB     *)&task1TCB,
 44                     (CPU_CHAR     *)"task1",
 45                     (OS_TASK_PTR)task1,
 46                     (void         *)0,
 47                     (OS_PRIO     )TASK1_PRIO,
 48                     (CPU_STK    *)&task1_stk[0],
 49                     (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
 50                     (CPU_STK_SIZE)TASK1_STK_SIZE,
 51                     (OS_MSG_QTY    )0,
 52                     (OS_TICK    )0,
 53                     (void        *)0,
 54                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
 55                     (OS_ERR        *)&err);
 56     
 57     OSTaskCreate(    (OS_TCB     *)&task2TCB,
 58                     (CPU_CHAR     *)"task2",
 59                     (OS_TASK_PTR)task2,
 60                     (void         *)0,
 61                     (OS_PRIO    ) TASK2_PRIO,
 62                     (CPU_STK    *)&task2_stk[0],
 63                     (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
 64                     (CPU_STK_SIZE)TASK2_STK_SIZE,
 65                     (OS_MSG_QTY)0,
 66                     (OS_TICK    )0,
 67                     (void        *)0,
 68                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
 69                     (OS_ERR        *)&err);    
 70 
 71                     
 72     OSTaskCreate(    (OS_TCB     *)&task3TCB,
 73                     (CPU_CHAR     *)"task3",
 74                     (OS_TASK_PTR)task3,
 75                     (void         *)0,
 76                     (OS_PRIO    )TASK3_PRIO,
 77                     (CPU_STK    *)&task3_stk[0],
 78                     (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
 79                     (CPU_STK_SIZE)TASK3_STK_SIZE,
 80                     (OS_MSG_QTY)0,
 81                     (OS_TICK    )0,
 82                     (void        *)0,
 83                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
 84                     (OS_ERR        *)&err);
 85 
 86     OSSemCreate(    (OS_SEM     *)&taskSem, 
 87                     (CPU_CHAR     *)"taskSem", 
 88                     (OS_SEM_CTR)0, 
 89                     (OS_ERR     *)err);
 90     
 91     OSTaskDel(        (OS_TCB     *)&taskStartTCB, 
 92                     (OS_ERR     *)&err);
 93 }
 94 
 95 static void task1(void *p_arg)
 96 {
 97 
 98     while (1)
 99     {
100         led_on(LED_4);
101         OSTimeDly(    (OS_TICK    )200, 
102                     (OS_OPT        )OS_OPT_TIME_DLY, 
103                     (OS_ERR     *)&err);
104 
105         led_off(LED_4);
106         OSTimeDly(    (OS_TICK    )200, 
107                     (OS_OPT        )OS_OPT_TIME_DLY, 
108                     (OS_ERR     *)&err);
109 
110         OSSemPost(    (OS_SEM     *)&taskSem, 
111                     (OS_OPT        )OS_OPT_POST_ALL, 
112                     (OS_ERR     *)&err);
113 
114     }
115 }
116 
117 static void task2(void *p_arg)
118 {
119     while (1)
120     {
121         led_on(LED_5);
122         OSSemPend(    (OS_SEM     *)&taskSem, 
123                     (OS_TICK    )10000, 
124                     (OS_OPT        )OS_OPT_PEND_BLOCKING, 
125                     (CPU_TS         *)0, 
126                     (OS_ERR     *)&err);
127 
128         led_off(LED_5);
129         OSSemPend(    (OS_SEM     *)&taskSem, 
130                     (OS_TICK    )10000, 
131                     (OS_OPT        )OS_OPT_PEND_BLOCKING, 
132                     (CPU_TS         *)0, 
133                     (OS_ERR     *)&err);
134         
135     }
136 }
137 
138 static void task3(void *p_arg)
139 {
140     
141     while (1)
142     {
143         led_on(LED_3);
144         OSTimeDly(    (OS_TICK    )100, 
145                     (OS_OPT        )OS_OPT_TIME_DLY, 
146                     (OS_ERR     *)&err);
147 
148         led_off(LED_3);
149         OSTimeDly(    (OS_TICK    )100, 
150                     (OS_OPT        )OS_OPT_TIME_DLY, 
151                     (OS_ERR     *)&err);
152         
153     }
154 }
155 
156 
157 /*******************************************************************************
158 * Function Name :void KeranlTask(void)
159 * Description   :启动任务
160 * Input         :
161 * Output        :
162 * Other         :
163 * Date          :2012.04.18  11:05:47
164 *******************************************************************************/
165 void KeranlTask(void)
166 {    
167     CPU_Init();
168     OSInit((OS_ERR *)&err);    
169     
170     OSTaskCreate(    (OS_TCB     *)&taskStartTCB,
171                     (CPU_CHAR     *)"task_start",
172                     (OS_TASK_PTR)StartTask,
173                     (void         *)0,
174                     (OS_PRIO    ) STARTUP_TASK_PRIO,
175                     (CPU_STK    *)&startTaskStk[0],
176                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE / 10,
177                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE,
178                     (OS_MSG_QTY)0,
179                     (OS_TICK    )0,
180                     (void        *)0,
181                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
182                     (OS_ERR        *)&err);
183                     
184     OSStart((OS_ERR *)&err);
185 }
Kernel.h
 1 #ifndef _kernel_h_
 2 #define _kernel_h_
 3 
 4 #include "os.h"
 5 
 6 
 7 
 8 
 9 
10 
11 
12 static void task1(void *p_arg);
13 static void task2(void *p_arg);
14 static void task3(void *p_arg);
15 
16 void KeranlTask(void);
17 
18 
19 #endif
Config.c
  1 /*
  2 ********************************************************************************
  3 *                                  uC/OS-II
  4 *                            
  5 *                              ARM Cortex-M3 Port
  6 *
  7 * File          : Config.C
  8 * Version       : V1.0
  9 * By            : 王宏强
 10 *
 11 * For           : Stm32f10x
 12 * Mode          : Thumb2
 13 * Toolchain     : 
 14 *                     RealView Microcontroller Development Kit (MDK)
 15 *                     Keil uVision
 16 * Description   : STM32F10x 内部 系统的配置
 17 *
 18 *                    1,系统中断优先级模式设置
 19 *                    2,系统程序启动指定
 20 *                    3,系统时钟计时器配置
 21 *                    4,芯片引脚初始化
 22 *                    
 23 * Date          : 2012.05.22
 24 *******************************************************************************/
 25 
 26 #include "misc.h"
 27 #include "stm32f10x_gpio.h"
 28 #include "stm32f10x_flash.h"
 29 #include "stm32f10x_rcc.h"
 30 #include "stm32f10x_iwdg.h"
 31 #include "config.h"
 32 
 33 
 34 GPIO_InitTypeDef GPIO_InitStructure;
 35 /*******************************************************************************
 36 * Function Name  : GPIO_Configuration
 37 * Description    : Configures the different GPIO ports.
 38 * Input          : None
 39 * Output         : None
 40 * Return         : None
 41 *******************************************************************************/
 42 void GPIO_Configuration(void)
 43 {
 44 #ifdef USE_STM3210B_EVAL
 45     /* Enable the USART2 Pins Software Remapping */
 46     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
 47 #endif
 48 
 49     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
 50                      RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
 51                      RCC_APB2Periph_GPIOE, ENABLE);
 52 
 53     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
 54     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
 55     GPIO_Init(GPIOA, &GPIO_InitStructure);
 56     GPIO_Init(GPIOB, &GPIO_InitStructure);
 57     GPIO_Init(GPIOC, &GPIO_InitStructure);
 58     GPIO_Init(GPIOD, &GPIO_InitStructure);
 59     GPIO_Init(GPIOE, &GPIO_InitStructure);
 60 
 61     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
 62                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
 63                          RCC_APB2Periph_GPIOE, DISABLE);  
 64 
 65 }
 66 
 67 
 68 /*******************************************************************************
 69 * Function Name  : Delay
 70 * Description    : Inserts a delay time.
 71 * Input          : nCount: specifies the delay time length.
 72 * Output         : None
 73 * Return         : None
 74 *******************************************************************************/
 75 void Delay(volatile CPU_INT32U nCount)
 76 {
 77   for(; nCount != 0; nCount--);
 78 }
 79 
 80 /*******************************************************************************
 81 函 数 名:void IWDG_Init(void)
 82 功能描述:看门狗初始化                        
 83 入口参数:                            
 84 返回参数:
 85 创建时间: 2011.6.24
 86 ********************************************************************************/
 87 void IWDG_Init(void)
 88 {
 89 
 90     IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );
 91     IWDG_SetPrescaler( IWDG_Prescaler_64);    //最小
 92     IWDG_SetReload( 0x138);        //40KHz内部时钟 0.5s
 93     IWDG_WriteAccessCmd( IWDG_WriteAccess_Disable );
 94     IWDG_Enable();
 95     IWDG_ReloadCounter();
 96 }
 97 
 98 /*******************************************************************************
 99 * Function Name :void SysTickInit(void)
100 * Description   :系统定时器时间配置
101 * Input         :
102 * Output        :
103 * Other         :时基为1ms
104 * Date          :2011.11.03  12:59:13
105 *******************************************************************************/
106 void SysTickInit(void)
107 {
108     SysTick_Config(SystemCoreClock / 1000);            //uCOS时基1ms
109 }
110 /*******************************************************************************
111 * Function Name :void InterruptOrder(void)
112 * Description   :中断向量,优先级
113 * Input         :
114 * Output        :
115 * Other         :
116 * Date          :2011.10.27  11:50:05
117 *******************************************************************************/
118 void NVIC_Configuration(void)
119 {
120     NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );//优先级设置
121 }
122 
123 /*******************************************************************************
124 * Function Name :void SystemConfig(void)
125 * Description   :系统初始化
126 * Input         :
127 * Output        :
128 * Other         :
129 * Date          :2011.10.27  13:14:59
130 *******************************************************************************/
131 void SystemConfigInit(void)
132 {
133     NVIC_Configuration();    //中断优先级设置
134     GPIO_Configuration();    //端口初始化,所有端口关
135 }
136 
137 
138 
139 
140 void led_init(void)
141 {
142     GPIO_InitTypeDef GPIO_InitStructure;
143     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
144     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |  GPIO_Pin_12 | GPIO_Pin_13;
145     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
146     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
147     GPIO_Init(GPIOA, &GPIO_InitStructure);
148 
149     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
150     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
151     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
152     GPIO_Init(GPIOB, &GPIO_InitStructure);
153 }
154 
155 void led_on(CPU_INT32U n)
156 {
157     switch (n)
158     {
159         case LED_0:
160         GPIO_SetBits(GPIOD, GPIO_Pin_2);
161         break;
162         case LED_1:
163         GPIO_SetBits(GPIOD, GPIO_Pin_3);
164         break;
165         case LED_2:
166         GPIO_SetBits(GPIOD, GPIO_Pin_4);
167         break;
168         case LED_3:
169         GPIO_SetBits(GPIOB, GPIO_Pin_9);
170         break;
171         case LED_4:
172         GPIO_SetBits(GPIOA, GPIO_Pin_12);
173         break;
174         case LED_5:
175         GPIO_SetBits(GPIOA, GPIO_Pin_11);
176         break;
177         default:
178         break;
179     }
180 }
181 
182 
183 void led_off(CPU_INT32U n)
184 {
185     switch (n)
186     {
187         case LED_0:
188         GPIO_ResetBits(GPIOD, GPIO_Pin_2);
189         break;
190         case LED_1:
191         GPIO_ResetBits(GPIOD, GPIO_Pin_3);
192         break;
193         case LED_2:
194         GPIO_ResetBits(GPIOD, GPIO_Pin_4);
195         break;
196         case LED_3:
197         GPIO_ResetBits(GPIOB, GPIO_Pin_9);
198         break;
199         case LED_4:
200         GPIO_ResetBits(GPIOA, GPIO_Pin_12);
201         break;
202         case LED_5:
203         GPIO_ResetBits(GPIOA, GPIO_Pin_11);
204         break;
205         default:
206         break;
207     }
208 }
Config.h
 1 /****************************************Copyright (c)**************************************************
 2 ** Modified by:        王宏强
 3 ** Modified date:      2012-05-20 
 4 ** Version:            v3.0
 5 ** Descriptions:       修改用于STM32F10x   
 6 **
 7 **------------------------------------------------------------------------------------------------------
 8 ** Modified by:         
 9 ** Modified date:       
10 ** Version:            
11 ** Descriptions:        
12 **
13 ********************************************************************************************************/
14 #include "os.h" 
15 
16 
17 /********************************/
18 /*       系统配置函数           */
19 /********************************/
20 #define LED_0 0
21 #define LED_1 1
22 #define LED_2 2
23 #define LED_3 3
24 #define LED_4 4
25 #define LED_5 5
26 
27 
28 void Delay(volatile CPU_INT32U nCount);
29 void IWDG_Init(void);
30 void SysTickInit(void);
31 void SystemConfigInit(void);
32 void led_init(void);
33 void led_on(CPU_INT32U n);
34 void led_off(CPU_INT32U n);
35 
36 
37 
38 
39 
40 
41 
42 
43 /********************************************************************************************************
44 **                            End Of File
45 ********************************************************************************************************/

app_cfg.h 追加代码 后如下:

app_cfg.h
  1 /*
  2 *********************************************************************************************************
  3 *                                              EXAMPLE CODE
  4 *
  5 *                          (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
  6 *
  7 *               All rights reserved.  Protected by international copyright laws.
  8 *               Knowledge of the source code may NOT be used to develop a similar product.
  9 *               Please help us continue to provide the Embedded community with the finest
 10 *               software available.  Your honesty is greatly appreciated.
 11 *********************************************************************************************************
 12 */
 13 
 14 /*
 15 *********************************************************************************************************
 16 *
 17 *                                      APPLICATION CONFIGURATION
 18 *
 19 *                                     ST Microelectronics STM32
 20 *                                              on the
 21 *
 22 *                                     Micrium uC-Eval-STM32F107
 23 *                                        Evaluation Board
 24 *
 25 * Filename      : app_cfg.h
 26 * Version       : V1.00
 27 * Programmer(s) : FT
 28 *********************************************************************************************************
 29 */
 30 
 31 #ifndef  APP_CFG_MODULE_PRESENT
 32 #define  APP_CFG_MODULE_PRESENT
 33 
 34 
 35 /*
 36 *********************************************************************************************************
 37 *                                       MODULE ENABLE / DISABLE
 38 *********************************************************************************************************
 39 */
 40 
 41 #define  APP_CFG_FS_EN                          DEF_DISABLED
 42 #define  APP_CFG_USB_DEV_EN                     DEF_DISABLED
 43 #define  APP_CFG_USB_OTG_EN                     DEF_DISABLED
 44 #define  APP_CFG_USB_HOST_EN                    DEF_DISABLED
 45 
 46 
 47 /*
 48 *********************************************************************************************************
 49 *                                              TASKS NAMES
 50 *********************************************************************************************************
 51 */
 52 
 53 
 54 
 55 /*
 56 *********************************************************************************************************
 57 *                                            TASK PRIORITIES
 58 *********************************************************************************************************
 59 */
 60 
 61 #define  APP_TASK_START_PRIO                               2
 62 
 63 /*
 64 *********************************************************************************************************
 65 *                                            TASK STACK SIZES
 66 *                             Size of the task stacks (# of OS_STK entries)
 67 *********************************************************************************************************
 68 */
 69 
 70 #define  APP_TASK_START_STK_SIZE                         512
 71 
 72 /*
 73 *********************************************************************************************************
 74 *                                        uC/LIB CONFIGURATION
 75 *********************************************************************************************************
 76 */
 77 
 78 #define  LIB_MEM_CFG_OPTIMIZE_ASM_EN            DEF_ENABLED
 79 #define  LIB_MEM_CFG_ARG_CHK_EXT_EN             DEF_ENABLED
 80 #define  LIB_MEM_CFG_ALLOC_EN                   DEF_ENABLED
 81 #define  LIB_MEM_CFG_POOL_NBR                             10
 82 #define  LIB_MEM_CFG_HEAP_SIZE                   (2 * 1024L)
 83 
 84 /*
 85 *********************************************************************************************************
 86 *                                       BSP CONFIGURATION
 87 *********************************************************************************************************
 88 */
 89 
 90 #define  BSP_CFG_SER_COMM_SEL                   BSP_SER_COMM_UART_02
 91 
 92 
 93 /*
 94 *********************************************************************************************************
 95 *                                     TRACE / DEBUG CONFIGURATION
 96 *********************************************************************************************************
 97 */
 98 
 99 #define  TRACE_LEVEL_OFF                                   0
100 #define  TRACE_LEVEL_INFO                                  1
101 #define  TRACE_LEVEL_DBG                                   2
102 
103 #define  APP_TRACE_LEVEL                        TRACE_LEVEL_DBG
104 #define  APP_TRACE                              BSP_Ser_Printf
105 
106 #include  <cpu.h>
107 void  BSP_Ser_Printf   (CPU_CHAR *format, ...);
108 
109 #define  FS_TRACE_LEVEL                         TRACE_LEVEL_DBG
110 #define  FS_TRACE                               BSP_Ser_Printf
111 
112 #define  APP_TRACE_INFO(x)                      ((APP_TRACE_LEVEL >= TRACE_LEVEL_INFO) ? (void)(APP_TRACE x) : (void)0)
113 #define  APP_TRACE_DBG(x)                       ((APP_TRACE_LEVEL >= TRACE_LEVEL_DBG ) ? (void)(APP_TRACE x) : (void)0)
114 
115 
116 
117 
118 /* task priority */
119 #define STARTUP_TASK_PRIO 4
120 //#define TASK_MODBUS_PRIO 5
121 //#define TASK_SI4432_PRIO 6
122 
123 #define TASK1_PRIO 10
124 #define TASK2_PRIO 13
125 #define TASK3_PRIO 14
126 
127 
128 /* task stack size */
129 #define STARTUP_TASK_STK_SIZE 100
130 #define TASK_MODBUS_SIZE 80
131 #define TASK1_STK_SIZE 80
132 #define TASK2_STK_SIZE 80
133 #define TASK3_STK_SIZE 80
134 //#define TASK_SI432_SIZE 80
135 
136 
137 
138 
139 #endif

 

 

下面对Project\App\uCOS_III\uC-CPU\Ports 下cpu_a.s进行修改, 因为这是GNU的汇编代码。

如下替换:

‘@’ 换为‘;’

.global  换为EXPORT

以下代码

.text

.align 2

.thumb

.syntax unified

换为

 

         PRESERVE8

         AREA        |.text|, CODE, READONLY

                   THUMB

把函数名上的.thumb_func  在前后添加 ‘;’注释掉;

并把函数 名后紧跟的‘:’删除。

修改后如下:

cpu_a.s
;********************************************************************************************************
;                                                uC/CPU
;                                    CPU CONFIGURATION & PORT LAYER
;
;                          (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
;
;               All rights reserved.  Protected by international copyright laws.
;
;               uC/CPU is provided in source form to registered licensees ONLY.  It is 
;               illegal to distribute this source code to any third party unless you receive 
;               written permission by an authorized Micrium representative.  Knowledge of 
;               the source code may NOT be used to develop a similar product.
;
;               Please help us continue to provide the Embedded community with the finest 
;               software available.  Your honesty is greatly appreciated.
;
;               You can contact us at www.micrium.com.
;********************************************************************************************************


;********************************************************************************************************
;
;                                            CPU PORT FILE
;
;                                            ARM-Cortex-M3
;                                            GNU C Compiler
;
; Filename      : cpu_a.s
; Version       : V1.29.00.00
; Programmer(s) : JJL
;********************************************************************************************************


;********************************************************************************************************
;                                           PUBLIC FUNCTIONS
;********************************************************************************************************

    EXPORT  CPU_IntDis
    EXPORT  CPU_IntEn

    EXPORT  CPU_SR_Save
    EXPORT  CPU_SR_Restore

    EXPORT  CPU_WaitForInt
    EXPORT  CPU_WaitForExcept


    EXPORT  CPU_CntLeadZeros
    EXPORT  CPU_CntTrailZeros
    EXPORT  CPU_RevBits


;********************************************************************************************************
;                                      CODE GENERATION DIRECTIVES
;********************************************************************************************************

    PRESERVE8
    AREA    |.text|, CODE, READONLY
    THUMB


;$PAGE
;********************************************************************************************************
;                                    DISABLE and ENABLE INTERRUPTS
;
; Description : Disable/Enable interrupts.
;
; Prototypes  : void  CPU_IntDis(void);
;               void  CPU_IntEn (void);
;********************************************************************************************************

;.thumb_func
CPU_IntDis
        CPSID   I
        BX      LR

;.thumb_func
CPU_IntEn
        CPSIE   I
        BX      LR


;********************************************************************************************************
;                                      CRITICAL SECTION FUNCTIONS
;
; Description : Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking, the
;               state of the interrupt disable flag is stored in the local variable 'cpu_sr' & interrupts
;               are then disabled ('cpu_sr' is allocated in all functions that need to disable interrupts).
;               The previous interrupt state is restored by copying 'cpu_sr' into the CPU's status register.
;
; Prototypes  : CPU_SR  CPU_SR_Save   (void);
;               void    CPU_SR_Restore(CPU_SR cpu_sr);
;
; Note(s)     : (1) These functions are used in general like this :
;
;                       void  Task (void  *p_arg)
;                       {
;                           CPU_SR_ALLOC();                     /* Allocate storage for CPU status register */
;                               :
;                               :
;                           CPU_CRITICAL_ENTER();               /* cpu_sr = CPU_SR_Save();                  */
;                               :
;                               :
;                           CPU_CRITICAL_EXIT();                /* CPU_SR_Restore(cpu_sr);                  */
;                               :
;                       }
;********************************************************************************************************

;.thumb_func
CPU_SR_Save
        MRS     R0, PRIMASK                     ; Set prio int mask to mask all (except faults)
        CPSID   I 
        BX      LR

;.thumb_func
CPU_SR_Restore                                 ; See Note #2.
        MSR     PRIMASK, R0
        BX      LR


;$PAGE
;********************************************************************************************************
;                                         WAIT FOR INTERRUPT
;
; Description : Enters sleep state, which will be exited when an interrupt is received.
;
; Prototypes  : void  CPU_WaitForInt (void)
;
; Argument(s) : none.
;********************************************************************************************************

;.thumb_func
CPU_WaitForInt
        WFI                                     ; Wait for interrupt
        BX      LR


;********************************************************************************************************
;                                         WAIT FOR EXCEPTION
;
; Description : Enters sleep state, which will be exited when an exception is received.
;
; Prototypes  : void  CPU_WaitForExcept (void)
;
; Argument(s) : none.
;********************************************************************************************************

;.thumb_func
CPU_WaitForExcept
        WFE                                     ; Wait for exception
        BX      LR


;$PAGE
;********************************************************************************************************
;                                         CPU_CntLeadZeros()
;                                        COUNT LEADING ZEROS
;
; Description : Counts the number of contiguous, most-significant, leading zero bits before the 
;                   first binary one bit in a data value.
;
; Prototype   : CPU_DATA  CPU_CntLeadZeros(CPU_DATA  val);
;
; Argument(s) : val         Data value to count leading zero bits.
;
; Return(s)   : Number of contiguous, most-significant, leading zero bits in 'val'.
;
; Caller(s)   : Application.
;
;               This function is an INTERNAL CPU module function but MAY be called by application 
;               function(s).
;
; Note(s)     : (1) (a) Supports 32-bit data value size as configured by 'CPU_DATA' (see 'cpu.h  
;                       CPU WORD CONFIGURATION  Note #1').
;
;                   (b) For 32-bit values :
;
;                             b31  b30  b29  ...  b04  b03  b02  b01  b00    # Leading Zeros
;                             ---  ---  ---       ---  ---  ---  ---  ---    ---------------
;                              1    x    x         x    x    x    x    x            0
;                              0    1    x         x    x    x    x    x            1
;                              0    0    1         x    x    x    x    x            2
;                              :    :    :         :    :    :    :    :            :
;                              :    :    :         :    :    :    :    :            :
;                              0    0    0         1    x    x    x    x           27
;                              0    0    0         0    1    x    x    x           28
;                              0    0    0         0    0    1    x    x           29
;                              0    0    0         0    0    0    1    x           30
;                              0    0    0         0    0    0    0    1           31
;                              0    0    0         0    0    0    0    0           32
;
;
;               (2) MUST be defined in 'cpu_a.asm' (or 'cpu_c.c') if CPU_CFG_LEAD_ZEROS_ASM_PRESENT is 
;                   #define'd in 'cpu_cfg.h' or 'cpu.h'.
;********************************************************************************************************

;.thumb_func
CPU_CntLeadZeros
        CLZ     R0, R0                          ; Count leading zeros
        BX      LR


;$PAGE
;********************************************************************************************************
;                                         CPU_CntTrailZeros()
;                                        COUNT TRAILING ZEROS
;
; Description : Counts the number of contiguous, least-significant, trailing zero bits before the 
;                   first binary one bit in a data value.
;
; Prototype   : CPU_DATA  CPU_CntTrailZeros(CPU_DATA  val);
;
; Argument(s) : val         Data value to count trailing zero bits.
;
; Return(s)   : Number of contiguous, least-significant, trailing zero bits in 'val'.
;
; Caller(s)   : Application.
;
;               This function is an INTERNAL CPU module function but MAY be called by application 
;               function(s).
;
; Note(s)     : (1) (a) Supports 32-bit data value size as configured by 'CPU_DATA' (see 'cpu.h  
;                       CPU WORD CONFIGURATION  Note #1').
;
;                   (b) For 32-bit values :
;
;                             b31  b30  b29  b28  b27  ...  b02  b01  b00    # Trailing Zeros
;                             ---  ---  ---  ---  ---       ---  ---  ---    ----------------
;                              x    x    x    x    x         x    x    1            0
;                              x    x    x    x    x         x    1    0            1
;                              x    x    x    x    x         1    0    0            2
;                              :    :    :    :    :         :    :    :            :
;                              :    :    :    :    :         :    :    :            :
;                              x    x    x    x    1         0    0    0           27
;                              x    x    x    1    0         0    0    0           28
;                              x    x    1    0    0         0    0    0           29
;                              x    1    0    0    0         0    0    0           30
;                              1    0    0    0    0         0    0    0           31
;                              0    0    0    0    0         0    0    0           32
;
;
;               (2) MUST be defined in 'cpu_a.asm' (or 'cpu_c.c') if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT is 
;                   #define'd in 'cpu_cfg.h' or 'cpu.h'.
;********************************************************************************************************

;.thumb_func
CPU_CntTrailZeros
        RBIT    R0, R0                          ; Reverse bits
        CLZ     R0, R0                          ; Count leading zeros
        BX      LR


;$PAGE
;********************************************************************************************************
;                                            CPU_RevBits()
;                                            REVERSE BITS
;
; Description : Reverses the bits in a data value.
;
; Prototypes  : CPU_DATA  CPU_RevBits(CPU_DATA  val);
;
; Argument(s) : val         Data value to reverse bits.
;
; Return(s)   : Value with all bits in 'val' reversed (see Note #1).
;
; Caller(s)   : Application.
;
;               This function is an INTERNAL CPU module function but MAY be called by application function(s).
;
; Note(s)     : (1) The final, reversed data value for 'val' is such that :
;
;                       'val's final bit  0       =  'val's original bit  N
;                       'val's final bit  1       =  'val's original bit (N - 1)
;                       'val's final bit  2       =  'val's original bit (N - 2)
;
;                               ...                           ...
;
;                       'val's final bit (N - 2)  =  'val's original bit  2
;                       'val's final bit (N - 1)  =  'val's original bit  1
;                       'val's final bit  N       =  'val's original bit  0
;********************************************************************************************************

;.thumb_func
CPU_RevBits
        RBIT    R0, R0                          ; Reverse bits
        BX      LR


;$PAGE
;********************************************************************************************************
;                                     CPU ASSEMBLY PORT FILE END
;********************************************************************************************************

    END

修改os_cfg.h

OS_CFG_TS_EN宏定义改为0u

OS_CFG_SCHED_LOCK_TIME_MEAS_EN 宏定义改为0u

OS_CFG_TASK_DEL_EN 宏定义改为 1u

其它可根据自己的功能需要 先1u或ou。

 

 

这里Project\App\uCOS_III\uC-LIB\Source中lib_str.c的Str_FmtNbr_Int32 函数 的函数体内局部变量没有赋初值,不够严谨 这里赋初值如下:

    CPU_CHAR     *pstr_fmt = (CPU_CHAR *)0;
    CPU_DATA      i = 0u;
    CPU_INT32U    nbr_fmt = 0u;
    CPU_INT32U    nbr_log = 0u;
    CPU_INT08U    nbr_dig_max = 0u;
    CPU_INT08U    nbr_dig_min = 0u;
    CPU_INT08U    nbr_dig_fmtd = 0u;
    CPU_INT08U    nbr_neg_sign = 0u;
    CPU_INT08U    nbr_lead_char = 0u;
    CPU_INT08U    dig_val = 0u;
    CPU_INT08U    lead_char_delta_0 = 0u;
    CPU_INT08U    lead_char_delta_a = 0u;
    CPU_BOOLEAN   lead_char_dig = 0u;
    CPU_BOOLEAN   lead_char_0 = 0u;
    CPU_BOOLEAN   fmt_invalid = 0u;
    CPU_BOOLEAN   print_char = 0u;
    CPU_BOOLEAN   nbr_neg_fmtd = 0u;

 

 

最后修改启动文件startup_stm32f10x_hd.s ,加载不同的启动文件 时不用怕,修改的内容都是一样的:

OS_CPU_PendSVHandler 替换所有的PendSV_Handler

OS_CPU_SysTickHandler替换所有的SysTick_Handler

使中断执行uCos的中断函数。

 

到这里就全部OK了。

 

仿真查看端口变化

 

编程结果过于臃肿:

 

开启3级优化:

再编译看结果:

 

整个工程文件存到我的网盘中http://pan.baidu.com/share/link?shareid=25418&uk=118334538

希望以上资料对大家有所帮助。

posted @ 2012-06-13 01:26  Hiker天下  阅读(24764)  评论(18编辑  收藏  举报