2024年3月23日发(作者:郸春雨)
关于ITM
ITM(Instrumentation Trace Macrocell),由Cortex-M3内核提供。以下是简单用法。
一、代码包含。
#ifdef TRACEINFO
/*Add ITM Port register definitions to 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
/*
Add an fputc function to 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) {
while (ITM_Port32(0) == 0);
ITM_Port8(0) = ch;
}
return(ch);
}
#endif
实现以上代码之后就可以使用printf语句了。
调试中,信息会输出到DebugViewer窗口中。
找到DebugViewer:
2024年3月23日发(作者:郸春雨)
关于ITM
ITM(Instrumentation Trace Macrocell),由Cortex-M3内核提供。以下是简单用法。
一、代码包含。
#ifdef TRACEINFO
/*Add ITM Port register definitions to 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
/*
Add an fputc function to 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) {
while (ITM_Port32(0) == 0);
ITM_Port8(0) = ch;
}
return(ch);
}
#endif
实现以上代码之后就可以使用printf语句了。
调试中,信息会输出到DebugViewer窗口中。
找到DebugViewer: