您的位置:首页 > 其它

STM32--KEIL的printf打印-ITM机制

2018-03-16 11:38 627 查看

http://www.keil.com/support/man/docs/ulink2/ulink2_trace_itm_viewer.htm

http://www.keil.com/support/man/docs/jlink/jlink_trace_itm_viewer.htm


Debug (printf) Viewer

Home » µVision Windows » Debug (printf) ViewerThe Debug (printf) Viewer window displays data streams that are transmitted sequentially through the ITM Stimulus Port0. Enable ITM Stimulus Port 0.

To use the viewer for trace output:Add ITM Stimulus Port register definitions to the 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 a fputc function which writes to the ITM Stimulus Port 0 register to the source code, which allows using printf for debug output.
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);
}

Add the debug trace messages.
printf("AD value = 0x%04X\r\n", AD_value);

Set ITM Stimulus Port Port 0 bit to allow Trace to capture the ITM Port 0 information. Clear the Port 7..0 privilege bit to allow access to the Port 0 bit from User mode.



Select View - Serial Windows - Debug (printf) Viewer to launch the window.




 NoteOnly data transmitted over ITM Stimulus port 0 is displayed in the Debug (printf) Viewer window. Other ITM Ports can be monitored with the Trace Records Window.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: