STM32keil5编译优化

STM32keil5编译优化
本来是写个IAP程序,Flash中只规划了4K字节,但是代码编写完后有6k,所以寻优化⽅案,优化完在1.7k左右。
STM32 keil5编译优化,可以勾选⼀下⼏项:
1、Options for Taeget-->Target
勾选使⽤微库
2、Options for Taeget-->Target
①选择优化级别Level 3(-O3)
②勾选One ELF Section per Function
3、关于One ELF Section per Function的作⽤特别说明下:
①编译器在处理⼀个 c ⽂件的时候呢,如果这个选项不选,那么这个C⽂件中的所有函数在编译后只会产⽣⼀个叫 .text 的输出节:
AREA ||.text||, CODE, READONLY, ALIGN=2
如果选了呢,那么每个函数将会产⽣⼀个输出节,如果你⽤C写了⼀个叫PRTL_HeadGet()的函数,那么编译器将会产⽣⼀个叫
i.PRTL_HeadGet 的输出节,具体如下:
AREA ||i.PRTL_HeadGet||, CODE, READONLY, ALIGN=2
PRTL_HeadGet PROC
勾选后,编译器产⽣的输出节,粒度⼩多了,便于到没有使⽤的函数,将它从最后输出⽂件中删除。这样,你最后产⽣的可执⾏⽂件⼤⼩将会变⼩。
②代码⼤⼩对⽐:
没勾选:Program Size: Code=4152 RO-data=216 RW-data=36 ZI-data=6148
勾选后:Program Size: Code=1376 RO-data=200 RW-data=0 ZI-data=6144
③map⽂件对⽐:
⼯程右击open map file.
没勾选:
Removing Unused input sections from the image.该部分内容是去除项⽬中没有使⽤的函数。没勾选前是按照⽂件优化的。
==============================================================================
Removing Unused input sections from the image.
Removing iap.o(.rev16_text), (4 bytes).
Removing iap.o(.revsh_text), (4 bytes).
Removing led.o(.rev16_text), (4 bytes).
Removing led.o(.revsh_text), (4 bytes).
Removing stm32f0xx_flash.o(.rev16_text), (4 bytes).
Removing stm32f0xx_flash.o(.revsh_text), (4 bytes).
Removing stm32f0xx_rcc.o(.rev16_text), (4 bytes).
Removing stm32f0xx_rcc.o(.revsh_text), (4 bytes).
Removing stm32f0xx_gpio.o(.rev16_text), (4 bytes).
Removing stm32f0xx_gpio.o(.revsh_text), (4 bytes).
Removing system_stm32f0xx.o(.rev16_text), (4 bytes).
Removing system_stm32f0xx.o(.revsh_text), (4 bytes).
Removing startup_stm32f030xc.o(HEAP), (512 bytes).
13 unused section(s) (total 560 bytes) removed from the image.
==============================================================================
勾选后:
看最后,94 unused section(s) (total 3760 bytes) removed from the image.由于每个函数⼀个输出节,所以优化是按照函数优化的,没有使⽤的函数都没有编译进去。⽽没有勾选时是按照⽂件优化的,只要该⽂件中有函数被使⽤,该⽂件中所有函数都会被编译进去。
Removing Unused input sections from the image.
Removing iap.o(.rev16_text), (4 bytes).
Removing iap.o(.revsh_text), (4 bytes).
Removing iap.o(i.IAP_Delay), (6 bytes).
Removing led.o(.rev16_text), (4 bytes).
Removing led.o(.rev16_text), (4 bytes).
Removing led.o(.revsh_text), (4 bytes).
Removing led.o(i.LEDTest), (42 bytes).
Removing led.o(i.LED_flash), (40 bytes).
Removing led.o(i.LED_temp_flash), (90 bytes).
Removing stm32f0xx_flash.o(.rev16_text), (4 bytes).
Removing stm32f0xx_flash.o(.revsh_text), (4 bytes).
Removing stm32f0xx_flash.o(i.FLASH_EraseAllPages), (52 bytes).
Removing stm32f0xx_flash.o(i.FLASH_GetFlagStatus), (20 bytes).
Removing stm32f0xx_flash.o(i.FLASH_GetPrefetchBufferStatus), (20 bytes).    Removing stm32f0xx_flash.o(i.FLASH_ITConfig), (24 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_BOOT0Config), (64 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_BOOT0SWConfig), (64 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_BOOTConfig), (64 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_EnableWRP), (140 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_Erase), (116 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_GetRDP), (20 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_GetUser), (16 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_GetWRP), (12 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_Launch), (20 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_Lock), (16 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_ProgramData), (56 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_RDPConfig), (92 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_SRAMParityConfig), (64 bytes).    Removing stm32f0xx_flash.o(i.FLASH_OB_Unlock), (32 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_UserConfig), (72 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_VDDAConfig), (64 bytes).
Removing stm32f0xx_flash.o(i.FLASH_OB_WriteUser), (60 bytes).
Removing stm32f0xx_flash.o(i.FLASH_PrefetchBufferCmd), (24 bytes).
Removing stm32f0xx_flash.o(i.FLASH_ProgramHalfWord), (52 bytes).
Removing stm32f0xx_flash.o(i.FLASH_SetLatency), (20 bytes).
Removing stm32f0xx_rcc.o(.rev16_text), (4 bytes).
Removing stm32f0xx_rcc.o(.revsh_text), (4 bytes).
Removing stm32f0xx_rcc.o(i.RCC_ADCCLKConfig), (44 bytes).
Removing stm32f0xx_rcc.o(i.RCC_AHBPeriphResetCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_APB1PeriphClockCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_APB1PeriphResetCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_APB2PeriphClockCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_APB2PeriphResetCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_AdjustHSI14CalibrationValue), (20 bytes).    Removing stm32f0xx_rcc.o(i.RCC_AdjustHSICalibrationValue), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_BackupResetCmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_CECCLKConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_ClearFlag), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_ClearITPendingBit), (12 bytes).
Removing stm32f0xx_rcc.o(i.RCC_ClockSecuritySystemCmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_DeInit), (92 bytes).
Removing stm32f0xx_rcc.o(i.RCC_GetClocksFreq), (376 bytes).
Removing stm32f0xx_rcc.o(i.RCC_GetFlagStatus), (52 bytes).
Removing stm32f0xx_rcc.o(i.RCC_GetITStatus), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_GetSYSCLKSource), (16 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HCLKConfig), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSEConfig), (16 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSI14ADCRequestCmd), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSI14Cmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSI48Cmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSI48Cmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_HSICmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_I2CCLKConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_ITConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_LSEConfig), (32 bytes).
Removing stm32f0xx_rcc.o(i.RCC_LSEDriveConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_LSICmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_MCOConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_PCLKConfig), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_PLLCmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_PLLConfig), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_PREDIV1Config), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_RTCCLKCmd), (28 bytes).
Removing stm32f0xx_rcc.o(i.RCC_RTCCLKConfig), (16 bytes).
Removing stm32f0xx_rcc.o(i.RCC_SYSCLKConfig), (20 bytes).
Removing stm32f0xx_rcc.o(i.RCC_USARTCLKConfig), (48 bytes).
Removing stm32f0xx_rcc.o(i.RCC_USBCLKConfig), (24 bytes).
Removing stm32f0xx_rcc.o(i.RCC_WaitForHSEStartUp), (44 bytes).
Removing stm32f0xx_rcc.o(.data), (16 bytes).
Removing stm32f0xx_gpio.o(.rev16_text), (4 bytes).
Removing stm32f0xx_gpio.o(.revsh_text), (4 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_DeInit), (112 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_PinAFConfig), (32 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_PinLockConfig), (26 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_ReadInputData), (4 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_ReadInputDataBit), (14 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_ReadOutputData), (4 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_ReadOutputDataBit), (14 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_StructInit), (24 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_Write), (4 bytes).
Removing stm32f0xx_gpio.o(i.GPIO_WriteBit), (12 bytes).
Removing system_stm32f0xx.o(.rev16_text), (4 bytes).
Removing system_stm32f0xx.o(.revsh_text), (4 bytes).
Removing system_stm32f0xx.o(i.SystemCoreClockUpdate), (108 bytes).    Removing system_stm32f0xx.o(.data), (20 bytes).
Removing startup_stm32f030xc.o(HEAP), (512 bytes).
94 unused section(s) (total 3760 bytes) removed from the image.

本文发布于:2024-09-25 02:19:57,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/95471.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:优化   没有   函数   编译   字节   勾选
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议