Understanding ARM Cortex-M Debugging and Tracing Techniques

Follow+Star Public Account, don’t miss exciting content

Understanding ARM Cortex-M Debugging and Tracing Techniques

Author | strongerHuang

WeChat Official Account | strongerHuang

Nowadays, the convenience of debugging numerous Cortex-M processors is due to a technology called CoreSight based on Arm Cortex-M processor devices, which introduces powerful new debugging and tracing functions.

Next, let’s focus on the debugging and tracing aspects of CoreSight.

Debugging and Tracing Functions

The two main functions of CoreSight are debugging and tracing.

1. Debugging Function

  • Control of the running processor, allowing starting and stopping programs
  • Single-step debugging of source and assembly code
  • Setting breakpoints while the processor is running
  • Instant read/write of memory content and peripheral registers
  • Programming internal and external FLASH memory

2. Tracing Function

  • Serial Wire Viewer (SWV) provides program counter (PC) sampling, data tracing, event tracing, and instrumentation tracing information

  • Instruction (ETM) tracing streams directly to your PC for historical sequence debugging, software performance analysis, and code coverage analysis

A diagram to understand the overall content:

Understanding ARM Cortex-M Debugging and Tracing Techniques

JTAG

JTAG is the industry-standard interface for downloading and debugging programs on the target processor, among many other functions. It provides an easy way to connect devices and is available on all Arm-based processor devices. The JTAG interface can be used with Cortex-M based devices to access CoreSight debugging functions.

1. JTAG History

JTAG stands for Joint Test Action Group, a common name for the IEEE standard 1149.1 known as the Standard Test Access Port and Boundary Scan Architecture. This standard is used to verify the functionality of printed circuit boards produced in design and testing.

JTAG was officially standardized by IEEE in document 1149.1-1990, and in 1994, supplementary documents were added to describe the Boundary Scan Description Language (BSDL). Since then, this standard has been widely adopted by electronic companies worldwide, and boundary scan has almost become synonymous with JTAG.

— Quote from Wikipedia

2. JTAG Interface

The JTAG interface typically consists of 4/5 pins connected to the chip:

  • TDI (Test Data Input)

  • TDO (Test Data Output)

  • TCK (Test Clock)

  • TMS (Test Mode Select)

  • TRST (Test Reset) optional

Understanding ARM Cortex-M Debugging and Tracing Techniques

SWD Serial Wire Debug

SWD, Serial Wire Debug (SWD) mode is an alternative to the standard JTAG interface, providing the same debugging functionality using only two pins without sacrificing performance, and introducing data tracing through the Serial Wire Viewer (SWV).

The JTAG pins include SWD interface pins, allowing use in standard target connectors. The pins include:

  • TCLK-SWCLK (Serial Clock)

  • TMS-SWDIO (Serial Data Input/Output)

  • TDO-SWO (Serial Wire Output – used by SWV)

About SWV

SWV: Serial Wire Viewer

Devices based on Cortex-M3, M4, and M7 can provide high-speed data tracing information in various ways depending on the type of information or analysis required. When the system processor continues to run at full speed, it transmits through the SWO pin.
Information can be obtained from the ITM (Instrumentation Trace Macrocell) and DWT (Data Watchpoint and Trace) units, which include:
  • PC (Program Counter) sampling

  • Event counters displaying CPU cycle statistics

  • Exception and interrupt execution with timing statistics

  • Trace data – data reads and writes for timing analysis

  • ITM trace information for simple printf-style debugging

Refer to my previous article “Print Output Tutorial“.

Extension: Download Debugger

I previously shared “Differences Between Download Debug Interfaces SWD and JTAG“, you can compare the differences when choosing a download debugger.

Many download debuggers support both JTAG and SWD modes, such as J-Link, ST-LINK, ULINK, and many niche download debuggers (like e-Link, GD-Link, etc.) also support SWD mode.

So, which one should we choose? Which one is better?

J-Link is considered comprehensive, but the price of the genuine product can be burdensome for ordinary individuals.There are various versions, costing several thousand each.

Understanding ARM Cortex-M Debugging and Tracing Techniques

Similarly, genuine ULINK is also priced in the thousands like J-Link. Of course, many people end up with counterfeit ULINK and J-Link products.

Compared to ULINK and J-Link, the genuine ST-Link is quite cost-effective, with a genuine ST-Link V2 priced at only two to three hundred, but the downside is that it can only be used for STM8/32.

———— END ————
Follow the public account and reply with “ARM Basic Tutorial” to read more related articles.
Reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Understanding ARM Cortex-M Debugging and Tracing Techniques

Understanding ARM Cortex-M Debugging and Tracing Techniques

Click “Read Original” to see more shares.

Leave a Comment

×