#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
l
在源代码中添加fputc函数,它向ITM的激励端口0寄存器写数据。如果有了fputc函数,则可以用printf函数做为调试输出。ITM的激励端口0与ITM Viewer窗口固定连接。
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;