Keil ARM-CM3 printf輸出調試信息到Debug (printf) Viewer

參考資料:http://www.keil.com/support/man/docs/jlink/jlink_trace_itm_viewer.htmspa

 

 

1.Target Options -> Debug -> Settings(JLink) -> Debug裏ort選擇SW模式code

2.在Target Options -> Debug -> Settings(JLink) -> Trace裏選擇Enablehtm

3.Core freq設爲120MHz(以LPC1788爲例)blog

4. 設置ITM Port的值以下所示get

5.在工程中添加.c文件以下it

#include "stdio.h"

#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

struct __FILE { int handle; /* Add whatever you 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);
}

6.用Debug模式運行工程,Debug (printf) Viewer中便可以查看printf的輸出信息。io

相關文章
相關標籤/搜索