时间:2022-09-26 09:04
人气:
作者:admin
首先新建或找一个基于Keil的STM32基础工程,这里我已经创建好了一个STM32F407VET6的工程模板,工程结构如下图的第1步的矩形框内所示。
下面需要移植FreeRTOS了,将FreeRTOS的源码文件复制到工程文件夹中,一些用不到的文件可删除(哪些文件需要用到可参考上一篇的源码结构分析部分),然后在Keil中也创建一个FreeRTOS目录,将c文件添加进工程,注意port.c来自于RDVS的ARM_CM4F,对应于移植到的SMT32F407硬件。

添加完c文件后,还要添加对应的h文件的搜寻路径,具体如下:

然后就可以编译了,先进行第1次编译:
......(省略显示若干行) FreeRTOSportableRVDSARM_CM4Fport.c: 0 warnings, 1 error compiling heap_4.c... .FreeRTOSincludeFreeRTOS.h(98): error: #5: cannot open source input file "FreeRTOSConfig.h": No such file or directory #include "FreeRTOSConfig.h" FreeRTOSportableMemMangheap_4.c: 0 warnings, 1 error ".ObjectsTemplate_FreeRTOS.axf" - 8 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:23
有一个错误,找不到"FreeRTOSConfig.h",这个文件在FreeRTOS源码的Demo文件中,
将Demo中的"FreeRTOSConfig.h"文件放到FreeRTOS文件夹下的include文件夹下, 进行第2次编译:
......(省略显示若干行)
compiling tasks.c...
compiling timers.c...
compiling port.c...
FreeRTOSportableRVDSARM_CM4Fport.c(713): error: #20: identifier "SystemCoreClock" is undefined
ortNVIC_SYSTICK_LOAD_REG = (
onfigSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
FreeRTOSportableRVDSARM_CM4Fport.c: 0 warnings, 1 error
又提示"SystemCoreClock" 未定义,因为在"FreeRTOSConfig.h" : 中使用了SysyemCoreClock来标记MCU的频率,
在"FreeRTOSConfig.h" :的87~95行:
#ifdef __ICCARM__ #include extern uint32_t SystemCoreClock; #endif #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 1 #define configCPU_CLOCK_HZ ( SystemCoreClock )
将条件编译
#ifdef __ICCARM__
修改为
#if defined(__ICCARM__)||defined(__CC_ARM)||defined(__GNU__)
再次进行第3次编译:
......(省略显示若干行) compiling port.c... compiling heap_4.c... linking... .ObjectsTemplate_FreeRTOS.axf: Error: L6200E: Symbol SVC_Handler multiply defined (by port.o and stm32f4xx_it.o). .ObjectsTemplate_FreeRTOS.axf: Error: L6200E: Symbol PendSV_Handler multiply defined (by port.o and stm32f4xx_it.o). .ObjectsTemplate_FreeRTOS.axf: Error: L6200E: Symbol SysTick_Handler multiply defined (by port.o and stm32f4xx_it.o). Not enough information to list image symbols. Not enough information to list the image map. Finished: 2 information, 0 warning and 3 error messages. ".ObjectsTemplate_FreeRTOS.axf" - 3 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:02
又提示port.o与stm32f4xx_it.o有重复定义(.o为编译的目标文件,其实就是对应的.c文件出了问题)
注释掉stm32f4xx_it.c中的SVC_Handler() PendSV_Handler() SysTick_Handler()即可
修改后的stm32f4xx_it.c的110~145行:
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
//void SVC_Handler(void)
//{
/