嵌入式


JTAG

<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/720efd0ccd5c4fea3737ecfb519916f4?showdoc=.jpg" alt="" /></p> <p>JTAG状态机通多连续5个TCK的TMS高电平复位到初始状态</p> <h3>stm32调试</h3> <ol> <li>semihosting</li> <li>TM机制要求使用SWD方式接口,并需要连接SWO线,一般的四线SWD方式(VCC SDCLK,SDIO,GND)是不行的。标准的20针JTAG接口是可以的,只需要在MDK里设置使用SWD接口即可。</li> </ol> <pre><code class="language-c">#include &lt;stdio.h&gt; #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 &amp; TRCENA) { while (ITM_Port32(0) == 0); ITM_Port8(0) = ch; } return(ch); }</code></pre> <p>Jlink配置文件放在工程下,任意名称都可</p> <pre><code class="language-c">/******************************************************************************/ /* STM32DBG.INI: STM32 Debugger Initialization File */ /******************************************************************************/ // &lt;&lt;&lt; Use Configuration Wizard in Context Menu &gt;&gt;&gt; // /******************************************************************************/ /* This file is part of the uVision/ARM development tools. */ /* Copyright (c) 2005-2007 Keil Software. All rights reserved. */ /* This software may only be used under the terms of a valid, current, */ /* end user licence from KEIL for a compatible version of KEIL software */ /* development tools. Nothing else gives you the right to use this software. */ /******************************************************************************/ FUNC void DebugSetup (void) { // &lt;h&gt; Debug MCU Configuration // &lt;o1.0&gt; DBG_SLEEP &lt;i&gt; Debug Sleep Mode // &lt;o1.1&gt; DBG_STOP &lt;i&gt; Debug Stop Mode // &lt;o1.2&gt; DBG_STANDBY &lt;i&gt; Debug Standby Mode // &lt;o1.5&gt; TRACE_IOEN &lt;i&gt; Trace I/O Enable // &lt;o1.6..7&gt; TRACE_MODE &lt;i&gt; Trace Mode // &lt;0=&gt; Asynchronous // &lt;1=&gt; Synchronous: TRACEDATA Size 1 // &lt;2=&gt; Synchronous: TRACEDATA Size 2 // &lt;3=&gt; Synchronous: TRACEDATA Size 4 // &lt;o1.8&gt; DBG_IWDG_STOP &lt;i&gt; Independant Watchdog Stopped when Core is halted // &lt;o1.9&gt; DBG_WWDG_STOP &lt;i&gt; Window Watchdog Stopped when Core is halted // &lt;o1.10&gt; DBG_TIM1_STOP &lt;i&gt; Timer 1 Stopped when Core is halted // &lt;o1.11&gt; DBG_TIM2_STOP &lt;i&gt; Timer 2 Stopped when Core is halted // &lt;o1.12&gt; DBG_TIM3_STOP &lt;i&gt; Timer 3 Stopped when Core is halted // &lt;o1.13&gt; DBG_TIM4_STOP &lt;i&gt; Timer 4 Stopped when Core is halted // &lt;o1.14&gt; DBG_CAN_STOP &lt;i&gt; CAN Stopped when Core is halted // &lt;/h&gt; _WDWORD(0xE0042004, 0x00000027); // DBGMCU_CR _WDWORD(0xE000ED08, 0x20000000); // Setup Vector Table Offset Register } DebugSetup(); // Debugger Setup </code></pre> <blockquote> <p>注意,要使用ITM机制,必须要打开BIT5。</p> </blockquote> <p>打开MDK工程,按照下图修改。 <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/4389ffb3d1490180461221b1814f8e27?showdoc=.jpg" alt="" /> <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/9c0f9468626df9ee3c46c019e93cb1f4?showdoc=.jpg" alt="" /></p> <p>下图中注意两点</p> <ol> <li>这里的CoreClock是120M,因为笔者使用的是stm32F207VG这款芯片,并且时钟配置为120M,所以这里填入120M,如果你使用stm32F10x,时钟配置成72M,那么这里需要填入72M。即需要跟实际情况保持一致。</li> <li>最后一定要将 0处打勾,并将其他bit位上的勾去掉,最好与此图保持一致,除CoreClock外。 <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/65ec5f7853c69ae82493c1179e5638ed?showdoc=.jpg" alt="" /></li> </ol> <p>完整版</p> <pre><code class="language-c">#pragma import(__use_no_semihosting_swi) struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; FILE __stdin; int fputc(int ch, FILE *f) { return ITM_SendChar(ch); } volatile int32_t ITM_RxBuffer; int fgetc(FILE *f) { while (ITM_CheckChar() != 1) __NOP(); return (ITM_ReceiveChar()); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int c) { fputc(c, 0); } int __backspace() { return 0; } void _sys_exit(int return_code) { label: goto label; /* endless loop */ } </code></pre> <p>查看函数的符号引用关系,可以通过生成详细的map文件来查看。命令行增加 --verbose --list rtt.map选项即可生成名为rtt.map的文件。</p> <h3>RTT</h3> <p><a href="https://blog.csdn.net/gyb510/article/details/52954622">https://blog.csdn.net/gyb510/article/details/52954622</a></p> <ul> <li> <p>Can this also be used on targets that do not have the SWO pin? A: Yes, the debug interface is used. This can be JTAG or SWD (2pins only!) on most Cortex-M devices, or even the FINE interface on some Renesas devices, just like the Infineon SPD interface (single pin!)</p> </li> <li>How does J-Link find the RTT buffer? A: There are 2 ways: If the Debugger (IDE) knows the address of the SEGGER_RTT structure, it passes it to J-Link. This is for example done by Ozone, the J-Link Debugger or SEGGER Embedded Studio. If a debugger is used that is not SEGGER-RTT aware, such as IAR's Embedded Workbench or emIDE, then J-Link searches for the ID in the known target RAM during execution of the program, transparently in the background. The process of locating the ID string takes just fractions of a second and does not delay program execution.</li> </ul> <h3>CoreSight</h3> <p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/b9a2929f31caac8e5f2481719741a683?showdoc=.jpg" alt="" /> <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/99da997100ddac0f0b31d66c28a60415?showdoc=.jpg" alt="" /></p> <p>CoreSight CoreSight 是一种基础架构,它可对完整的芯片上系统 (SoC) 设计的性能进行调试、监视和优化,CoreSight™ 跟踪宏单元在 SoC 中提供全面的非干预性可见性。 总结来说CoreSight的调试结构中按照功能可以分为三大部分:Source,Link和Sink。</p> <p>Source意即源部件,指一些信号或者profile/debug数据的来源,用于产生向ATB(AMBA Trace Bus)发送的跟踪数据,一般是APB总线。 比如STM和ETM都属于Source部分。</p> <p>STM (System Trace Macrocell):用于获取系统的跟踪信息。</p> <p>ETM (Embedded Trace Macrocell):用于获取处理器核的跟踪信息。</p> <p>Sink意即控制访问部件,配置和控制数据流的产生,但是不产生数据流。 指一些可以保持这些从source过来数据的模块。</p> <p>比如DAP和ECT都属于Sink部分。</p> <p>DAP(Debug Access Port):可以实时访问AMBA总线上的系统内存,外设寄存器,以及所有调试配置寄存器,而不需挂起系统。</p> <p>ECT(Embedded Cross Trigger):包括CTI(Cross Trigger Interface)和CTM(Cross Trigger Matrix),为ETM(Embedded Trace Macrocell)提供接口,用于将一个处理器的调试事件传递给另一个处理器。</p> <p>Link意即汇聚点,芯片上跟踪数据的终点。指用于引导从source到sink过程中的类似于通道作用的模块。</p> <p>比如TPIU、ETB和SWO都属于汇聚点。</p> <p>TPIU(Trace Port Interface Unit):将片内各种跟踪数据源获取的信息按照TPIU帧的格式进行组装,然后通过Trace Port传送到片外。</p> <p>ETB(Embedded Trace Buffer):一个32位的RAM,作为片内跟踪信息缓冲区。</p> <p>SWO(Serial Wire Output):类似TPIU,但仅输出ITM单元的跟踪信息,只需要一个引脚。</p> <p>通过遵循 CoreSight 架构规范,可以方便地将合作伙伴特定的跟踪宏单元集成到 CoreSight 系统中</p> <h4>ETM,嵌入式跟踪宏单元</h4> <p>ETM 宏单元为 ARM 微处理器提供实时指令跟踪和数据跟踪。跟踪软件工具使用 ETM 生成的信息重建全部或部分程序的执行情况。</p> <h4>PTM,程序跟踪宏单元</h4> <p>PTM 是一个模块,它根据程序流程跟踪 (PFT) 体系结构执行实时指令流跟踪。跟踪工具使用 PTM 生成的信息重建全部或部分程序的执行情况。</p> <h4>ITM,测量跟踪宏单元</h4> <p>CoreSight ITM 块是一个软件应用程序驱动的跟踪源。支持的代码将生成软件测量跟踪 (SWIT)。此外,该块还提供粗略的时间戳功能。</p> <p>该块的主要用途是:</p> <p>支持 printf 风格调试 跟踪操作系统和应用程序事件 发出诊断系统信息</p> <h4>HTM,AHB 跟踪宏单元</h4> <p>HTM 可显示无法使用 ETM 从内核跟踪推断的总线信息:</p> <p>了解多层总线利用率。 软件调试。例如,内存区域访问和数据访问的可见性。 跟踪触发器或过滤器的总线事件检测,以及用于总线分析。 HTM 提供了有关 AHB 总线的地址和数据跟踪信息。通过将 HTM 中的信息与调试器结合使用,可对基于 AHB 的嵌入式系统进行方便、精确的调试。HTM 提供了广泛的资源以使事件识别功能生成触发事件。HTM 通过 AMBA 跟踪总线 (ATB) 来生成输出的跟踪数据。跟踪调试功能是非干预性的。可以使用 APB (AMBA v3) 接口来控制 HTM。</p> <h4>STM,系统跟踪宏单元</h4> <p>STM为所有软件开发人员提供了低成本的软件和硬件执行实时可见性,尤其是应用程序和内核开发人员,从而为整个供应链中支持 ARM 处理器的设备提供了功能丰富且优化的低能耗软件。</p> <h4>ECT,嵌入式交叉触发</h4> <p>CoreSight ECT 是一个控制和访问组件,支持 SoC 内的多个触发事件的交互和同步。</p> <h4>ETB,嵌入式跟踪缓存</h4> <p>CoreSight ETB 是一个跟踪接收器,它可使用可配置大小的 RAM 为跟踪数据提供芯片上存储。</p>

页面列表

ITEM_HTML