基于keil平台下STM32L系列移植FreeRTOS操作系统

1,下载FreeRTOS

https://www.freertos.org/a00104.html

image

点击下载后,会进入如下界面

image

之后会弹出下载界面,格式为.EXE,不用怀疑。不是木马。

等待下载完成,速度比较慢。

下载完成后解压文件。

2,安装keil5 ,下载安装STM32L库及相关文件。

推荐安装使用JSON库


image

安装完成后,新建工程,新建组,新建目录文件夹拷贝相关目录到自己目录下,

image

拷贝FreeRTOSv10.2.0\FreeRTOS\Source的文件 heapX.c在portable中的FreeRTOSv10.2.0\FreeRTOS\Source\portable\MemMang中,keil加载FreeRTOSv10.2.0\FreeRTOS\Source\portable\RVDS\ARM_CM3中的文件。

image


添加这个文件夹路径到编译Path下,添加Define :STM32L1XX_MD,USE_STDPERIPH_DRIVER

image

选择编译器编译

#ifdef __ICCARM__
    #include "stm32l1xx_tim.h"         //ʶ±ðIAR±àÒë
    extern void vConfigureTimerForRunTimeStats( void );
    extern unsigned long ulTIM6_OverflowCount;
#endif /* __ICCARM__ */
#ifdef __CC_ARM                  //ʶ±ðkeil±àÒë
    #include "stm32l1xx_tim.h"
    extern void vConfigureTimerForRunTimeStats( void );
    extern unsigned long ulTIM6_OverflowCount;
  1. 打开FreeRTOSConfig.h文件,在其最下面添加一下宏定义,这些宏将FreeRTOS的这三个回调跟stm32官方的对应起来,这样就不用修改启动文件。同时需要将stm32f10x_it.c里边对应的三个函数注释掉或者加上__weak关键字。

            #define xPortPendSVHandler                   PendSV_Handler

            #define xPortSysTickHandler                    SysTick_Handler

            #define vPortSVCHandler                         SVC_Handler

    keil环境下stm32f103移植freertos

    keil环境下stm32f103移植freertos

  2. 编译报错:

image



修改main.c文件

添加如下函数:

 void vApplicationTickHook(void)
 {
     /* This function will be called by each tick interrupt if
     configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
     added here, but the tick hook is called from an interrupt context, so
     code must not attempt to block, and only the interrupt safe FreeRTOS API
     functions can be used (those that end in FromISR()).  */

}

 void vApplicationIdleHook(void)
 {
     /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
     to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
     task.  It is essential that code added to this hook function never attempts
     to block in any way (for example, call xQueueReceive() with a block time
     specified, or call vTaskDelay()).  If the application makes use of the
     vTaskDelete() API function (as this demo application does) then it is also
     important that vApplicationIdleHook() is permitted to return to its calling
     function, because it is the responsibility of the idle task to clean up
     memory allocated by the kernel to any task that has since been deleted. */
 }

 void vApplicationMallocFailedHook(void)
 {
     /* vApplicationMallocFailedHook() will only be called if
     configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
     function that will get called if a call to pvPortMalloc() fails.
     pvPortMalloc() is called internally by the kernel whenever a task, queue,
     timer or semaphore is created.  It is also called by various parts of the
     demo application.  If heap_1.c or heap_2.c are used, then the size of the
     heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
     FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
     to query the size of free heap space that remains (although it does not
     provide information on how the remaining heap might be fragmented). */
     taskDISABLE_INTERRUPTS();
     for(;;);
 }

添加如下头文件:

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"

posted @ 2019-03-14 14:02  朽木生  阅读(3299)  评论(0编辑  收藏  举报