keil jlink调试使用助手printf

利用JLINK实现printf功能。

主要是利用Jlink SW模式下自带的trace功能,使能Trace。点击Settings使能Trace。



新建头文件、源文件添加至工程:

头文件中添加:

#define ITM_Port8(n)    (*((volatile unsigned char*)(0xE0000000+4*n)))

#define ITM_Port16(n)   (*((volatile unsignedshort*)(0xE0000000+4*n)))

#define ITM_Port32(n)   (*((volatile unsigned long*)(0xE0000000+4*n)))

#define DEMCR           (*((volatile unsigned long*)(0xE000EDFC)))

#define TRCENA          0x01000000

源文件中添加:

#include "stdio.h"

struct __FILE { int handle; /* Add whateveryou need here */ };

FILE __stdout;

FILE __stdin;

int fputc(int ch, FILE *f) {

  if(DEMCR & TRCENA) {

   while (ITM_Port32(0) == 0);

   ITM_Port8(0) = ch;

  }

 return(ch);

}

接着,在工程打开view->serial windows->Debug (printf)viewer。

在程序中添加printf,则可在Debug(printf) Viewer中进行查看。


官方地址:

http://www.keil.com/support/man/docs/jlink/jlink_trace_itm_viewer.htm


猜你喜欢

转载自blog.csdn.net/bubuxindong/article/details/79317096