在工程里面添加下列代码:

#include <stdio.h>

#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


//半主机模式必须定义这个
struct __FILE
{
    int handle;
};
FILE __stdout;
FILE __stdin;

int fputc(int ch, FILE *f)
{
    if (DEMCR & TRCENA)
    {
        while (ITM_Port32(0) == 0);

        ITM_Port8(0) = ch;
    }
    return(ch);
}
点击JLink的调试设置对话框,Trace页面,如下图设置即可:

在Keil环境下使用JLink实现printf输出重定向至debug窗口

原始文章:


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

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-07-07
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2022-02-03
  • 2021-07-18
  • 2021-11-27
  • 2021-06-19
  • 2021-04-01
  • 2021-08-25
相关资源
相似解决方案