Debug (printf) Viewer

http://www.keil.com/support/man/docs/ulink2/ulink2_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.

Debug (printf) Viewer_第1张图片

To use the viewer for trace output:

  1. 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
    
  2. 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);
    }
    
  3. Add the debug trace messages.
    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 Windows - Debug (printf) Viewer to launch the window.

    Selecting Debug (printf) Viewer 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.

你可能感兴趣的:(C语言,stm32)