最近发现在keil编译的时候,出现莫名的问题,貌似代码有被优化掉的问题,后来查了下相关的资料,貌似懂了点。
我选择的是默认的default优化方式,上网看了下,默认的是level2级别优化,最后选择level0就没有问题了
下面是网上找的资料,介绍了优化功能介绍
Getting the Best Optimized Code for your Embedded Application
The ARM Compilation Tools are the only compilation tool s co -developed with the ARM processors, and specifically
designed to optimally support the ARM architecture. They are a result of 20 years of development, and are recognized as the
industry -leading C and C++ compilation tools for the ARM, Thumb, and Thumb -2 instructions sets.
The ARM Compilation tools consist of:
• The ARM Compiler, which enables you to compile C and C++ code. It is an optimizing compiler, and features
command - line options to enable you to control the level of optimization
• Linker and Utilities, which assign addresses and lay out sections of code to form a final image
• A selection of libraries, including the ISO standard C libraries, and the MicroLIB C library which is optimized for
embedded applications
• Assembler, which generates machine code instructions from ARM, Thumb or Thumb-2 assembly- level source code
Compiler Options for Embedded Applications
The ARM Compilation Tools include a number of compiler optimizations to help you best target your code for your chosen
microcontroller device and application area.
They can be accessed from within µVision by clicking on Project – Options for Target.
T he options described this document can be found on the Target an d C/C++ tabs of the Options for Targets dialog.
MDK Compiler Optimizations
• Cross- Module
Optimization takes information from a prior build and uses it to place UNUSED functions into their
build your application twice to take adv antage of it for reduced code size.
Cross-Module Optimization has been shown to reduce code size, by removing unused functions from your application. It
can also improve the performance of your application, by allowing modules to share inline code.
• The M icroLIB C library
has been optimized to reduce the size of embedded applications. It is a subset of the ISO
functions such as memcpy() are slower, while some features of the