Keil debugging techniques and alternative printf (SWO function)

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.

# Define ITM_Port8 (n) (* ((volatile unsigned char *) (0xE0000000 +4 * n)))
# Define ITM_Port16 (n) (* ((volatile unsigned short *) (0xE0000000 +4 * n)))
# Define ITM_Port32 (n) (* ((volatile unsigned long *) (0xE0000000 +4 * n))) 

# Define DEMCR (* ((volatile unsigned long *) (0xE000EDFC)))
# 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.

struct __ FILE
{ int handle; / * Add whatever you need here * /};
FILE __ stdout;
FILE __ stdin;

int fputc( int ch, FILE * f )
{
  if ( DEMCR & TRCENA )
  {
    the
    while ( ITM_Port32( 0 ) == 0 )
      ;
    ITM_Port8( 0 ) = CH;
  }
  return ( ch );
}

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

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.

时间: 2024-10-12 17:24:15

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

<Debugging Techniques> LDD3 学习笔记

Debugging Techniques 内核debug的挑战: Kernel programming brings its own, unique debugging challenges. Kernel code can not be easily executed under a debugger, nor can it be easily traced, because it is a set of functionalities not related to a specific pr

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

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

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

Proteus是一个仿真软件,可以在里面设计电路并模拟测试,也可生成PCB的布线等等,反正就是强大的不行.初学单片机,除了开发板,这个仿真器就是一个很好的调式环境.软件安装信息: Proteus 8.7 Keil uvision4 Window 10 很多人说window10安装不成功,其他还好,刚开始装Proteus 8.7,出现了一个缺少hhctrl.ocx的组件,下载后注册,就好了.其他安装不再说明,没有什么大问题.目前Keil和Proteus联调成功: 代码如下所示: /*-------

Debugging QML Applications

Debugging QML Applications Console API Log console.log, console.debug, console.info, console.warn and console.error can be used to print debugging information to the console. For example: function f(a, b) { console.log("a is ", a, "b is &qu

c51 printf的用法

keil的官方网站关于printf的参考 http://www.keil.com/support/man/docs/c51/c51_printf.htm

【转】用宏定义代替printf函数

问题提出 有时候我们想用宏定义来决定是编译debug版本的代码还是release的代码,dubug版本的代码会通过printf打印调试信息,release版本的代码则不会.我们总不能对每一条printf都这样写: 1 #if _DEBUG_ 2 printf("hello world!"); 3 #endif 这样子实在是太麻烦了!万一要各个地方都要打印,会使版面看起来很乱. 解决方法 我后来想到一个方法,可以使用宏定义代替printf函数,由于printf是可变参数的函数,这里就要用

Linux Kernel - Debug Guide (Linux内核调试指南 )

http://blog.csdn.net/blizmax6/article/details/6747601 linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一部分:基础知识*** 总纲:内核世界的陷阱 源码阅读的陷阱 代码调试的陷阱 原理理解的陷阱 建立调试环境 发行版的选择和安装 安装交叉编译工具 bin工具集的使用 qemu的使用 initrd.img的原理与制作 x86虚拟调试环境的建立 arm虚拟调试环境的建立 arm开发板调试环

Making your first driver - complete walkthrough(使用VisualDDK)

This article describes how to create, build and debug your first driver using Visual Studio and VisualDDK. It provides detailed step-by-step instructions on using the development and debugging tools, leaving the driver API and architecture descriptio

linux内核调试指南

linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一部分:基础知识*** 总纲:内核世界的陷阱 源码阅读的陷阱 代码调试的陷阱 原理理解的陷阱 建立调试环境 发行版的选择和安装 安装交叉编译工具 bin工具集的使用 qemu的使用 initrd.img的原理与制作 x86虚拟调试环境的建立 arm虚拟调试环境的建立 arm开发板调试环境的建立 gdb基础 基本命令 gdb之gui gdb技巧 gdb宏 汇编基础--X86篇 用户手册 AT&