小目标_移植FreeRTOS到STM32F412

来源:互联网 发布:收购淘宝买家订单数据 编辑:程序博客网 时间:2024/05/16 14:08

年后工作需要用到STM32F412和FreeRTOS(免费操作系统),趁着这个时候有时间,先了解了解...

工作一直用STM32F207,编译环境IAR7.20,所以直接用到一个Demo软件进行修改,将STM32F2库函数换成STM32F4,修改过程发现一个大问题,IAR7.20无法找到STM32F412,以前在公司出现这样的问题,找STM32技术支持,他们提供相关的文件,将文件拷贝到IAR7.20相关目录就搞定,由于已经放假,只能自己在网上找,找关天,未找到,只能去www.iar.com官网看看,发现介绍IAR7.80支持STM32F412,所以下载IAR7.80并安装,完成后,发现IAR7.80需要注册,没有license,所以将IAR7.80安装目录下的config与STM32F412相关的文件,全部拷贝到IAR7.20安装目录下对应的文件,搞定。

编译过程中不小心采用IAR7.80打开工程,结果换回IAR7.20之后,一直提示工程某个文件无法打开,提行如下:

“The project 'project' contains the unknown tools 'XXXX'  ”

       在网上搜索解决办法,官网上有类似解决方案,http://supp.iar.com/Support/?note=47528&from=search+result 

        从https://sourceforge.net/projects/freertos/files/FreeRTOS/V8.2.3/ 下载V8.2.3版本,并将FreeRTOS相关文件加载到工程里

                                                     

修改FreeRTOSConfig.h配置文件

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 
 *
 * See http://www.freertos.org/a00110.html.
 *----------------------------------------------------------*/
#define configUSE_PREEMPTION        1
#define configUSE_IDLE_HOOK         0
#define configUSE_TICK_HOOK         0
#define configCPU_CLOCK_HZ          ( ( unsigned long ) 100000000 )//168000000 
#define configTICK_RATE_HZ          ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES        ( 10 )
#define configMINIMAL_STACK_SIZE    ( ( unsigned short ) 1024 )
#define configTOTAL_HEAP_SIZE       ( ( size_t ) ( 30 * 1024 ) )
#define configMAX_TASK_NAME_LEN     ( 16 )
#define configUSE_TRACE_FACILITY    1
#define configUSE_16_BIT_TICKS      0 //系统时钟使用32bit
#define configIDLE_SHOULD_YIELD     1


/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )


/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */


#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1


/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS       __NVIC_PRIO_BITS
#else
#define configPRIO_BITS       4        /* 15 priority levels */
#endif


/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0x0f


/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY0x01


/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for(;;);  }

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */

最后创建两个任务(main.c),便移植完成

static void vTaskStart(void *pvParameters);
static void vTaskStart2(void *pvParameters);
static void AppTaskCreate (void);

static TaskHandle_t xHandleTaskStart = NULL;
static TaskHandle_t xHandleTaskStart2 = NULL;


int main(void)
{
    __set_PRIMASK(1);  /* 禁止全局中断 */
    /* 硬件初始化 */
    bsp_Init(); 

    AppTaskCreate();

    vTaskStartScheduler();

    while(1)
;
}

static void vTaskStart(void *pvParameters)
{
    int a = 0;
    while(1)
    {
        a = 0;
        vTaskDelay(2000);   
    }

}

static void vTaskStart2(void *pvParameters)

{
    int a = 0;
    while(1)
    {
        a = 0;
        vTaskDelay(2000);   
    }

}

static void AppTaskCreate (void)
{
    xTaskCreate(vTaskStart2,                 // 任务函数
                "vTaskStart2",               // 任务名
                512,                        // 任务栈大小,单位word,也就是4字节
                NULL,                       // 任务参数
                5,                          // 任务优先级
                &xHandleTaskStart2 );        // 任务句柄

    xTaskCreate(vTaskStart,                 // 任务函数
                "vTaskStart",               // 任务名
                512,                        // 任务栈大小,单位word,也就是4字节
                NULL,                       // 任务参数
                4,                          // 任务优先级
                &xHandleTaskStart );        // 任务句柄
}

0 0