keil 局部变量不能查看值,显示为not in scope
用MDK调试一块STM32F207的程序,想查看一下变量却发现watch窗口总是
<not in scope>和<cannot evaluate>,无奈凑合着通过printf函数进行串口打印查看。
后来实在受不了,想了一下,觉得应该是编译器把这个局部变量给优化掉了,并没有在内存中生成,果断把优化级别改为Level 0,重新编译,解决。
Getting the Best Optimized Code for your Embedded Application
ARM Compilation Tools
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
own ELF section in the corresponding object file. This option is also known as Linker Feedback, and requires you to
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
standard C runtime library, and offers a tradeoff between functionality and code size. Some of the standard C library
functions such as memcpy() are slower, while some features of the default library are not supported. Unsupported
features include:
o Operating system functions e.g. abort(), exit(), time(), system(), getenv(),
o Wide character and multi-byte support e.g. mbtowc(), wctomb()
o The stdio file I/O function, with the exception of stdin, stdout and stderr
o Position-independent and thread -safe code
Use the MicroLIB C library for applications where overall performance can be traded off against the need to reduce code
size and memory cost.
• Link- Time Code Generation instructs the compiler to create objects in an intermediate format so that the linker can
perform further code optimizations. This gives the code generator visibility into cross - file dependencies of all objects
simultaneously, allowing it t o apply a higher level of optimizations. Link -time code generation can reduce code size, and
allow your application to run faster.
• Optimization Levels can also be adjusted. The different levels of optimization allow you to trade off between the level
of debug information available in the compiled code, and the performance of the code. The following optimization levels
are available:
o - O0 applies minimum optimizations.
Most optimizations are switched off, and the code generated has the best debug view.
o - O1 applies restricted optimization.
For example, unused inline functions and unused static functions are removed. At this level of optimization, the
compiler also applies automatic optimizations such as removing redundant code and re -ordering instructions s o
as to avoid an interlock situation. The code generated is reasonably optimized, with a good debug view.
o - O2 applies high optimization (This is the default setting).
Optimizations applied at this level take advantage of ARM’s in-depth knowledge of the processor architecture,
to exploit processor -specific behavio r of the given target. It generates well optimized code, but with limited
debug view.
o - O3 applies th e most aggressive optimization.
The optimization is in accordance with the user’s – Ospace/- Otime choice . By default, multi - file compilation is
enabled, which leads to a longer compile time, but gives the highest levels of optimization.
• The Optimize for Time checkbox causes the compiler to optimize with a greater focus on achieving the best
performance when checked ( - O time) or the smallest code siz e when unchecked ( -O space).
Unchecking Optimize for Time selects the – Ospace option which instructs the compiler to perform optimizations to
reduce the image size at the expense of a poss ible increase i n execution time. F or example, using out -of -line function
calls instead of inline code for large structure copies. This is the default option. When running the compiler from the
command line, this option is invoked using ‘ -Ospace’
Checking Optimize for Time selects the – Otime option which instructs the compiler to optimize the code for the fastest
execution time, at the risk of an increase in the image size. It is recommended that you compile the time -critical parts of
your code with – Otime, and the rest us ing the – Ospace directive .
• Split Load and Store Multiples instructs the compiler to split LDM and STM instructions involving a large number of
registers into a series of loads/stores of fewer multiple registers. This means that an LDM of 16 registers can be split into
4 separate LDMs of 4 registers each. This option helps to reduce the interrupt latency on ARM systems which do not
have a cache or write buffer, and systems which use zero - wait state 32-bit memory.
For example, the ARM7 and ARM9 processor s t ake can only take an exception on an instruction boundary. If an
exception occurs at the start of an LDM of 16 registers in a cacheless ARM7 /ARM9 system, the system will finish
making 16 accesses to memory before taking the exception. Depending on the memory arbitration system, this can result
in a very high interrupt latency. Breaking the LDM into 4 individual LDMs for 4 registers means that the processor will
take the exception after loading a maximum of 4 registers, thereby greatly reducing the interrupt latency.
Selecting this option improves the overall performance of the system.
• The One ELF Section per Function option tells the compiler to put all functions into their own individual ELF
sections. This allows the linker to remove unused functions.
An ELF code section typically contains the code for a number of functions. The linker is normally only able to remove
unused ELF sections, not unused functions. An ELF section can only be removed if all its contents are unused.
Therefore, splitting each function into its own ELF section allows the compiler to easily identify which ones are unused,
and remove them.
Selecting this option increases the time required to compile your code, but results in improved performance .
The combination of options applied will depend on your optimization goal – whether you are optimizing for smallest code
size, or best performance.
The next section illustrates the best optimization options for each of these goals.
Optimizing for Smallest Code Size
To optimize your code for the smallest size, the best options to apply are:
• The MicroLIB C library
• Cross- module optimization
• Optimization level 2 ( -O2)
Compile the Measure example without any optimizations
The Measure example uses analog and digital inputs to simulate a data l ogger.
File -- Open Project
C: \Keil \ARM\Boards \Keil \MCBSTM32\Measure\Measure.uv2
Click the Options for Target button
In the Target tab:
• Uncheck Cross- Module Optimization
• Uncheck Use MicroLIB
• Uncheck Use Link- Time Code Generation
In the C/C++ tab:
• Set Optimization Level to Zero
Then click OK to save your changes.
Project – Build target
Without any compiler optimizations applied, the initial code size is 13,656 Bytes.
MDK Compiler Optimizations
Optimize the Measur e example for Size
Apply the compiler optimizations in turn, and re-compile each time to see their effect in reducing the code size for the
example.
• Options for Target – Target tab: Use the MicroLIB C library
• Options for Target – Target tab: Use cross - mod ule optimization - Remember to compile twice
• Options for Target – C/C++ tab: Enable Optimization level 2 ( -O2)
Optimization Applied Compile Size Size Reduction Improvement
MicroLIB C library 8,960 Bytes 4,696 Bytes 34% smaller
Cross- Module Compilation 13,500 Bytes 156 Bytes 1.1% smaller
Optimization level – O2 12,936 Bytes 720 Bytes 5.3% smaller
All 3 optimization options 8,116 Bytes 5,540 Bytes 40.6% smaller
Applying all the optimizations will reduce the code size down to 8,116 Bytes.
The fully optimized code is 5,540 Bytes smaller, a total code size reduction of 40.6%
MDK Compiler Optimizations
Optimizing for Best Performance
To optimize your code for performance, the best options to apply are:
• Cross- module optimization
• Optimization level 3 ( -O3)
• Optimize for time
Run the Dhrystone benchmark without any optimizations
The Dhrystone benchmark is used to measure and compare the performance of different computers, or the efficiency of the
code generated for the same computer by different compilers.
File – Open Project
C: \Keil \ARM\Examples \DHRY \DHRY.uv2
Click the Options for Target button
Turn off optimization settings in the Target and C/C++ tabs , then click OK
Project – Build target
Enter D ebug mode
View – Se rial Windows – UART #1
Open the UART #1 window
View – Analysis Windows – Performance Analyzer
Open the Performance Analyzer
Debug – Run
Start running the application
When prompted:
Enter 50000 in the UART#1 window and press Enter
In the Performance Analyzer window, note that
• The drhy_1 loop took 2.829s
• The dhry_2 took 2.014s
In the UAR T #1 window, note that
• It took 138.0 ms for 1 run through Dhrystone
• The application is executing 7246.4 Dhrystones per second
Optimize the Dhrystone example for Performance
Re-compile the example with all three of the following optimizations applied:
• Options f or Target – Target tab: Cross - module optimization – Remember to compile twice
• Options for Target – C/C++ tab: Optimization level 3 ( -O3)
• Options for Target – C/C++ tab: Optimize for Time
Re-run the application, and examine the performance.
Measurement Without optimizations With Optimizations Improvement
dhry_1 2.829s 1.695s 40.1% faster
dhry_2 2.014s 1.011s 49.8% faster
Microseconds for 1 run
through Dhrystone
138.0 70 49.3% faster
Dhrystones per second 7246.4 14,285.7 97.1% more
The fu lly optimize d code achieves approximate ly 2x the performance of the un -optimized code.
Summary
The ARM Compilation Tools offer a range of options to apply when compiling your code. These options can be combined to
optimize your code for best performance, for smallest code size, or for any performance point between these two extremes, to
best suit your targeted microcontroller device and market.
When optimizing your code, MDK- ARM makes it easy and convenient to measure the effect of the different optimization
sett ings on your application. The code size is clearly displayed after compilation, and a range of analysis tools such as the
Performance Analyzer enable you to measure performance.
The optimization options in the ARM Compilation Tools, together with the easy- to - use analysis tools in MDK - ARM, help
you to easily optimize your application to meet your specific requirements.
keil 局部变量不能查看值,显示为not in scope相关推荐
- 打开计算机 硬盘显示空白,电脑上文件夹的查看选项显示空白如何解决
电脑上文件夹的查看选项显示空白如何解决 腾讯视频/爱奇艺/优酷/外卖 充值4折起 我们在使用电脑的时候,总会遇到这样那样的问题,今天就跟大家介绍一下电脑上文件夹的查看选项显示空白的具体解决方法. 1. ...
- python包NiBabel对医学影像文件格式进行读写并可视化实战:查看和显示.nii.gz、.nii文件
python包NiBabel对医学影像文件格式进行读写并可视化实战:查看和显示.nii.gz..nii文件 目录 python包NiBabel对医学影像文件格式进行读写并可视化实战:查看和显示.nii ...
- C#之windows桌面软件第十二课:电脑ADC值显示(上位机),记忆上次串口号,并用TrackBar控件显示ADC值
C#之windows桌面软件第十二课:电脑ADC值显示(上位机),记忆上次串口号,并用TrackBar控件显示ADC值 using System; using System.Collections.G ...
- C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示)
C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示) using System; using System.Collections.Generic; using System ...
- C#之windows桌面软件第十课:电脑ADC值显示(上位机)(单通道显示)
C#之windows桌面软件第十课:电脑ADC值显示(上位机) (单通道显示) using System; using System.Collections.Generic; using System ...
- 查看mysql数据库的主机_MySQL查看或显示数据库(SHOW DATABASES语句)
数据库可以看作是一个专门存储数据对象的容器,每一个数据库都有唯一的名称,并且数据库的名称都是有实际意义的,这样就可以清晰的看出每个数据库用来存放什么数据.在 MySQL 数据库中存在系统数据库和自定义 ...
- 3、MySQL查看或显示数据库(SHOW DATABASES语句)
数据库可以看作是一个专门存储数据对象的容器,每一个数据库都有唯一的名称,并且数据库的名称都是有实际意义的,这样就可以清晰的看出每个数据库用来存放什么数据.在 MySQL 数据库中存在系统数据库和自定义 ...
- OpenCASCADE绘制测试线束:图形命令之AIS 查看器——显示命令
OpenCASCADE绘制测试线束:图形命令之AIS 查看器--显示命令 vdisplay vdonly vdisplayall verase veraseall vsetdispmode vdisp ...
- ajax后台返回数据中文乱码_解决Jmeter返回值显示中文乱码 的三种方法及设置随机动态参数(非原创侵删)...
一.Jmeter返回值显示中文乱码解决方法 第一种解决方法: 1. 点击线程组--添加--后置处理器--BeanShell后置处理程序 2.点击BeanShell后置处理程序,编写:prev.setD ...
最新文章
- 三甲医院副主任博士医师,工资竟然不如程序员老公的一半!
- xmpp这一段蛋疼的 坑,
- python基础语法第10关作业-Python基础作业一
- onInterceptTouchEvent和onTouchEvent调用时序
- maven 打包时缺少文件_解决Intellij Idea下使用Maven项目打包时部分文件缺失问题
- IDEA 点击进入方法内部_【推荐收藏】IDEA的Debug调试,你全会用么?
- python更新到什么版本_Linux更新Python版本及修改python默认版本的方法
- Kafka史上最详细总结
- 一个程序员年近四十岁的一些胡思乱想
- 深入解析 Go 中 Slice 底层实现
- java获取元素创建时间,java – 动态顺序统计:在恒定时间内获取第k个元素?
- xxx is not mapped 错误 解决方案
- hssfwork 导出excel 文件已损坏_C# NPOI 操作EXCEL文件的读取和导出
- 计量语言学软件Altmann-Fitter阿尔特曼拟合器的使用简介(更新中)
- halcon 计算图像的反余弦值:acos_image
- 七彩虹计算机主板维修,七彩虹C .H61U v28主板维修一例
- DXP 内电层GND和POWER出现的死铜如何去除
- 帷幕的帷是什么意思_《老酒馆》热播背后:你真的看明白大戏背后的意思了吗?...
- 刘海洋《LaTex入门》学习笔记5
- mysql在GROUP_CONCAT中拼接字符串