Debug (printf) Viewer
The Debug (printf) Viewer window displays data streams that are transmitted sequentially through the ITM Stimulus Port 0. Enable ITM Stimulus Port 0.

To use the Debug (printf) Viewer for tracing:
- Add ITM Port register definitions to your 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
2. Add an fputc function to your 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);
}
3. Add your debugging trace messages to your source code using printf.
printf("AD value = 0x%04X\r\n", AD_value);
4. Set the ITM Port 0 to capture the information. Clear the Port 7..0 privilege bit to access ITM Port 0 from User mode.

5. Open the View - Serial Windows - Debug (printf) Viewer window.
Note
- ITM Stimulus Ports can be monitored in the Instruction Trace Window, where ITM Port 0 is shown as well.
- Consult Configure Cortex-M Target of the MDK-Primer for information on how to retarget the output.
本文详细介绍了如何在Cortex-M设备上使用Debug(printf)Viewer进行跟踪调试。通过定义ITM Port寄存器并添加fputc函数,使printf能够输出消息。设置ITM Port 0捕获信息,并在User模式下清除Port 7..0特权位,以访问ITM Port 0。最后,在MDK中打开Debug(printf)Viewer窗口查看数据流。
2450

被折叠的 条评论
为什么被折叠?



