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
The 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.
Note
- Only 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.