stm32在MDK环境下重新建工程,文件夹以及相应文件夹的文件都相同,但是不知道为啥编译完成后代码长度变长

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了stm32在MDK环境下重新建工程,文件夹以及相应文件夹的文件都相同,但是不知道为啥编译完成后代码长度变长相关的知识,希望对你有一定的参考价值。

stm32重建工程代码长度变长

可能是新建工程的时候MDK把默认的优化率给改变了。
可以按以下操作修改编译器的优化率:
project->options for target->C/C++,那里有个optimization,level 0优化率最低,编译后代码最大,level 4优化率最大,代码最小,一般咱们选defualt默认即可。

ps:不过楼主要先确保您的MDK已经破解了,不然optimization这个选项是不可选的。
参考技术A 如果变动的不是特别多的话应该是没有问题的 编译器在编译的时候会对代码进行优化操作 可能编译的顺序不一样了 所以优化的方式也不一样了 导致代码长度有所变化本回答被提问者采纳

keil 4.22 MDK 建工程时出现的重定义错误

在更新官方的STM32 官方库3.5版本的函数库后,建立工程时会出现诸多重定义错误,例如:

D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(23): error:  #256: invalid redeclaration of type name "s32" (declared at line 487 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(27): error:  #256: invalid redeclaration of type name "sc32" (declared at line 491 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(31): error:  #256: invalid redeclaration of type name "vs32" (declared at line 495 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(35): error:  #256: invalid redeclaration of type name "vsc32" (declared at line 499 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(39): error:  #256: invalid redeclaration of type name "u32" (declared at line 503 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(43): error:  #256: invalid redeclaration of type name "uc32" (declared at line 507 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(47): error:  #256: invalid redeclaration of type name "vu32" (declared at line 511 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(51): error:  #256: invalid redeclaration of type name "vuc32" (declared at line 515 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "RESET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "SET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "DISABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "ENABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "ERROR" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "SUCCESS" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #256: invalid redeclaration of type name "ErrorStatus" (declared at line 524 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_conf.h(147): warning:  #47-D: incompatible redefinition of macro "HSE_Value" (declared at line 528 of ".\\CM3\\stm32f10x.h")
user\\main.c(30): error:  #20: identifier "GPIO_InitTypeDef" is undefined
user\\main.c(53): warning:  #223-D: function "RCC_APB2PeriphClockCmd" declared implicitly
user\\main.c(53): error:  #20: identifier "RCC_APB2Periph_GPIOB" is undefined
user\\main.c(53): error:  #20: identifier "RCC_APB2Periph_GPIOD" is undefined
user\\main.c(55): error:  #20: identifier "GPIO_Pin_5" is undefined
user\\main.c(56): error:  #20: identifier "GPIO_Mode_Out_PP" is undefined
user\\main.c(57): error:  #20: identifier "GPIO_Speed_50MHz" is undefined
user\\main.c(58): warning:  #223-D: function "GPIO_Init" declared implicitly
user\\main.c(60): error:  #20: identifier "GPIO_Pin_6" is undefined
user\\main.c(60): error:  #20: identifier "GPIO_Pin_3" is undefined
user\\main.c(66): error:  #20: identifier "GPIO_Pin_13" is undefined
user\\main.c(70): warning:  #223-D: function "GPIO_ResetBits" declared implicitly
user\\main.c(88): warning:  #223-D: function "GPIO_SetBits" declared implicitly
user\\main.c(88): error:  #20: identifier "GPIO_Pin_5" is undefined
user\\main.c(88): warning:  #223-D: function "GPIO_ResetBits" declared implicitly
user\\main.c(88): error:  #20: identifier "GPIO_Pin_6" is undefined
user\\main.c(88): error:  #20: identifier "GPIO_Pin_3" is undefined
compiling stm32f10x_rcc.c...
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(23): error:  #256: invalid redeclaration of type name "s32" (declared at line 487 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(27): error:  #256: invalid redeclaration of type name "sc32" (declared at line 491 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(31): error:  #256: invalid redeclaration of type name "vs32" (declared at line 495 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(35): error:  #256: invalid redeclaration of type name "vsc32" (declared at line 499 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(39): error:  #256: invalid redeclaration of type name "u32" (declared at line 503 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(43): error:  #256: invalid redeclaration of type name "uc32" (declared at line 507 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(47): error:  #256: invalid redeclaration of type name "vu32" (declared at line 511 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(51): error:  #256: invalid redeclaration of type name "vuc32" (declared at line 515 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "RESET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "SET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "DISABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "ENABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "ERROR" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "SUCCESS" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #256: invalid redeclaration of type name "ErrorStatus" (declared at line 524 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_conf.h(147): warning:  #47-D: incompatible redefinition of macro "HSE_Value" (declared at line 528 of ".\\CM3\\stm32f10x.h")
compiling stm32f10x_gpio.c...
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(23): error:  #256: invalid redeclaration of type name "s32" (declared at line 487 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(27): error:  #256: invalid redeclaration of type name "sc32" (declared at line 491 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(31): error:  #256: invalid redeclaration of type name "vs32" (declared at line 495 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(35): error:  #256: invalid redeclaration of type name "vsc32" (declared at line 499 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(39): error:  #256: invalid redeclaration of type name "u32" (declared at line 503 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(43): error:  #256: invalid redeclaration of type name "uc32" (declared at line 507 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(47): error:  #256: invalid redeclaration of type name "vu32" (declared at line 511 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(51): error:  #256: invalid redeclaration of type name "vuc32" (declared at line 515 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "RESET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "SET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "DISABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "ENABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "ERROR" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "SUCCESS" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #256: invalid redeclaration of type name "ErrorStatus" (declared at line 524 of ".\\CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_conf.h(147): warning:  #47-D: incompatible redefinition of macro "HSE_Value" (declared at line 528 of ".\\CM3\\stm32f10x.h")
compiling system_stm32f10x.c...
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(23): error:  #256: invalid redeclaration of type name "s32" (declared at line 487 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(27): error:  #256: invalid redeclaration of type name "sc32" (declared at line 491 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(31): error:  #256: invalid redeclaration of type name "vs32" (declared at line 495 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(35): error:  #256: invalid redeclaration of type name "vsc32" (declared at line 499 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(39): error:  #256: invalid redeclaration of type name "u32" (declared at line 503 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(43): error:  #256: invalid redeclaration of type name "uc32" (declared at line 507 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(47): error:  #256: invalid redeclaration of type name "vu32" (declared at line 511 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(51): error:  #256: invalid redeclaration of type name "vuc32" (declared at line 515 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "RESET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #101: "SET" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(57): error:  #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "DISABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #101: "ENABLE" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(59): error:  #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "ERROR" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #101: "SUCCESS" has already been declared in the current scope
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_type.h(62): error:  #256: invalid redeclaration of type name "ErrorStatus" (declared at line 524 of "CM3\\stm32f10x.h")
D:\\Keil2\\ARM\\INC\\ST\\STM32F10x\\stm32f10x_conf.h(147): warning:  #47-D: incompatible redefinition of macro "HSE_Value" (declared at line 528 of "CM3\\stm32f10x.h")

解决办法:

在官方给的函数库头文件路径(C:\\Users\\admin\\Desktop\\ARM3\\FWlib\\inc   )下 加入stm32f10x_conf.h头文件  下载链接(http://download.csdn.net/detail/xiaoleiacm/7134683)  

重新编译即可。

其他原因参照 http://blog.csdn.net/iceiilin/article/details/6100494

以上是关于stm32在MDK环境下重新建工程,文件夹以及相应文件夹的文件都相同,但是不知道为啥编译完成后代码长度变长的主要内容,如果未能解决你的问题,请参考以下文章

初识STM32--MDK5下使用V3.5库新建工程

STM32开发环境--使用MDK建立一个工程

STM32开发环境--使用MDK建立一个工程

MDK524a新建STM32工程--标准外设库V3.5

STM32F407开发板用户手册第4章 STM32F407工程模板建立(MDK5)

STM32F407开发板用户手册第4章 STM32F407工程模板建立(MDK5)