zoukankan      html  css  js  c++  java
  • MDK Debug (printf) Viewer打印数据

    1.Target Options -> Debug -> Settings(JLink) -> Debug里ort选择SW模式

    2.在Target Options -> Debug -> Settings(JLink) -> Trace里选择Enable

    3.Core freq设为64MHz(以NRF52832为例)

    4. 设置ITM Port的值如下所示

    5.在工程中添加.c文件如下

    #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; /* 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);
    }
    //或者
    int fputc(int ch, FILE *f) {
       ITM_SendChar(ch);//内联函数
       return(ch);
    }

    6.用Debug模式运行工程,Debug (printf) Viewer中即可以查看printf的输出信息。

     注意:

    1.Core freq频率需要设置的与板子运行频率相同

    2.ITM可以理解为一个可以提供调试数据结果的MCU内部的东东,他首先是一个硬件存在,在Cortex-M3,M4,M7上都支持(很遗憾,性价比很高的M0,M0+是不支持的)

    3.没有提供SWO管脚,是无法做ITM跟踪调试的(将内核信息输出到IDE或者RTT终端)

    参考:

    https://www.cnblogs.com/GBRgbr/p/4450556.html

    https://blog.csdn.net/hanchaoman/article/details/102494914

  • 相关阅读:
    iris数据集
    codevs 1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛
    codevs 1742 爬楼梯(水题日常)
    codevs 2277 爱吃皮蛋的小明(水题日常)
    洛谷 P3386 【模板】二分图匹配
    vijos 1190 繁忙的都市
    codevs 1487 大批整数排序(水题日常)
    洛谷 P2820 局域网
    codevs 1683 车厢重组(水题日常)
    codevs 1228 苹果树
  • 原文地址:https://www.cnblogs.com/yeshenmeng/p/12377619.html
Copyright © 2011-2022 走看看