打印
[应用相关]

uCos-III移植到STM32F10x

[复制链接]
457|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
最近在百度上看了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。
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.添加工程文件:


使用特权

评论回复
沙发
internally|  楼主 | 2019-6-18 09:19 | 只看该作者
Main.c, Kernel.c,Kernel.h,Config.c,Config.h代码如下提供。

Main.c
#include "os.h"
#include "Kernel.h"
#include "Config.h"

int main()
{
    SystemConfigInit();   
    KeranlTask();
   
    return 0;
}

Kernel.c
/*-------------------------------------------------------------------------

                            软件主体

   
-------------------------------------------------------------------------*/

#include "os.h"
#include "kernel.h"
#include "config.h"

extern void SysTickInit(void);

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

static OS_TCB task1TCB;
static CPU_STK task1_stk[TASK1_STK_SIZE];

static OS_TCB task2TCB;
static CPU_STK task2_stk[TASK2_STK_SIZE];

static OS_TCB task3TCB;
static CPU_STK task3_stk[TASK3_STK_SIZE];

static volatile OS_SEM taskSem;
static volatile OS_ERR err;

/*******************************************************************************
* Function Name :void StartTask(void)
* Description   :启动任务
* Input         :
* Output        :
* Other         :
* Date          :2012.04.18  11:48:23
*******************************************************************************/
void StartTask(void)
{
   
    led_init();
    SysTickInit();
   
    OSTaskCreate(    (OS_TCB     *)&task1TCB,
                    (CPU_CHAR     *)"task1",
                    (OS_TASK_PTR)task1,
                    (void         *)0,
                    (OS_PRIO     )TASK1_PRIO,
                    (CPU_STK    *)&task1_stk[0],
                    (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK1_STK_SIZE,
                    (OS_MSG_QTY    )0,
                    (OS_TICK    )0,
                    (void        *)0,
                    (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                    (OS_ERR        *)&err);
   
    OSTaskCreate(    (OS_TCB     *)&task2TCB,
                    (CPU_CHAR     *)"task2",
                    (OS_TASK_PTR)task2,
                    (void         *)0,
                    (OS_PRIO    ) TASK2_PRIO,
                    (CPU_STK    *)&task2_stk[0],
                    (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK2_STK_SIZE,
                    (OS_MSG_QTY)0,
                    (OS_TICK    )0,
                    (void        *)0,
                    (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                    (OS_ERR        *)&err);   

                    
    OSTaskCreate(    (OS_TCB     *)&task3TCB,
                    (CPU_CHAR     *)"task3",
                    (OS_TASK_PTR)task3,
                    (void         *)0,
                    (OS_PRIO    )TASK3_PRIO,
                    (CPU_STK    *)&task3_stk[0],
                    (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK3_STK_SIZE,
                    (OS_MSG_QTY)0,
                    (OS_TICK    )0,
                    (void        *)0,
                    (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                    (OS_ERR        *)&err);

    OSSemCreate(    (OS_SEM     *)&taskSem,
                    (CPU_CHAR     *)"taskSem",
                    (OS_SEM_CTR)0,
                    (OS_ERR     *)err);
   
    OSTaskDel(        (OS_TCB     *)&taskStartTCB,
                    (OS_ERR     *)&err);
}

static void task1(void *p_arg)
{

    while (1)
    {
        led_on(LED_4);
        OSTimeDly(    (OS_TICK    )200,
                    (OS_OPT        )OS_OPT_TIME_DLY,
                    (OS_ERR     *)&err);

        led_off(LED_4);
        OSTimeDly(    (OS_TICK    )200,
                    (OS_OPT        )OS_OPT_TIME_DLY,
                    (OS_ERR     *)&err);

        OSSemPost(    (OS_SEM     *)&taskSem,
                    (OS_OPT        )OS_OPT_POST_ALL,
                    (OS_ERR     *)&err);

    }
}

static void task2(void *p_arg)
{
    while (1)
    {
        led_on(LED_5);
        OSSemPend(    (OS_SEM     *)&taskSem,
                    (OS_TICK    )10000,
                    (OS_OPT        )OS_OPT_PEND_BLOCKING,
                    (CPU_TS         *)0,
                    (OS_ERR     *)&err);

        led_off(LED_5);
        OSSemPend(    (OS_SEM     *)&taskSem,
                    (OS_TICK    )10000,
                    (OS_OPT        )OS_OPT_PEND_BLOCKING,
                    (CPU_TS         *)0,
                    (OS_ERR     *)&err);
        
    }
}

static void task3(void *p_arg)
{
   
    while (1)
    {
        led_on(LED_3);
        OSTimeDly(    (OS_TICK    )100,
                    (OS_OPT        )OS_OPT_TIME_DLY,
                    (OS_ERR     *)&err);

        led_off(LED_3);
        OSTimeDly(    (OS_TICK    )100,
                    (OS_OPT        )OS_OPT_TIME_DLY,
                    (OS_ERR     *)&err);
        
    }
}


/*******************************************************************************
* Function Name :void KeranlTask(void)
* Description   :启动任务
* Input         :
* Output        :
* Other         :
* Date          :2012.04.18  11:05:47
*******************************************************************************/
void KeranlTask(void)
{   
    CPU_Init();
    OSInit((OS_ERR *)&err);   
   
    OSTaskCreate(    (OS_TCB     *)&taskStartTCB,
                    (CPU_CHAR     *)"task_start",
                    (OS_TASK_PTR)StartTask,
                    (void         *)0,
                    (OS_PRIO    ) STARTUP_TASK_PRIO,
                    (CPU_STK    *)&startTaskStk[0],
                    (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE / 10,
                    (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE,
                    (OS_MSG_QTY)0,
                    (OS_TICK    )0,
                    (void        *)0,
                    (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                    (OS_ERR        *)&err);
                    
    OSStart((OS_ERR *)&err);
}

Kernel.h
#ifndef _kernel_h_
#define _kernel_h_

#include "os.h"







static void task1(void *p_arg);
static void task2(void *p_arg);
static void task3(void *p_arg);

void KeranlTask(void);


#endif
Config.c
/*
********************************************************************************
*                                  uC/OS-II
*                           
*                              ARM Cortex-M3 Port
*
* File          : Config.C
* Version       : V1.0
* By            : 王宏强
*
* For           : Stm32f10x
* Mode          : Thumb2
* Toolchain     :
*                     RealView Microcontroller Development Kit (MDK)
*                     Keil uVision
* Description   : STM32F10x 内部 系统的配置
*
*                    1,系统中断优先级模式设置
*                    2,系统程序启动指定
*                    3,系统时钟计时器配置
*                    4,芯片引脚初始化
*                    
* Date          : 2012.05.22
*******************************************************************************/

#include "misc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_iwdg.h"
#include "config.h"


GPIO_InitTypeDef GPIO_InitStructure;
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configures the different GPIO ports.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
#ifdef USE_STM3210B_EVAL
    /* Enable the USART2 Pins Software Remapping */
    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#endif

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                     RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                     RCC_APB2Periph_GPIOE, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    GPIO_Init(GPIOE, &GPIO_InitStructure);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE, DISABLE);  

}


/*******************************************************************************
* Function Name  : Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(volatile CPU_INT32U nCount)
{
  for(; nCount != 0; nCount--);
}

/*******************************************************************************
函 数 名:void IWDG_Init(void)
功能描述:看门狗初始化                        
入口参数:                           
返回参数:
创建时间: 2011.6.24
********************************************************************************/
void IWDG_Init(void)
{

    IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );
    IWDG_SetPrescaler( IWDG_Prescaler_64);    //最小
    IWDG_SetReload( 0x138);        //40KHz内部时钟 0.5s
    IWDG_WriteAccessCmd( IWDG_WriteAccess_Disable );
    IWDG_Enable();
    IWDG_ReloadCounter();
}

/*******************************************************************************
* Function Name :void SysTickInit(void)
* Description   :系统定时器时间配置
* Input         :
* Output        :
* Other         :时基为1ms
* Date          :2011.11.03  12:59:13
*******************************************************************************/
void SysTickInit(void)
{
    SysTick_Config(SystemCoreClock / 1000);            //uCOS时基1ms
}
/*******************************************************************************
* Function Name :void InterruptOrder(void)
* Description   :中断向量,优先级
* Input         :
* Output        :
* Other         :
* Date          :2011.10.27  11:50:05
*******************************************************************************/
void NVIC_Configuration(void)
{
    NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );//优先级设置
}

/*******************************************************************************
* Function Name :void SystemConfig(void)
* Description   :系统初始化
* Input         :
* Output        :
* Other         :
* Date          :2011.10.27  13:14:59
*******************************************************************************/
void SystemConfigInit(void)
{
    NVIC_Configuration();    //中断优先级设置
    GPIO_Configuration();    //端口初始化,所有端口关
}




void led_init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |  GPIO_Pin_12 | GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
}

void led_on(CPU_INT32U n)
{
    switch (n)
    {
        case LED_0:
        GPIO_SetBits(GPIOD, GPIO_Pin_2);
        break;
        case LED_1:
        GPIO_SetBits(GPIOD, GPIO_Pin_3);
        break;
        case LED_2:
        GPIO_SetBits(GPIOD, GPIO_Pin_4);
        break;
        case LED_3:
        GPIO_SetBits(GPIOB, GPIO_Pin_9);
        break;
        case LED_4:
        GPIO_SetBits(GPIOA, GPIO_Pin_12);
        break;
        case LED_5:
        GPIO_SetBits(GPIOA, GPIO_Pin_11);
        break;
        default:
        break;
    }
}


void led_off(CPU_INT32U n)
{
    switch (n)
    {
        case LED_0:
        GPIO_ResetBits(GPIOD, GPIO_Pin_2);
        break;
        case LED_1:
        GPIO_ResetBits(GPIOD, GPIO_Pin_3);
        break;
        case LED_2:
        GPIO_ResetBits(GPIOD, GPIO_Pin_4);
        break;
        case LED_3:
        GPIO_ResetBits(GPIOB, GPIO_Pin_9);
        break;
        case LED_4:
        GPIO_ResetBits(GPIOA, GPIO_Pin_12);
        break;
        case LED_5:
        GPIO_ResetBits(GPIOA, GPIO_Pin_11);
        break;
        default:
        break;
    }
}
Config.h
/****************************************Copyright (c)**************************************************
** Modified by:        王宏强
** Modified date:      2012-05-20
** Version:            v3.0
** Descriptions:       修改用于STM32F10x   
**
**------------------------------------------------------------------------------------------------------
** Modified by:         
** Modified date:      
** Version:            
** Descriptions:        
**
********************************************************************************************************/
#include "os.h"


/********************************/
/*       系统配置函数           */
/********************************/
#define LED_0 0
#define LED_1 1
#define LED_2 2
#define LED_3 3
#define LED_4 4
#define LED_5 5


void Delay(volatile CPU_INT32U nCount);
void IWDG_Init(void);
void SysTickInit(void);
void SystemConfigInit(void);
void led_init(void);
void led_on(CPU_INT32U n);
void led_off(CPU_INT32U n);








/********************************************************************************************************
**                            End Of File
********************************************************************************************************/

使用特权

评论回复
板凳
internally|  楼主 | 2019-6-18 09:19 | 只看该作者
app_cfg.h 追加代码 后如下:
app_cfg.h
/*
*********************************************************************************************************
*                                              EXAMPLE CODE
*
*                          (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               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.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                      APPLICATION CONFIGURATION
*
*                                     ST Microelectronics STM32
*                                              on the
*
*                                     Micrium uC-Eval-STM32F107
*                                        Evaluation Board
*
* Filename      : app_cfg.h
* Version       : V1.00
* Programmer(s) : FT
*********************************************************************************************************
*/

#ifndef  APP_CFG_MODULE_PRESENT
#define  APP_CFG_MODULE_PRESENT


/*
*********************************************************************************************************
*                                       MODULE ENABLE / DISABLE
*********************************************************************************************************
*/

#define  APP_CFG_FS_EN                          DEF_DISABLED
#define  APP_CFG_USB_DEV_EN                     DEF_DISABLED
#define  APP_CFG_USB_OTG_EN                     DEF_DISABLED
#define  APP_CFG_USB_HOST_EN                    DEF_DISABLED


/*
*********************************************************************************************************
*                                              TASKS NAMES
*********************************************************************************************************
*/



/*
*********************************************************************************************************
*                                            TASK PRIORITIES
*********************************************************************************************************
*/

#define  APP_TASK_START_PRIO                               2

/*
*********************************************************************************************************
*                                            TASK STACK SIZES
*                             Size of the task stacks (# of OS_STK entries)
*********************************************************************************************************
*/

#define  APP_TASK_START_STK_SIZE                         512

/*
*********************************************************************************************************
*                                        uC/LIB CONFIGURATION
*********************************************************************************************************
*/

#define  LIB_MEM_CFG_OPTIMIZE_ASM_EN            DEF_ENABLED
#define  LIB_MEM_CFG_ARG_CHK_EXT_EN             DEF_ENABLED
#define  LIB_MEM_CFG_ALLOC_EN                   DEF_ENABLED
#define  LIB_MEM_CFG_POOL_NBR                             10
#define  LIB_MEM_CFG_HEAP_SIZE                   (2 * 1024L)

/*
*********************************************************************************************************
*                                       BSP CONFIGURATION
*********************************************************************************************************
*/

#define  BSP_CFG_SER_COMM_SEL                   BSP_SER_COMM_UART_02


/*
*********************************************************************************************************
*                                     TRACE / DEBUG CONFIGURATION
*********************************************************************************************************
*/

#define  TRACE_LEVEL_OFF                                   0
#define  TRACE_LEVEL_INFO                                  1
#define  TRACE_LEVEL_DBG                                   2

#define  APP_TRACE_LEVEL                        TRACE_LEVEL_DBG
#define  APP_TRACE                              BSP_Ser_Printf

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

#define  FS_TRACE_LEVEL                         TRACE_LEVEL_DBG
#define  FS_TRACE                               BSP_Ser_Printf

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




/* task priority */
#define STARTUP_TASK_PRIO 4
//#define TASK_MODBUS_PRIO 5
//#define TASK_SI4432_PRIO 6

#define TASK1_PRIO 10
#define TASK2_PRIO 13
#define TASK3_PRIO 14


/* task stack size */
#define STARTUP_TASK_STK_SIZE 100
#define TASK_MODBUS_SIZE 80
#define TASK1_STK_SIZE 80
#define TASK2_STK_SIZE 80
#define TASK3_STK_SIZE 80
//#define TASK_SI432_SIZE 80




#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  在前后添加 ‘;’注释掉;

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

修改后如下:
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

使用特权

评论回复
5
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。

使用特权

评论回复
6
internally|  楼主 | 2019-6-18 09:21 | 只看该作者
这里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;

使用特权

评论回复
7
internally|  楼主 | 2019-6-18 09:21 | 只看该作者
最后修改启动文件startup_stm32f10x_hd.s ,加载不同的启动文件 时不用怕,修改的内容都是一样的:

OS_CPU_PendSVHandler 替换所有的PendSV_Handler

OS_CPU_SysTickHandler替换所有的SysTick_Handler

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

到这里就全部OK了。

使用特权

评论回复
8
internally|  楼主 | 2019-6-18 09:22 | 只看该作者
仿真查看端口变化



编程结果过于臃肿:

使用特权

评论回复
9
internally|  楼主 | 2019-6-18 09:23 | 只看该作者
开启3级优化:

再编译看结果:

使用特权

评论回复
10
internally|  楼主 | 2019-6-18 09:23 | 只看该作者
整个工程文件资料网盘链接:http://pan.baidu.com/share/link?shareid=25418&uk=118334538

使用特权

评论回复
11
xiaoqizi| | 2019-7-8 09:32 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
12
八层楼| | 2019-7-8 10:05 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
13
观海| | 2019-7-8 10:50 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
14
guanjiaer| | 2019-7-8 10:55 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
15
heimaojingzhang| | 2019-7-8 11:03 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

315

帖子

0

粉丝