Keil™, An ARM® Company

ULINK®2 User's Guide

Using the ITM Viewer

ITM Viewer WindowThe ITM Viewer window displays an ASCII or HEX representation of the data sequentially transmitted over ITM Port 0 in the ITM Viewer tab within µVision.

It may be used to view 8-bit, serial data generated from the target device, such as the output of a printf statement. This can be very useful during target debugging.

To use the ITM Viewer for Trace debug output:

  1. Add ITM Stimulus 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 a fputc function which writes to the ITM Stimulus Port 0 register to your source code. Adding this fputc function allows you to use printf for debug output. The ITM Viewer only works with ITM Port 0.
    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 Debug Trace Messages to your source code using printf.
    printf("AD value = 0x%04X\r\n", AD_value);
    
  4. 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.

    ITM Stimulus Port 0
  5. Select View - Serial Window - ITM Viewer to display the ITM Viewer window.

    Selecting ITM Viewer Window

Note

  • Only data transmitted over ITM Stimulus port 0 is displayed in the ITM window. Other ITM Ports can be monitored in the Trace Records Window where also ITM Port 0 is shown.