MDK4.x(uvision 4.x)开发STM32入门工程的错误排除
在工程中加入源程序main.c文件,源代码内容如下:
#include "stm32f10x_lib.h"
int main(void)
{
}
编译会出现错误,使得入门者难以继续深入学习STM32。
错误提示的全部信息如下:
test.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_md.o).
解决办法如下:
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
原来在复位中断服务函数里面,调用了SystemInit这个函数,而这个函数在.s文件里面没有定义。
所以解决的办法有两个。
1,在外部(其他任何.c文件里面)定义SystemInit这个函数,哪怕是个空函数也可以。
2,把
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
这三句话去掉。
例如,采用2方法,注释掉3行,改后为:
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
; IMPORT SystemInit
; LDR R0, =SystemInit
; BLX R0
LDR R0, =__main
BX R0
ENDP
保存后再编译就不会出现上面的错误了。
Reset_Handler
;
;
;
保存后再编译就不会出现上面的错误了。
(http://www.openedv.com/posts/list/3010.htm)
二、用stm32f10x.h文件时的问题
在工程中加入源程序main.c文件,源代码内容如下:
#include "stm32f10x.h"
int main(void)
{
}
编译会出现错误,使得入门者难以继续深入学习STM32。
错误提示的全部信息如下:
C:Keil_STM32ARMINCSTSTM32F10xstm32f10x.h(80): error:
解决办法如下:
右键点击工程名,选择第一个options for target ,下面选择C/C++,在define文本框中输入:STM32F10X_MD,USE_STDPERIPH_DRIVER即可。MD根据你选择的机种更换为LD或HD
(http://zhidao.baidu.com/link?url=erV1uOi-zVAWbRa6Af9OalKFHAVl1oVSY8CWVgPKqcBXFF_SX6Og4L0NfpD2fSpn2ARXzwd OEneefYD_N2gfaK)
再编译,会出现更多错误,例如:
error:#256: invalid redeclaration of type name "s32" (declared at line 470 of "C:Keil_STM32ARMINCSTSTM32F10xstm32f10x.h")
#256: invalid redeclaration of type name "sc32" (declared at line 474 of "C:Keil_STM32ARMINCSTSTM32F10xstm32f10x.h")
......
error:#101: "RESET" has already been declared in the current scope
error:#101: "SET" has already been declared in the current scope
......
error:#256: invalid redeclaration of type name "ErrorStatus" (declared at line 507 of "C:Keil_STM32ARMINCSTSTM32F10xstm32f10x.h")
warning:#47-D: incompatible redefinition of macro "HSE_Value" (declared at line 511 of "C:Keil_STM32ARMINCSTSTM32F10xstm32f10x.h")
解决办法:
打开stm32f10x_conf.h文件,将第21行的“#include "stm32f10x_type.h"”注释掉,再保存stm32f10x_conf.h文件,重新编译即可。
评论