MDK 下使用 JLink ITM 输出log
1,将如下内容拷贝到一个.c文件中放到工程中编译
#include <string.h> #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 needed */ }; FILE __stdout; FILE __stdin; int fputc(int ch, FILE *f) { if (DEMCR & TRCENA) { while (ITM_Port32(0) == 0); ITM_Port8(0) = ch; } return(ch); }
2,MDK中设置使用SW模式同时使能Trace输出
3,打开Debug Viewer试图即可查看代码中使用 printf() 打印的输出