Keil的例程移植是个重点
以上海灵动的FTHR-G0001为例
首先要有手册、例程
d82d10de-e278-465f-8282-9f98dabfa4be.zip
打开例程后发现总是少文件,还有因为路径问题报错
先看一下最终排除错误后的结果:
为力求真实,我从头开始截图说明:
打开Keil压缩包,把其中的文件夹 点右键 复制到 另一个位置,
从另一个位置的文件夹里打开KEIL文件,
以上说的是,不要再压缩文件中打开KEIL例程,会加载路径错误。
点开:
点开
点开,默认读者知晓KEIL安装,并装好keil v5
编译:
编译版本报错:
解决方式:
更换V6.2.1
重新编译:33个错误
用讯飞星火查询报错原因:
Build started: Project: USART_Interrupt
*** Using Compiler 'V6.21', folder: 'D:\Keil_v5\ARM\ARMCLANG\Bin'
Build target 'USART_Interrupt'
compiling main.c...
../main.c(33): warning: In file included from...
../platform.h:38:10: fatal error: 'hal_conf.h' file not found
38 | #include "hal_conf.h"
| ^~~~~~~~~~~~
1 error generated.
compiling mm32g0001_it.c...
../mm32g0001_it.c(33): warning: In file included from...
../platform.h:38:10: fatal error: 'hal_conf.h' file not found
38 | #include "hal_conf.h"
| ^~~~~~~~~~~~
1 error generated.
compiling usart_interrupt.c...
../usart_interrupt.c(34): warning: In file included from...
../platform.h:38:10: fatal error: 'hal_conf.h' file not found
38 | #include "hal_conf.h"
| ^~~~~~~~~~~~
1 error generated.
compiling platform.c...
../platform.c(34): warning: In file included from...
../platform.h:38:10: fatal error: 'hal_conf.h' file not found
38 | #include "hal_conf.h"
| ^~~~~~~~~~~~
1 error generated.
compiling hal_adc.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_adc.c'
ArmClang: error: no input files
compiling hal_crc.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_crc.c'
ArmClang: error: no input files
compiling hal_dbg.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_dbg.c'
ArmClang: error: no input files
compiling hal_exti.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_exti.c'
ArmClang: error: no input files
compiling hal_flash.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_flash.c'
ArmClang: error: no input files
compiling hal_gpio.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_gpio.c'
ArmClang: error: no input files
compiling hal_i2c.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_i2c.c'
ArmClang: error: no input files
compiling hal_iwdg.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_iwdg.c'
ArmClang: error: no input files
compiling hal_misc.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_misc.c'
ArmClang: error: no input files
compiling hal_pwr.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_pwr.c'
ArmClang: error: no input files
compiling hal_rcc.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_rcc.c'
ArmClang: error: no input files
compiling hal_spi.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_spi.c'
ArmClang: error: no input files
compiling hal_tim.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_tim.c'
ArmClang: error: no input files
compiling hal_uid.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_uid.c'
ArmClang: error: no input files
compiling hal_usart.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/HAL_Lib/src/hal_usart.c'
ArmClang: error: no input files
compiling system_mm32g0001.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/Source/system_mm32g0001.c'
ArmClang: error: no input files
assembling startup_mm32g0001_keil.s...
startup_mm32g0001_keil.s: error: A1023E: File "..\..\..\..\..\Device\MM32G0001\Source\KEIL_StartAsm\startup_mm32g0001_keil.s" could not be opened: No such file or directory
".\Objects\USART_Interrupt.axf" - 33 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:19
注释:
从编译错误信息来看,主要问题有以下几点:
1. 找不到头文件 "hal_conf.h"。请确保该头文件存在于正确的路径下,并在项目中正确引用。
2. 找不到源文件 "../../../../../Device/MM32G0001/HAL_Lib/src/hal_adc.c" 等。请确保这些源文件存在于正确的路径下,并在项目中正确引用。
3. 找不到汇编文件 "startup_mm32g0001_keil.s"。请确保该文件存在于正确的路径下,并在项目中正确引用。
请检查项目设置和文件路径,确保所有文件都存在于正确的位置,并在项目中正确引用。
从这个例程中移植 hal_conf.h :
41d52245-d97f-4fd6-820a-49cbe5a16954.zip
注意解压缩成文件夹再用,注意路径:
移植过程:
复制上图的上上级文件夹:
到被移植的文件夹:
重新添加
先观察原来的.c文件
然后删除:
重新添加.c文件,点Add File,找到、逐一全部添加,或按住Ctrl多次点击添加,或按住Shift点击头尾文件全部添加:
点击一次Add后点击Close;再点击OK.
下面添加路径到KEIL:
点三个点:
添加路径:
点击 OK
添加.h文件路径:
再次编译:
此处3个错误:
Build started: Project: USART_Interrupt
*** Using Compiler 'V6.21', folder: 'D:\Keil_v5\ARM\ARMCLANG\Bin'
Build target 'USART_Interrupt'
compiling main.c...
../main.c(33): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h:43:10: fatal error: 'mm32_device.h' file not found
43 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling mm32g0001_it.c...
../mm32g0001_it.c(33): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h:43:10: fatal error: 'mm32_device.h' file not found
43 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling usart_interrupt.c...
../usart_interrupt.c(34): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h:43:10: fatal error: 'mm32_device.h' file not found
43 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling platform.c...
../platform.c(34): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h:43:10: fatal error: 'mm32_device.h' file not found
43 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_adc.c...
../HAL_Lib/src/hal_adc.c(33): warning: In file included from...
../HAL_Lib/inc\hal_adc.h:40:10: fatal error: 'mm32_device.h' file not found
40 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_crc.c...
../HAL_Lib/src/hal_crc.c(34): warning: In file included from...
../HAL_Lib/inc\hal_crc.h:38:10: fatal error: 'mm32_device.h' file not found
38 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_dbg.c...
../HAL_Lib/src/hal_dbg.c(38): warning: In file included from...
../HAL_Lib/inc\hal_dbg.h:44:10: fatal error: 'mm32_device.h' file not found
44 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_exti.c...
../HAL_Lib/src/hal_exti.c(38): warning: In file included from...
../HAL_Lib/inc\hal_exti.h:45:10: fatal error: 'mm32_device.h' file not found
45 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_flash.c...
../HAL_Lib/src/hal_flash.c(33): warning: In file included from...
../HAL_Lib/inc\hal_flash.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_gpio.c...
../HAL_Lib/src/hal_gpio.c(33): warning: In file included from...
../HAL_Lib/inc\hal_gpio.h:38:10: fatal error: 'mm32_device.h' file not found
38 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_i2c.c...
../HAL_Lib/src/hal_i2c.c(33): warning: In file included from...
../HAL_Lib/inc\hal_i2c.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_iwdg.c...
../HAL_Lib/src/hal_iwdg.c(33): warning: In file included from...
../HAL_Lib/inc\hal_iwdg.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_misc.c...
../HAL_Lib/src/hal_misc.c(33): warning: In file included from...
../HAL_Lib/inc\hal_misc.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_pwr.c...
../HAL_Lib/src/hal_pwr.c(34): warning: In file included from...
../HAL_Lib/inc\hal_pwr.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_rcc.c...
../HAL_Lib/src/hal_rcc.c(34): warning: In file included from...
../HAL_Lib/inc\hal_rcc.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_spi.c...
../HAL_Lib/src/hal_spi.c(34): warning: In file included from...
../HAL_Lib/inc\hal_spi.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_tim.c...
../HAL_Lib/src/hal_tim.c(33): warning: In file included from...
../HAL_Lib/inc\hal_tim.h:40:10: fatal error: 'mm32_device.h' file not found
40 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_uid.c...
../HAL_Lib/src/hal_uid.c(33): warning: In file included from...
../HAL_Lib/inc\hal_uid.h:39:10: fatal error: 'mm32_device.h' file not found
39 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling hal_usart.c...
../HAL_Lib/src/hal_usart.c(32): warning: In file included from...
../HAL_Lib/inc\hal_usart.h:35:10: fatal error: 'mm32_device.h' file not found
35 | #include "mm32_device.h"
| ^~~~~~~~~~~~~~~
1 error generated.
compiling system_mm32g0001.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/Source/system_mm32g0001.c'
ArmClang: error: no input files
assembling startup_mm32g0001_keil.s...
startup_mm32g0001_keil.s: error: A1023E: File "..\..\..\..\..\Device\MM32G0001\Source\KEIL_StartAsm\startup_mm32g0001_keil.s" could not be opened: No such file or directory
".\Objects\USART_Interrupt.axf" - 3 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:19
用讯飞星火注释错误:
从编译错误信息来看,主要问题是找不到头文件 "mm32_device.h"。请检查该头文件是否存在于正确的路径下,以及在项目中是否正确引用。
解决方案:找到移植例程,移植 mm32_device.h 到被移植程序:
找到了:
经过相同的方法,复制上上级文件包到移植程序文件包,
删除原来的mm32_device.h文件删除,添加新的mm32_device.h,
注意是选择All Files:
然后设置路径,再编译。得到的结果是:
具体报错:
Rebuild started: Project: USART_Interrupt
*** Using Compiler 'V6.21', folder: 'D:\Keil_v5\ARM\ARMCLANG\Bin'
Rebuild target 'USART_Interrupt'
compiling main.c...
../main.c(33): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h(43): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling mm32g0001_it.c...
../mm32g0001_it.c(33): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h(43): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling usart_interrupt.c...
../usart_interrupt.c(34): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h(43): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling platform.c...
../platform.c(34): warning: In file included from...
../platform.h(38): warning: In file included from...
../HAL_Lib/inc\hal_conf.h(43): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_adc.c...
../HAL_Lib/src/hal_adc.c(33): warning: In file included from...
../HAL_Lib/inc\hal_adc.h(40): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_crc.c...
../HAL_Lib/src/hal_crc.c(34): warning: In file included from...
../HAL_Lib/inc\hal_crc.h(38): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_dbg.c...
../HAL_Lib/src/hal_dbg.c(38): warning: In file included from...
../HAL_Lib/inc\hal_dbg.h(44): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_exti.c...
../HAL_Lib/src/hal_exti.c(38): warning: In file included from...
../HAL_Lib/inc\hal_exti.h(45): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_flash.c...
../HAL_Lib/src/hal_flash.c(33): warning: In file included from...
../HAL_Lib/inc\hal_flash.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_gpio.c...
../HAL_Lib/src/hal_gpio.c(33): warning: In file included from...
../HAL_Lib/inc\hal_gpio.h(38): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_i2c.c...
../HAL_Lib/src/hal_i2c.c(33): warning: In file included from...
../HAL_Lib/inc\hal_i2c.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_iwdg.c...
../HAL_Lib/src/hal_iwdg.c(33): warning: In file included from...
../HAL_Lib/inc\hal_iwdg.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_misc.c...
../HAL_Lib/src/hal_misc.c(33): warning: In file included from...
../HAL_Lib/inc\hal_misc.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_pwr.c...
../HAL_Lib/src/hal_pwr.c(34): warning: In file included from...
../HAL_Lib/inc\hal_pwr.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_rcc.c...
../HAL_Lib/src/hal_rcc.c(34): warning: In file included from...
../HAL_Lib/inc\hal_rcc.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_spi.c...
../HAL_Lib/src/hal_spi.c(34): warning: In file included from...
../HAL_Lib/inc\hal_spi.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_tim.c...
../HAL_Lib/src/hal_tim.c(33): warning: In file included from...
../HAL_Lib/inc\hal_tim.h(40): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_uid.c...
../HAL_Lib/src/hal_uid.c(33): warning: In file included from...
../HAL_Lib/inc\hal_uid.h(39): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling hal_usart.c...
../HAL_Lib/src/hal_usart.c(32): warning: In file included from...
../HAL_Lib/inc\hal_usart.h(35): warning: In file included from...
../Include\mm32_device.h(22): warning: In file included from...
../Include/mm32g0001.h:137:10: fatal error: 'core_cm0.h' file not found
137 | #include <core_cm0.h>
| ^~~~~~~~~~~~
1 error generated.
compiling system_mm32g0001.c...
ArmClang: error: no such file or directory: '../../../../../Device/MM32G0001/Source/system_mm32g0001.c'
ArmClang: error: no input files
assembling startup_mm32g0001_keil.s...
startup_mm32g0001_keil.s: error: A1023E: File "..\..\..\..\..\Device\MM32G0001\Source\KEIL_StartAsm\startup_mm32g0001_keil.s" could not be opened: No such file or directory
".\Objects\USART_Interrupt.axf" - 3 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:22
用讯飞星火注释:
这个编译错误是由于找不到'core_cm0.h'头文件导致的。你需要确保该头文件存在于你的项目中,并且路径设置正确。你可以尝试以下方法解决这个问题:
1. 确保'core_cm0.h'文件存在于你的项目中,如果没有,请从其他地方复制过来。
2. 检查项目设置中的头文件搜索路径,确保包含了'core_cm0.h'所在的目录。你可以在Keil中通过以下步骤检查和修改头文件搜索路径:
- 打开项目选项(Project -> Options for Target 'xxx')
- 在C/C++选项卡下,找到“Include Paths”设置
- 确保包含'core_cm0.h'所在目录的路径已添加或修改为正确的路径
3. 如果上述方法都无法解决问题,尝试将'core_cm0.h'文件复制到Keil安装目录下的相应文件夹中,例如:D:\Keil_v5\ARM\ARMCC\include。
还是缺少 core_cm0.h 文件,移植的方法解决:
找到了:
复制文件夹:
粘贴到:
点那个文件夹带加号的按钮,给文件夹起名,添加 core_cm0.h
移植后编译结果:
重复使用讯飞星火,注释错误:
这个编译错误是由于在usart_interrupt.c文件中,使用了strcpy函数,但没有包含<string.h>头文件。同时,还提示找不到system_mm32g0001.c文件和startup_mm32g0001_keil.s文件。
解决方法:
1. 在usart_interrupt.c文件的开头添加#include <string.h>。
2. 确保system_mm32g0001.c文件存在于正确的路径下,即Device/MM32G0001/Source/目录下。
3. 确保startup_mm32g0001_keil.s文件存在于正确的路径下,即Device/MM32G0001/Source/KEIL_StartAsm/目录下。
原因:
startup文件夹报错,移植可解决:
粘贴
重新编译:
点回文首,可以下载。
文末的话:在我开始时,移植是个难点,后来自己悟道了,分享给大家。