首先新建或找一个基于keil的stm32基础工程,这里我已经创建好了一个stm32f407vet6的工程模板,工程结构如下图的第1步的矩形框内所示。
下面需要移植freertos了,将freertos的源码文件复制到工程文件夹中,一些用不到的文件可删除(哪些文件需要用到可参考上一篇的源码结构分析部分),然后在keil中也创建一个freertos目录,将c文件添加进工程,注意port.c来自于rdvs的arm_cm4f,对应于移植到的smt32f407硬件。
添加完c文件后,还要添加对应的h文件的搜寻路径,具体如下:
然后就可以编译了,先进行第1次编译:
......(省略显示若干行)freertosportablervdsarm_cm4fport.c: 0 warnings, 1 errorcompiling heap_4.c....freertosincludefreertos.h(98): error: #5: cannot open source input file freertosconfig.h: no such file or directory #include freertosconfig.hfreertosportablememmangheap_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了,这样基本上算移植成功了。
多功能电子元器件测试仪LED推拉力测试机应用案例分析
基于RFID的室内定位系统设计
苏州功率电感厂家揭秘cd75贴片功率电感发烫的原因
MOS管三个极的判定
LifeSignals推出与3M和意法半导体联合开发的Life Signal™系列
FreeRTOS移植-基于STM32F407
智能安全帽
2020年Q3中国智能手机市场继续收缩,小米成唯一增长
雷军:周鸿祎把傅盛都给忽悠了 忍无可忍!
波峰焊炉中焊料的维护及工艺调整
现在入手iPhone11还是iPhone12?
卢伟冰发表Redmi品牌独立宣言 死磕品质追求极致性价比
科瑞技术最新升级的切叠一体机首次亮相
华润微:在手订单饱满,多个业务板块齐头并进
高通加速布局VR/无人机 物联网时代能否复制辉煌
你知道怎么Spring security整合JWT么
一款十分强大的文件加密解密CLI工具toplip的详细资料概述
简要概述LoRa技术在智慧工厂的应用
为什么多数人会选择购买贴片电阻
万用表9V电池代换电路,1.5 to 9v dc-dc converter