[应用相关] uCos-III移植到STM32F10x

[复制链接]
954|14
 楼主| internally 发表于 2019-6-18 09:16 | 显示全部楼层 |阅读模式
最近在百度上看了uCOS-III 的介绍后,诸多功能有很大的提升和改进,感觉有必要升级一下开发环境。百度介绍:http://baike.baidu.com/view/8531313.htm
环境:
  • STM32F10x 3.5固件库。
  • MDK4.23 编译器
  • 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。
2012061301024157.jpg
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.把工程引用文件路径指定 参图:
2012061301044346.jpg
2.添加工程文件:
2012061301081711.jpg
2012061301065411.jpg

2012061301075433.jpg
2012061301083612.jpg
2012061301085118.jpg

 楼主| internally 发表于 2019-6-18 09:19 | 显示全部楼层
Main.c, Kernel.c,Kernel.h,Config.c,Config.h代码如下提供。

  1. Main.c
  2. #include "os.h"
  3. #include "Kernel.h"
  4. #include "Config.h"

  5. int main()
  6. {
  7.     SystemConfigInit();   
  8.     KeranlTask();
  9.    
  10.     return 0;
  11. }

  1. Kernel.c
  2. /*-------------------------------------------------------------------------

  3.                             软件主体

  4.    
  5. -------------------------------------------------------------------------*/

  6. #include "os.h"
  7. #include "kernel.h"
  8. #include "config.h"

  9. extern void SysTickInit(void);

  10. static OS_TCB taskStartTCB;
  11. static CPU_STK startTaskStk[STARTUP_TASK_STK_SIZE];         //启动任务的程序空间

  12. static OS_TCB task1TCB;
  13. static CPU_STK task1_stk[TASK1_STK_SIZE];

  14. static OS_TCB task2TCB;
  15. static CPU_STK task2_stk[TASK2_STK_SIZE];

  16. static OS_TCB task3TCB;
  17. static CPU_STK task3_stk[TASK3_STK_SIZE];

  18. static volatile OS_SEM taskSem;
  19. static volatile OS_ERR err;

  20. /*******************************************************************************
  21. * Function Name :void StartTask(void)
  22. * Description   :启动任务
  23. * Input         :
  24. * Output        :
  25. * Other         :
  26. * Date          :2012.04.18  11:48:23
  27. *******************************************************************************/
  28. void StartTask(void)
  29. {
  30.    
  31.     led_init();
  32.     SysTickInit();
  33.    
  34.     OSTaskCreate(    (OS_TCB     *)&task1TCB,
  35.                     (CPU_CHAR     *)"task1",
  36.                     (OS_TASK_PTR)task1,
  37.                     (void         *)0,
  38.                     (OS_PRIO     )TASK1_PRIO,
  39.                     (CPU_STK    *)&task1_stk[0],
  40.                     (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
  41.                     (CPU_STK_SIZE)TASK1_STK_SIZE,
  42.                     (OS_MSG_QTY    )0,
  43.                     (OS_TICK    )0,
  44.                     (void        *)0,
  45.                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  46.                     (OS_ERR        *)&err);
  47.    
  48.     OSTaskCreate(    (OS_TCB     *)&task2TCB,
  49.                     (CPU_CHAR     *)"task2",
  50.                     (OS_TASK_PTR)task2,
  51.                     (void         *)0,
  52.                     (OS_PRIO    ) TASK2_PRIO,
  53.                     (CPU_STK    *)&task2_stk[0],
  54.                     (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
  55.                     (CPU_STK_SIZE)TASK2_STK_SIZE,
  56.                     (OS_MSG_QTY)0,
  57.                     (OS_TICK    )0,
  58.                     (void        *)0,
  59.                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  60.                     (OS_ERR        *)&err);   

  61.                     
  62.     OSTaskCreate(    (OS_TCB     *)&task3TCB,
  63.                     (CPU_CHAR     *)"task3",
  64.                     (OS_TASK_PTR)task3,
  65.                     (void         *)0,
  66.                     (OS_PRIO    )TASK3_PRIO,
  67.                     (CPU_STK    *)&task3_stk[0],
  68.                     (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
  69.                     (CPU_STK_SIZE)TASK3_STK_SIZE,
  70.                     (OS_MSG_QTY)0,
  71.                     (OS_TICK    )0,
  72.                     (void        *)0,
  73.                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  74.                     (OS_ERR        *)&err);

  75.     OSSemCreate(    (OS_SEM     *)&taskSem,
  76.                     (CPU_CHAR     *)"taskSem",
  77.                     (OS_SEM_CTR)0,
  78.                     (OS_ERR     *)err);
  79.    
  80.     OSTaskDel(        (OS_TCB     *)&taskStartTCB,
  81.                     (OS_ERR     *)&err);
  82. }

  83. static void task1(void *p_arg)
  84. {

  85.     while (1)
  86.     {
  87.         led_on(LED_4);
  88.         OSTimeDly(    (OS_TICK    )200,
  89.                     (OS_OPT        )OS_OPT_TIME_DLY,
  90.                     (OS_ERR     *)&err);

  91.         led_off(LED_4);
  92.         OSTimeDly(    (OS_TICK    )200,
  93.                     (OS_OPT        )OS_OPT_TIME_DLY,
  94.                     (OS_ERR     *)&err);

  95.         OSSemPost(    (OS_SEM     *)&taskSem,
  96.                     (OS_OPT        )OS_OPT_POST_ALL,
  97.                     (OS_ERR     *)&err);

  98.     }
  99. }

  100. static void task2(void *p_arg)
  101. {
  102.     while (1)
  103.     {
  104.         led_on(LED_5);
  105.         OSSemPend(    (OS_SEM     *)&taskSem,
  106.                     (OS_TICK    )10000,
  107.                     (OS_OPT        )OS_OPT_PEND_BLOCKING,
  108.                     (CPU_TS         *)0,
  109.                     (OS_ERR     *)&err);

  110.         led_off(LED_5);
  111.         OSSemPend(    (OS_SEM     *)&taskSem,
  112.                     (OS_TICK    )10000,
  113.                     (OS_OPT        )OS_OPT_PEND_BLOCKING,
  114.                     (CPU_TS         *)0,
  115.                     (OS_ERR     *)&err);
  116.         
  117.     }
  118. }

  119. static void task3(void *p_arg)
  120. {
  121.    
  122.     while (1)
  123.     {
  124.         led_on(LED_3);
  125.         OSTimeDly(    (OS_TICK    )100,
  126.                     (OS_OPT        )OS_OPT_TIME_DLY,
  127.                     (OS_ERR     *)&err);

  128.         led_off(LED_3);
  129.         OSTimeDly(    (OS_TICK    )100,
  130.                     (OS_OPT        )OS_OPT_TIME_DLY,
  131.                     (OS_ERR     *)&err);
  132.         
  133.     }
  134. }


  135. /*******************************************************************************
  136. * Function Name :void KeranlTask(void)
  137. * Description   :启动任务
  138. * Input         :
  139. * Output        :
  140. * Other         :
  141. * Date          :2012.04.18  11:05:47
  142. *******************************************************************************/
  143. void KeranlTask(void)
  144. {   
  145.     CPU_Init();
  146.     OSInit((OS_ERR *)&err);   
  147.    
  148.     OSTaskCreate(    (OS_TCB     *)&taskStartTCB,
  149.                     (CPU_CHAR     *)"task_start",
  150.                     (OS_TASK_PTR)StartTask,
  151.                     (void         *)0,
  152.                     (OS_PRIO    ) STARTUP_TASK_PRIO,
  153.                     (CPU_STK    *)&startTaskStk[0],
  154.                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE / 10,
  155.                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE,
  156.                     (OS_MSG_QTY)0,
  157.                     (OS_TICK    )0,
  158.                     (void        *)0,
  159.                     (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  160.                     (OS_ERR        *)&err);
  161.                     
  162.     OSStart((OS_ERR *)&err);
  163. }

  1. Kernel.h
  2. #ifndef _kernel_h_
  3. #define _kernel_h_

  4. #include "os.h"







  5. static void task1(void *p_arg);
  6. static void task2(void *p_arg);
  7. static void task3(void *p_arg);

  8. void KeranlTask(void);


  9. #endif
  1. Config.c
  2. /*
  3. ********************************************************************************
  4. *                                  uC/OS-II
  5. *                           
  6. *                              ARM Cortex-M3 Port
  7. *
  8. * File          : Config.C
  9. * Version       : V1.0
  10. * By            : 王宏强
  11. *
  12. * For           : Stm32f10x
  13. * Mode          : Thumb2
  14. * Toolchain     :
  15. *                     RealView Microcontroller Development Kit (MDK)
  16. *                     Keil uVision
  17. * Description   : STM32F10x 内部 系统的配置
  18. *
  19. *                    1,系统中断优先级模式设置
  20. *                    2,系统程序启动指定
  21. *                    3,系统时钟计时器配置
  22. *                    4,芯片引脚初始化
  23. *                    
  24. * Date          : 2012.05.22
  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. GPIO_InitTypeDef GPIO_InitStructure;
  33. /*******************************************************************************
  34. * Function Name  : GPIO_Configuration
  35. * Description    : Configures the different GPIO ports.
  36. * Input          : None
  37. * Output         : None
  38. * Return         : None
  39. *******************************************************************************/
  40. void GPIO_Configuration(void)
  41. {
  42. #ifdef USE_STM3210B_EVAL
  43.     /* Enable the USART2 Pins Software Remapping */
  44.     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
  45. #endif

  46.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  47.                      RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  48.                      RCC_APB2Periph_GPIOE, ENABLE);

  49.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  50.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  51.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  52.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  53.     GPIO_Init(GPIOC, &GPIO_InitStructure);
  54.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  55.     GPIO_Init(GPIOE, &GPIO_InitStructure);

  56.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  57.                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  58.                          RCC_APB2Periph_GPIOE, DISABLE);  

  59. }


  60. /*******************************************************************************
  61. * Function Name  : Delay
  62. * Description    : Inserts a delay time.
  63. * Input          : nCount: specifies the delay time length.
  64. * Output         : None
  65. * Return         : None
  66. *******************************************************************************/
  67. void Delay(volatile CPU_INT32U nCount)
  68. {
  69.   for(; nCount != 0; nCount--);
  70. }

  71. /*******************************************************************************
  72. 函 数 名:void IWDG_Init(void)
  73. 功能描述:看门狗初始化                        
  74. 入口参数:                           
  75. 返回参数:
  76. 创建时间: 2011.6.24
  77. ********************************************************************************/
  78. void IWDG_Init(void)
  79. {

  80.     IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );
  81.     IWDG_SetPrescaler( IWDG_Prescaler_64);    //最小
  82.     IWDG_SetReload( 0x138);        //40KHz内部时钟 0.5s
  83.     IWDG_WriteAccessCmd( IWDG_WriteAccess_Disable );
  84.     IWDG_Enable();
  85.     IWDG_ReloadCounter();
  86. }

  87. /*******************************************************************************
  88. * Function Name :void SysTickInit(void)
  89. * Description   :系统定时器时间配置
  90. * Input         :
  91. * Output        :
  92. * Other         :时基为1ms
  93. * Date          :2011.11.03  12:59:13
  94. *******************************************************************************/
  95. void SysTickInit(void)
  96. {
  97.     SysTick_Config(SystemCoreClock / 1000);            //uCOS时基1ms
  98. }
  99. /*******************************************************************************
  100. * Function Name :void InterruptOrder(void)
  101. * Description   :中断向量,优先级
  102. * Input         :
  103. * Output        :
  104. * Other         :
  105. * Date          :2011.10.27  11:50:05
  106. *******************************************************************************/
  107. void NVIC_Configuration(void)
  108. {
  109.     NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );//优先级设置
  110. }

  111. /*******************************************************************************
  112. * Function Name :void SystemConfig(void)
  113. * Description   :系统初始化
  114. * Input         :
  115. * Output        :
  116. * Other         :
  117. * Date          :2011.10.27  13:14:59
  118. *******************************************************************************/
  119. void SystemConfigInit(void)
  120. {
  121.     NVIC_Configuration();    //中断优先级设置
  122.     GPIO_Configuration();    //端口初始化,所有端口关
  123. }




  124. void led_init(void)
  125. {
  126.     GPIO_InitTypeDef GPIO_InitStructure;
  127.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
  128.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |  GPIO_Pin_12 | GPIO_Pin_13;
  129.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  130.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  131.     GPIO_Init(GPIOA, &GPIO_InitStructure);

  132.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  133.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  134.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  135.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  136. }

  137. void led_on(CPU_INT32U n)
  138. {
  139.     switch (n)
  140.     {
  141.         case LED_0:
  142.         GPIO_SetBits(GPIOD, GPIO_Pin_2);
  143.         break;
  144.         case LED_1:
  145.         GPIO_SetBits(GPIOD, GPIO_Pin_3);
  146.         break;
  147.         case LED_2:
  148.         GPIO_SetBits(GPIOD, GPIO_Pin_4);
  149.         break;
  150.         case LED_3:
  151.         GPIO_SetBits(GPIOB, GPIO_Pin_9);
  152.         break;
  153.         case LED_4:
  154.         GPIO_SetBits(GPIOA, GPIO_Pin_12);
  155.         break;
  156.         case LED_5:
  157.         GPIO_SetBits(GPIOA, GPIO_Pin_11);
  158.         break;
  159.         default:
  160.         break;
  161.     }
  162. }


  163. void led_off(CPU_INT32U n)
  164. {
  165.     switch (n)
  166.     {
  167.         case LED_0:
  168.         GPIO_ResetBits(GPIOD, GPIO_Pin_2);
  169.         break;
  170.         case LED_1:
  171.         GPIO_ResetBits(GPIOD, GPIO_Pin_3);
  172.         break;
  173.         case LED_2:
  174.         GPIO_ResetBits(GPIOD, GPIO_Pin_4);
  175.         break;
  176.         case LED_3:
  177.         GPIO_ResetBits(GPIOB, GPIO_Pin_9);
  178.         break;
  179.         case LED_4:
  180.         GPIO_ResetBits(GPIOA, GPIO_Pin_12);
  181.         break;
  182.         case LED_5:
  183.         GPIO_ResetBits(GPIOA, GPIO_Pin_11);
  184.         break;
  185.         default:
  186.         break;
  187.     }
  188. }
  1. Config.h
  2. /****************************************Copyright (c)**************************************************
  3. ** Modified by:        王宏强
  4. ** Modified date:      2012-05-20
  5. ** Version:            v3.0
  6. ** Descriptions:       修改用于STM32F10x   
  7. **
  8. **------------------------------------------------------------------------------------------------------
  9. ** Modified by:         
  10. ** Modified date:      
  11. ** Version:            
  12. ** Descriptions:        
  13. **
  14. ********************************************************************************************************/
  15. #include "os.h"


  16. /********************************/
  17. /*       系统配置函数           */
  18. /********************************/
  19. #define LED_0 0
  20. #define LED_1 1
  21. #define LED_2 2
  22. #define LED_3 3
  23. #define LED_4 4
  24. #define LED_5 5


  25. void Delay(volatile CPU_INT32U nCount);
  26. void IWDG_Init(void);
  27. void SysTickInit(void);
  28. void SystemConfigInit(void);
  29. void led_init(void);
  30. void led_on(CPU_INT32U n);
  31. void led_off(CPU_INT32U n);








  32. /********************************************************************************************************
  33. **                            End Of File
  34. ********************************************************************************************************/

 楼主| internally 发表于 2019-6-18 09:19 | 显示全部楼层
app_cfg.h 追加代码 后如下:
  1. app_cfg.h
  2. /*
  3. *********************************************************************************************************
  4. *                                              EXAMPLE CODE
  5. *
  6. *                          (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
  7. *
  8. *               All rights reserved.  Protected by international copyright laws.
  9. *               Knowledge of the source code may NOT be used to develop a similar product.
  10. *               Please help us continue to provide the Embedded community with the finest
  11. *               software available.  Your honesty is greatly appreciated.
  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. #ifndef  APP_CFG_MODULE_PRESENT
  31. #define  APP_CFG_MODULE_PRESENT


  32. /*
  33. *********************************************************************************************************
  34. *                                       MODULE ENABLE / DISABLE
  35. *********************************************************************************************************
  36. */

  37. #define  APP_CFG_FS_EN                          DEF_DISABLED
  38. #define  APP_CFG_USB_DEV_EN                     DEF_DISABLED
  39. #define  APP_CFG_USB_OTG_EN                     DEF_DISABLED
  40. #define  APP_CFG_USB_HOST_EN                    DEF_DISABLED


  41. /*
  42. *********************************************************************************************************
  43. *                                              TASKS NAMES
  44. *********************************************************************************************************
  45. */



  46. /*
  47. *********************************************************************************************************
  48. *                                            TASK PRIORITIES
  49. *********************************************************************************************************
  50. */

  51. #define  APP_TASK_START_PRIO                               2

  52. /*
  53. *********************************************************************************************************
  54. *                                            TASK STACK SIZES
  55. *                             Size of the task stacks (# of OS_STK entries)
  56. *********************************************************************************************************
  57. */

  58. #define  APP_TASK_START_STK_SIZE                         512

  59. /*
  60. *********************************************************************************************************
  61. *                                        uC/LIB CONFIGURATION
  62. *********************************************************************************************************
  63. */

  64. #define  LIB_MEM_CFG_OPTIMIZE_ASM_EN            DEF_ENABLED
  65. #define  LIB_MEM_CFG_ARG_CHK_EXT_EN             DEF_ENABLED
  66. #define  LIB_MEM_CFG_ALLOC_EN                   DEF_ENABLED
  67. #define  LIB_MEM_CFG_POOL_NBR                             10
  68. #define  LIB_MEM_CFG_HEAP_SIZE                   (2 * 1024L)

  69. /*
  70. *********************************************************************************************************
  71. *                                       BSP CONFIGURATION
  72. *********************************************************************************************************
  73. */

  74. #define  BSP_CFG_SER_COMM_SEL                   BSP_SER_COMM_UART_02


  75. /*
  76. *********************************************************************************************************
  77. *                                     TRACE / DEBUG CONFIGURATION
  78. *********************************************************************************************************
  79. */

  80. #define  TRACE_LEVEL_OFF                                   0
  81. #define  TRACE_LEVEL_INFO                                  1
  82. #define  TRACE_LEVEL_DBG                                   2

  83. #define  APP_TRACE_LEVEL                        TRACE_LEVEL_DBG
  84. #define  APP_TRACE                              BSP_Ser_Printf

  85. #include  <cpu.h>
  86. void  BSP_Ser_Printf   (CPU_CHAR *format, ...);

  87. #define  FS_TRACE_LEVEL                         TRACE_LEVEL_DBG
  88. #define  FS_TRACE                               BSP_Ser_Printf

  89. #define  APP_TRACE_INFO(x)                      ((APP_TRACE_LEVEL >= TRACE_LEVEL_INFO) ? (void)(APP_TRACE x) : (void)0)
  90. #define  APP_TRACE_DBG(x)                       ((APP_TRACE_LEVEL >= TRACE_LEVEL_DBG ) ? (void)(APP_TRACE x) : (void)0)




  91. /* task priority */
  92. #define STARTUP_TASK_PRIO 4
  93. //#define TASK_MODBUS_PRIO 5
  94. //#define TASK_SI4432_PRIO 6

  95. #define TASK1_PRIO 10
  96. #define TASK2_PRIO 13
  97. #define TASK3_PRIO 14


  98. /* task stack size */
  99. #define STARTUP_TASK_STK_SIZE 100
  100. #define TASK_MODBUS_SIZE 80
  101. #define TASK1_STK_SIZE 80
  102. #define TASK2_STK_SIZE 80
  103. #define TASK3_STK_SIZE 80
  104. //#define TASK_SI432_SIZE 80




  105. #endif

 楼主| internally 发表于 2019-6-18 09:20 | 显示全部楼层
下面对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  在前后添加 ‘;’注释掉;

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

修改后如下:
  1. cpu_a.s

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


  20. ;********************************************************************************************************
  21. ;
  22. ;                                            CPU PORT FILE
  23. ;
  24. ;                                            ARM-Cortex-M3
  25. ;                                            GNU C Compiler
  26. ;
  27. ; Filename      : cpu_a.s
  28. ; Version       : V1.29.00.00
  29. ; Programmer(s) : JJL
  30. ;********************************************************************************************************


  31. ;********************************************************************************************************
  32. ;                                           PUBLIC FUNCTIONS
  33. ;********************************************************************************************************

  34.     EXPORT  CPU_IntDis
  35.     EXPORT  CPU_IntEn

  36.     EXPORT  CPU_SR_Save
  37.     EXPORT  CPU_SR_Restore

  38.     EXPORT  CPU_WaitForInt
  39.     EXPORT  CPU_WaitForExcept


  40.     EXPORT  CPU_CntLeadZeros
  41.     EXPORT  CPU_CntTrailZeros
  42.     EXPORT  CPU_RevBits


  43. ;********************************************************************************************************
  44. ;                                      CODE GENERATION DIRECTIVES
  45. ;********************************************************************************************************

  46.     PRESERVE8
  47.     AREA    |.text|, CODE, READONLY
  48.     THUMB


  49. ;$PAGE
  50. ;********************************************************************************************************
  51. ;                                    DISABLE and ENABLE INTERRUPTS
  52. ;
  53. ; Description : Disable/Enable interrupts.
  54. ;
  55. ; Prototypes  : void  CPU_IntDis(void);
  56. ;               void  CPU_IntEn (void);
  57. ;********************************************************************************************************

  58. ;.thumb_func
  59. CPU_IntDis
  60.         CPSID   I
  61.         BX      LR

  62. ;.thumb_func
  63. CPU_IntEn
  64.         CPSIE   I
  65.         BX      LR


  66. ;********************************************************************************************************
  67. ;                                      CRITICAL SECTION FUNCTIONS
  68. ;
  69. ; Description : Disable/Enable interrupts by preserving the state of interrupts.  Generally speaking, the
  70. ;               state of the interrupt disable flag is stored in the local variable 'cpu_sr' & interrupts
  71. ;               are then disabled ('cpu_sr' is allocated in all functions that need to disable interrupts).
  72. ;               The previous interrupt state is restored by copying 'cpu_sr' into the CPU's status register.
  73. ;
  74. ; Prototypes  : CPU_SR  CPU_SR_Save   (void);
  75. ;               void    CPU_SR_Restore(CPU_SR cpu_sr);
  76. ;
  77. ; Note(s)     : (1) These functions are used in general like this :
  78. ;
  79. ;                       void  Task (void  *p_arg)
  80. ;                       {
  81. ;                           CPU_SR_ALLOC();                     /* Allocate storage for CPU status register */
  82. ;                               :
  83. ;                               :
  84. ;                           CPU_CRITICAL_ENTER();               /* cpu_sr = CPU_SR_Save();                  */
  85. ;                               :
  86. ;                               :
  87. ;                           CPU_CRITICAL_EXIT();                /* CPU_SR_Restore(cpu_sr);                  */
  88. ;                               :
  89. ;                       }
  90. ;********************************************************************************************************

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

  96. ;.thumb_func
  97. CPU_SR_Restore                                 ; See Note #2.
  98.         MSR     PRIMASK, R0
  99.         BX      LR


  100. ;$PAGE
  101. ;********************************************************************************************************
  102. ;                                         WAIT FOR INTERRUPT
  103. ;
  104. ; Description : Enters sleep state, which will be exited when an interrupt is received.
  105. ;
  106. ; Prototypes  : void  CPU_WaitForInt (void)
  107. ;
  108. ; Argument(s) : none.
  109. ;********************************************************************************************************

  110. ;.thumb_func
  111. CPU_WaitForInt
  112.         WFI                                     ; Wait for interrupt
  113.         BX      LR


  114. ;********************************************************************************************************
  115. ;                                         WAIT FOR EXCEPTION
  116. ;
  117. ; Description : Enters sleep state, which will be exited when an exception is received.
  118. ;
  119. ; Prototypes  : void  CPU_WaitForExcept (void)
  120. ;
  121. ; Argument(s) : none.
  122. ;********************************************************************************************************

  123. ;.thumb_func
  124. CPU_WaitForExcept
  125.         WFE                                     ; Wait for exception
  126.         BX      LR


  127. ;$PAGE
  128. ;********************************************************************************************************
  129. ;                                         CPU_CntLeadZeros()
  130. ;                                        COUNT LEADING ZEROS
  131. ;
  132. ; Description : Counts the number of contiguous, most-significant, leading zero bits before the
  133. ;                   first binary one bit in a data value.
  134. ;
  135. ; Prototype   : CPU_DATA  CPU_CntLeadZeros(CPU_DATA  val);
  136. ;
  137. ; Argument(s) : val         Data value to count leading zero bits.
  138. ;
  139. ; Return(s)   : Number of contiguous, most-significant, leading zero bits in 'val'.
  140. ;
  141. ; Caller(s)   : Application.
  142. ;
  143. ;               This function is an INTERNAL CPU module function but MAY be called by application
  144. ;               function(s).
  145. ;
  146. ; Note(s)     : (1) (a) Supports 32-bit data value size as configured by 'CPU_DATA' (see 'cpu.h  
  147. ;                       CPU WORD CONFIGURATION  Note #1').
  148. ;
  149. ;                   (b) For 32-bit values :
  150. ;
  151. ;                             b31  b30  b29  ...  b04  b03  b02  b01  b00    # Leading Zeros
  152. ;                             ---  ---  ---       ---  ---  ---  ---  ---    ---------------
  153. ;                              1    x    x         x    x    x    x    x            0
  154. ;                              0    1    x         x    x    x    x    x            1
  155. ;                              0    0    1         x    x    x    x    x            2
  156. ;                              :    :    :         :    :    :    :    :            :
  157. ;                              :    :    :         :    :    :    :    :            :
  158. ;                              0    0    0         1    x    x    x    x           27
  159. ;                              0    0    0         0    1    x    x    x           28
  160. ;                              0    0    0         0    0    1    x    x           29
  161. ;                              0    0    0         0    0    0    1    x           30
  162. ;                              0    0    0         0    0    0    0    1           31
  163. ;                              0    0    0         0    0    0    0    0           32
  164. ;
  165. ;
  166. ;               (2) MUST be defined in 'cpu_a.asm' (or 'cpu_c.c') if CPU_CFG_LEAD_ZEROS_ASM_PRESENT is
  167. ;                   #define'd in 'cpu_cfg.h' or 'cpu.h'.
  168. ;********************************************************************************************************

  169. ;.thumb_func
  170. CPU_CntLeadZeros
  171.         CLZ     R0, R0                          ; Count leading zeros
  172.         BX      LR


  173. ;$PAGE
  174. ;********************************************************************************************************
  175. ;                                         CPU_CntTrailZeros()
  176. ;                                        COUNT TRAILING ZEROS
  177. ;
  178. ; Description : Counts the number of contiguous, least-significant, trailing zero bits before the
  179. ;                   first binary one bit in a data value.
  180. ;
  181. ; Prototype   : CPU_DATA  CPU_CntTrailZeros(CPU_DATA  val);
  182. ;
  183. ; Argument(s) : val         Data value to count trailing zero bits.
  184. ;
  185. ; Return(s)   : Number of contiguous, least-significant, trailing zero bits in 'val'.
  186. ;
  187. ; Caller(s)   : Application.
  188. ;
  189. ;               This function is an INTERNAL CPU module function but MAY be called by application
  190. ;               function(s).
  191. ;
  192. ; Note(s)     : (1) (a) Supports 32-bit data value size as configured by 'CPU_DATA' (see 'cpu.h  
  193. ;                       CPU WORD CONFIGURATION  Note #1').
  194. ;
  195. ;                   (b) For 32-bit values :
  196. ;
  197. ;                             b31  b30  b29  b28  b27  ...  b02  b01  b00    # Trailing Zeros
  198. ;                             ---  ---  ---  ---  ---       ---  ---  ---    ----------------
  199. ;                              x    x    x    x    x         x    x    1            0
  200. ;                              x    x    x    x    x         x    1    0            1
  201. ;                              x    x    x    x    x         1    0    0            2
  202. ;                              :    :    :    :    :         :    :    :            :
  203. ;                              :    :    :    :    :         :    :    :            :
  204. ;                              x    x    x    x    1         0    0    0           27
  205. ;                              x    x    x    1    0         0    0    0           28
  206. ;                              x    x    1    0    0         0    0    0           29
  207. ;                              x    1    0    0    0         0    0    0           30
  208. ;                              1    0    0    0    0         0    0    0           31
  209. ;                              0    0    0    0    0         0    0    0           32
  210. ;
  211. ;
  212. ;               (2) MUST be defined in 'cpu_a.asm' (or 'cpu_c.c') if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT is
  213. ;                   #define'd in 'cpu_cfg.h' or 'cpu.h'.
  214. ;********************************************************************************************************

  215. ;.thumb_func
  216. CPU_CntTrailZeros
  217.         RBIT    R0, R0                          ; Reverse bits
  218.         CLZ     R0, R0                          ; Count leading zeros
  219.         BX      LR


  220. ;$PAGE
  221. ;********************************************************************************************************
  222. ;                                            CPU_RevBits()
  223. ;                                            REVERSE BITS
  224. ;
  225. ; Description : Reverses the bits in a data value.
  226. ;
  227. ; Prototypes  : CPU_DATA  CPU_RevBits(CPU_DATA  val);
  228. ;
  229. ; Argument(s) : val         Data value to reverse bits.
  230. ;
  231. ; Return(s)   : Value with all bits in 'val' reversed (see Note #1).
  232. ;
  233. ; Caller(s)   : Application.
  234. ;
  235. ;               This function is an INTERNAL CPU module function but MAY be called by application function(s).
  236. ;
  237. ; Note(s)     : (1) The final, reversed data value for 'val' is such that :
  238. ;
  239. ;                       'val's final bit  0       =  'val's original bit  N
  240. ;                       'val's final bit  1       =  'val's original bit (N - 1)
  241. ;                       'val's final bit  2       =  'val's original bit (N - 2)
  242. ;
  243. ;                               ...                           ...
  244. ;
  245. ;                       'val's final bit (N - 2)  =  'val's original bit  2
  246. ;                       'val's final bit (N - 1)  =  'val's original bit  1
  247. ;                       'val's final bit  N       =  'val's original bit  0
  248. ;********************************************************************************************************

  249. ;.thumb_func
  250. CPU_RevBits
  251.         RBIT    R0, R0                          ; Reverse bits
  252.         BX      LR


  253. ;$PAGE
  254. ;********************************************************************************************************
  255. ;                                     CPU ASSEMBLY PORT FILE END
  256. ;********************************************************************************************************

  257.     END

 楼主| internally 发表于 2019-6-18 09:21 | 显示全部楼层
修改os_cfg.h

OS_CFG_TS_EN宏定义改为0u

OS_CFG_SCHED_LOCK_TIME_MEAS_EN 宏定义改为0u

OS_CFG_TASK_DEL_EN 宏定义改为 1u

其它可根据自己的功能需要 先1u或0u。
 楼主| internally 发表于 2019-6-18 09:21 | 显示全部楼层
这里Project\App\uCOS_III\uC-LIB\Source中lib_str.c的Str_FmtNbr_Int32 函数 的函数体内局部变量没有赋初值,不够严谨 这里赋初值如下:
  1. CPU_CHAR     *pstr_fmt = (CPU_CHAR *)0;
  2.     CPU_DATA      i = 0u;
  3.     CPU_INT32U    nbr_fmt = 0u;
  4.     CPU_INT32U    nbr_log = 0u;
  5.     CPU_INT08U    nbr_dig_max = 0u;
  6.     CPU_INT08U    nbr_dig_min = 0u;
  7.     CPU_INT08U    nbr_dig_fmtd = 0u;
  8.     CPU_INT08U    nbr_neg_sign = 0u;
  9.     CPU_INT08U    nbr_lead_char = 0u;
  10.     CPU_INT08U    dig_val = 0u;
  11.     CPU_INT08U    lead_char_delta_0 = 0u;
  12.     CPU_INT08U    lead_char_delta_a = 0u;
  13.     CPU_BOOLEAN   lead_char_dig = 0u;
  14.     CPU_BOOLEAN   lead_char_0 = 0u;
  15.     CPU_BOOLEAN   fmt_invalid = 0u;
  16.     CPU_BOOLEAN   print_char = 0u;
  17.     CPU_BOOLEAN   nbr_neg_fmtd = 0u;

 楼主| internally 发表于 2019-6-18 09:21 | 显示全部楼层
最后修改启动文件startup_stm32f10x_hd.s ,加载不同的启动文件 时不用怕,修改的内容都是一样的:

OS_CPU_PendSVHandler 替换所有的PendSV_Handler

OS_CPU_SysTickHandler替换所有的SysTick_Handler

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

到这里就全部OK了。
 楼主| internally 发表于 2019-6-18 09:22 | 显示全部楼层
仿真查看端口变化
922735d083ccc464e9.png
972315d083cd524943.png

编程结果过于臃肿:
462685d083ce5c7a98.png
 楼主| internally 发表于 2019-6-18 09:23 | 显示全部楼层
开启3级优化:
930105d083cfc38868.png
再编译看结果:
968875d083d0d8ee24.png
 楼主| internally 发表于 2019-6-18 09:23 | 显示全部楼层
整个工程文件资料网盘链接:http://pan.baidu.com/share/link?shareid=25418&uk=118334538
xiaoqizi 发表于 2019-7-8 09:32 | 显示全部楼层
非常感谢楼主分享
八层楼 发表于 2019-7-8 10:05 | 显示全部楼层
非常感谢楼主分享
观海 发表于 2019-7-8 10:50 | 显示全部楼层
非常感谢楼主分享
guanjiaer 发表于 2019-7-8 10:55 | 显示全部楼层
非常感谢楼主分享
heimaojingzhang 发表于 2019-7-8 11:03 | 显示全部楼层
非常感谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

315

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部