首先新建或找一個基于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) //{ //} /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ //void PendSV_Handler(void) //{ //} /** * @brief This function handles SysTick Handler. * @param None * @retval None */ //void SysTick_Handler(void) //{ // //}
再次進行第4次編譯:
......(省略顯示若干行) linking... .ObjectsTemplate_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationIdleHook (referred from tasks.o). .ObjectsTemplate_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationStackOverflowHook (referred from tasks.o). .ObjectsTemplate_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationTickHook (referred from tasks.o). .ObjectsTemplate_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationMallocFailedHook (referred from heap_4.o). Not enough information to list image symbols. Finished: 1 information, 0 warning and 4 error messages. ".ObjectsTemplate_FreeRTOS.axf" - 4 Error(s), 0 Warning(s).
又提示4個hook函數未定義,
這是因為在"FreeRTOSConfig.h"中定義了這些鉤子函數,但未找到函數定義,我們先注釋掉這些定義,
就是將configUSE_IDLE_HOOK之類的宏定義定義為0即可,
查看"FreeRTOSConfig.h"的93~108行:
#define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 1 #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 75 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 10 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 #define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_MALLOC_FAILED_HOOK 1
修改93 94 106 108行的數值為0,即:
#define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 ......(省略顯示11行) #define configCHECK_FOR_STACK_OVERFLOW 0 ......(省略顯示1行) #define configUSE_MALLOC_FAILED_HOOK 0
再次進行第5次編譯:
......(省略顯示若干行) compiling port.c... compiling heap_4.c... linking... Program Size: Code=1880 RO-data=424 RW-data=68 ZI-data=2036 ".ObjectsTemplate_FreeRTOS.axf" - 0 Error(s), 0 Warning(s). Build Time Elapsed: 00:00:01
終于編譯ok了,這樣基本上算移植成功了。
審核編輯:劉清
-
嵌入式
+關注
關注
5082文章
19104瀏覽量
304803 -
FreeRTOS
+關注
關注
12文章
484瀏覽量
62139
發布評論請先 登錄
相關推薦
評論