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

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.

Debug (printf) Viewer Window

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值