One of the basic needs of the embedded software development through the terminal to output debugging information, generally two ways to achieve:

one is the COM port on the UART and PC using a serial cable connecting plate through the PC HyperTerminal to view the debugging information;

Another mechanism is the use of semi-host, but it may not be used in tool chain support.

Cortex-M3 core-based software debug break this limit, the Cortex-M3 core provides

a ITM (Instrumentation TraceMacrocell) interface debugging theITM data received by the SWO pin SWV (Serial Wire Viewer).

ITM 32 common data channel, based on the implementation the CMSIS requirements as the debugging output terminal to output debugging information,

channel 31 for the operating system (privileged mode access) channel 0.

In core_cm3 h the defined ITM_SendChar () function by calling the function to rewrite fputc print debugging information in the application by printf,

these debugging information can be viewed by the ITM Viewer.

With this implementation, embedded software developers can not configure the serial port

and use the terminal debugging software output debugging information to some extent reduce the workload. 
 
Basic concepts:

SWD 
The J-Link and J-Trace support ARMs Serial WireDebug (SWD).

SWD replaces the 5-pin JTAG port with a clock (SWDCLK) and a single bi-directional data pin (SWDIO),

providing all thenormal JTAG debug and testfunctionality.

Pin 13 of SWD: 
SWO - Serial Wire Output trace port. (Optional, not required for SWD communication.) 
 
SWO 
J-Link can be used with devices that supportSerial Wire Output (SWO).

Serial Wire Output (SWO) support meanssupport for a single pin output signal from the core. It iscurrently tested with Cortex-M3 only. 
 
SWV 
The Instrumentation Trace Macrocell (ITM) andSerial Wire Output (SWO) can be used to form a Serial Wire Viewer (SWV).

The Serial Wire Viewer provides a low cost method ofobtaining information from inside the MCU.

The SWO can output tracedata in two output formats, but only one output mechanism is validat any one time.

The 2 defined encodings are UART and Manchester.

The current J-Link implementation only supports UART encoding.

Serial Wire Viewer uses the SWO pin to transmit different packetsfor different types of information.

The three sources in theCortex-M3 core which can output information via this pinare:

- Instrumentation Trace Macrocell (ITM) forapplication-driven trace source that supports printf-styledebugging.
It supports 32 different channels, which allow it to beused for other purposes such as real-time kernel information aswell.

- Data Watchpoint and Trace (DWT) for real-timevariable monitoring and PC-sampling,
which can in turn be used toperiodically output the PC or various CPU-internal counters,
whichcan be used to obtain profiling information from thetarget.

- Timestamping. Timestamps are emitted relative topackets. 
 Debug (printf) Viewer

Home »?Vision Windows >> Debug (printf) Viewer 
The Debug (printf) Viewer window displays data streams that are transmitted sequentially through the ITM Stimulus Port 0. Enable ITM Stimulus Port 0.

Debug Viewer window

To use the Debug (printf) Viewer for tracing:

1. Add ITM Port register definitions to your source code.

  1. # Define ITM_Port8 (n) (* ((volatile unsigned char *) (0xE0000000 + * n)))
  2. # Define ITM_Port16 (n) (* ((volatile unsigned short *) (0xE0000000 + * n)))
  3. # Define ITM_Port32 (n) (* ((volatile unsigned long *) (0xE0000000 + * n)))
  4.  
  5. # Define DEMCR (* ((volatile unsigned long *) (0xE000EDFC)))
  6. # Define TRCENA 0x01000000

2. Add an fputc function to your source code that writes to the ITM Port 0 register. The fputc function enables printf to output messages.

  1. struct __ FILE
  2. { int handle; / * Add whatever you need here * /};
  3. FILE __ stdout;
  4. FILE __ stdin;
  5.  
  6. int fputc( int ch, FILE * f )
  7. {
  8. if ( DEMCR & TRCENA )
  9. {
  10. the
  11. while ( ITM_Port32( ) == )
  12. ;
  13. ITM_Port8( ) = CH;
  14. }
  15. return ( ch );
  16. }

3.Add your debugging trace messages to your source code using printf.

  1. printf ("AD value = 0x% 04X \ r \ n", AD_value);

4.Set the ITM Port 0 to capture the information. Clear the Port 7 .. 0 privilege bit to access ITM Port 0 from User mode.

ITM Stimulus Port 0 
Open the View - Serial Windows - Debug (printf) Viewer window.

Note

ITM Stimulus Ports can be monitored in the Instruction Trace Window, where ITM Port 0 is shown as well. 
Consult Configure Cortex-M Target of the MDK-Primer for information on how to retarget the output.

Keil debugging techniques and alternative printf (SWO function)的更多相关文章

  1. <<linux device driver,third edition>> Chapter 4:Debugging Techniques

    Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...

  2. 在keil中使用printf()函数的要点

    在keil中printf默认是向串口中发送数据的,所以,如果应用该函数,必须先初始化串口,否则可能引起死机的情况,并且在printf之前应该先将TI置位,摘抄原因如下: 1.printf函数是调用pu ...

  3. printf in KEIL C51

    转自:http://blog.csdn.net/it1988888/article/details/8821713 在keil中printf默认是向串口中发送数据的,所以,如果应用该函数,必须先初始化 ...

  4. Keil C51 的printf

    转自:http://blog.csdn.net/zhanglianpin/article/details/44779009 在Keil C51 中使用printf ,首先需要重新实现 putchar( ...

  5. 使用printf函数实现串口信息打印——设置IAR和Keil的Options

    在Keil和IAR中都可以使用printf函数,但两者设置的方法不一样.以下分别是IAR和Keil的设置. 下面是Keil的设置. 选中Options--->Target--->Code ...

  6. AMD64 Instruction-Level Debugging With dbx

    http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/amd64-dbx-364568.html A ...

  7. STM32F103C8T6最小板搞定CMSIS-DAP和SWO功能

    转载:http://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=616081&extra=page%3D&am ...

  8. 初学单片机:Proteus介绍、Proteus与Keil联调(Windows10环境下)

    Proteus是一个仿真软件,可以在里面设计电路并模拟测试,也可生成PCB的布线等等,反正就是强大的不行.初学单片机,除了开发板,这个仿真器就是一个很好的调式环境.软件安装信息: Proteus 8. ...

  9. Named function expressions demystified

    Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...

随机推荐

  1. MFS - MooseFS 文件系统

    MFSMooseFS 文件系统 可以实现RAID 功能:节约成本 实现在线扩展:是一种半分布式文件系统. 一.MFS文件系统的组成 1.mfsmaster 元数据服务器. 在整个体系中负责管理管理文件 ...

  2. C# UDP广播消息

    首先是发送端: /// <summary> /// 发送UDP消息 /// </summary> /// <param name="msg">消 ...

  3. 错误的理解引起的bug async await 执行顺序

    今天有幸好碰到一个bug,让我知道了之前我对await async 的理解有点偏差. 错误的理解 之前我一直以为  await 后面的表达式,如果是直接返回一个具体的值就不会等待,而是继续执行asyn ...

  4. day17作业

    1.java.util  2.队列先进先出,栈堆先进后出   3.链表  4.LinkedList  5.TreeSet  6.Comparable  7.Map  8.next() 1.AC 2.A ...

  5. 字符串前面加u、r、b的含义

    u/U:表示unicode字符串 不是仅仅是针对中文, 可以针对任何的字符串,代表是对字符串进行unicode编码. 一般英文字符在使用各种编码下, 基本都可以正常解析, 所以一般不带u:但是中文, ...

  6. LeetCode(20):有效的括号

    Easy! 题目描述: 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭 ...

  7. C++ code:动态内存

    C++给我们提供了动态内存分配的new和delete操作.一般而论,new和delete操作多用在内存需求捉摸不定的场合.然而,需要处理的数据,如果变动范围很小,我们可以用STL中通用型的容器来做,大 ...

  8. GeoHash解析及java实现

    GeoHash解析请参考这里: http://www.open-open.com/lib/view/open1417940079964.html java实现GeoHash,代码已注释. import ...

  9. hadoop2.5搭建过程

    1 搭建环境所使用的资源 VMware Workstation 9 ubuntu-14.04.2-desktop-amd64.iso jdk-7u80-linux-x64.tar.gz hadoop- ...

  10. bzoj 1151: [CTSC2007]动物园zoo

    思路:因为每个人最多只能看到五个动物,我们考虑将其状压,f[ i ][ s ] 表示到了第 i 个位置, i, i + 1, i + 2, i + 3, i + 4这四个动物的状态为s, 此时的最大值 ...