Unlock the power of ARM: Debug and Trace

Unlock the power of ARM: Debug and Trace

Written by: Malek Boubahri & Khaled Dhif

Published on: 21/08/2024

Introduction

ARM Cortex-M processors are central to modern embedded systems, blending cutting-edge technology with practical efficiency. At their core, these processors utilize a RISC (Reduced Instruction Set Computer) architecture, which, combined with a 32-bit processing width and a pipeline design, delivers impressive performance and energy efficiency. The Thumb-2 instruction set further enhances this by balancing high performance with compact code.

For example, in STM32 microcontrollers, ARM Cortex cores integrate seamlessly within their ecosystem through a robust bus system, including the Advanced High-performance Bus (AHB) and Advanced Peripheral Bus (APB). This architecture ensures efficient data transfer between the processor and its peripherals. The Memory Protection Unit (MPU) provides effective memory management, while the Nested Vectored Interrupt Controller (NVIC) efficiently manages and prioritizes interrupts, which is crucial for real-time performance.

This efficient integration of these IPs enables STM32 MCUs to perform a broad range of functions, from simple control tasks to complex signal processing. The block diagram below illustrates how a Cortex-M4 core is embedded within the overall architecture of an STM32F4 MCU.

STM32 Block Diagram Featuring ARM Cortex-M4 Core

In this article, we will explore the advanced debugging and tracing capabilities of ARM Cortex-M processors, specifically the Single Wire Output (SWO) pin. Before diving into SWO, we will introduce CoreSight, ARM’s comprehensive debugging and trace technology, to provide context on how SWO fits into the broader debugging framework.


CoreSight: ARM’s Debugging and Tracing Ecosystem

CoreSight is ARM's comprehensive framework designed to enhance debugging and tracing for embedded systems. It comprises several key components that collaborate to support both real-time debugging and in-depth system analysis:

  • Instrumentation Trace Macrocell (ITM): Provides non-blocking trace messages for software profiling.
  • Data Watchpoint and Trace (DWT) Unit: Facilitates watchpoints, program counter sampling, and trace event triggering.
  • Flash Patch and Breakpoint (FPB) Unit: Enables setting breakpoints in Flash memory and remapping ROM sections for debugging.
  • Embedded Trace Macrocell (ETM): Captures detailed sequences of executed instructions.
  • Trace Port Interface Unit (TPIU): Channels trace data from ITM, DWT, and ETM to an external debugger.
  • ROM Table: Lists available debug components within a specific implementation.

CoreSight’s debugging and tracing functionalities serve distinct yet complementary roles:

  • Debug: Involves real-time observation and modification of a system’s state, allowing developers to diagnose issues, set breakpoints, and inspect or modify registers and memory. Debugging can be invasive (halting the processor) or self-hosted (continuing processor operation while monitoring its state).
  • Trace: Focuses on non-invasive, continuous monitoring of system activity. It captures execution data without interrupting the system, which is crucial for analyzing behavior over time and in high-speed applications where halting is impractical. Trace units provide the ability for running software to be instrumented with messaging (either by the programmer, or through a tool flow)


Example of CoreSight Debug and Trace Infrastructure in Cortex M-3


SWO: Enhancing Debugging and Tracing in ARM Cortex-M

The Single Wire Output (SWO) pin in ARM Cortex-M processors simplifies debugging and tracing by capturing real-time data efficiently. It streamlines the process by allowing printf outputs to be redirected for real-time monitoring without extra UART interfaces.

SWO’s Role in the Debugging Framework

  • Integration with SWD: SWO is integrated into the Serial Wire Debug (SWD) interface, which offers a compact alternative to traditional JTAG. While SWD uses two main pins (SWDIO and SWCLK) for communication, SWO adds an extra channel for trace data, requiring only three pins (SWDIO, SWCLK, and SWO).
  • Role in Debugging: SWO enables the redirection of debug outputs, such as printf statements, to a single pin, simplifying monitoring of application behavior, particularly when pin availability is limited.
  • Trace Data Output: SWO can transmit complex trace data from the ITM, DWT, and even the ETM when configured. This data is crucial for in-depth performance analysis and debugging.
  • Efficiency: SWO’s efficiency in pin usage and processing overhead makes it ideal for embedded systems. It provides detailed debug and trace data without requiring a full trace port, conserving I/O pins and resources.


JTAG and SWD Pins: Understanding the Debug Interfaces

ARM Cortex-M processors offer two primary debugging interfaces: JTAG and Serial Wire Debug (SWD). Each interface serves specific purposes and uses distinct pin configurations, although they share some common signals.

JTAG (Joint Test Action Group) Signals:

- TMS (Test Mode State pin): This pin controls the JTAG state machine.

- TDO (Test Data Out pin): Outputs data from the device.

- RTCK (JTAG Return Test ClocK): Provides a return clock signal.

- TDI (Test Data In pin): This pin inputs data to the device.

- TRST (Test ReSeT pin): This optional pin is sometimes not available and can be left unconnected. It is an open-collector/open-drain output.

- TCLK (Test CLock pin): This pin provides the clock signal for JTAG operations.

- VCC: Positive supply voltage for JTAG interface drivers.

- GND: Digital ground.

- RESET: Connect to the (active low) reset input of the target CPU. This pin is an open-collector/open-drain output.

Serial Wire Debug (SWD) Signals:

SWD is a more compact alternative to JTAG, using fewer pins. It offers an efficient debugging interface with the following pins:

- SWDIO (Serial Wire Debug Data I/O): Data input and output pin.?

- SWO (Serial Wire Output): Optional pin for trace output.

- SWCLK (Serial Wire Clock): The clock pin for SWD communication.?

- VCC: Positive supply voltage for JTAG interface drivers.

- GND: Digital ground.

- RESET: Connect to the (active low) reset input of the target CPU. This pin is an open-collector/open-drain output.


Example: ARM CoreSight Generic Debug Connectors

Pin Sharing Note:

The SWO pin is utilized for trace data in both JTAG and SWD configurations. Since it is shared between these interfaces, only one can be used at a time. If you use JTAG, the SWO pin will not be available for use. Conversely, if you select SWD, you can leverage SWO for trace outputs, provided that it is properly configured.


Debug Discovery in ARM Cortex-M Architecture

The availability and configuration of debugging features can differ between ARM Cortex-M implementations. To determine which debugging components are included in a specific microcontroller, the ARM architecture provides mechanisms for discovering and understanding these features.

Key Aspects of Debug Discovery:

  • Optional Components: Debug features are not always present in every ARM Cortex-M implementation. The inclusion of these features depends on the specific microcontroller or processor configuration.
  • ROM Table Indicators: ARM Cortex-M processors use a ROM table that includes indicators to show whether certain debug units are available. This allows you to identify which debugging components are included in the implementation.

Additional Details: When a debug unit is present, additional registers and configurations may provide further information about its specific capabilities and functionalities.

The following diagrams illustrate the debug infrastructure implementation in two different microcontroller platforms: a TI microcontroller and an STM32 microcontroller. The discovery process helps us identify which debug components are integrated within the processor and which are external.

Texas Instrument’s Tiva C Series TM4C123GH6PM Debug Infrastructure Implementation?



STM32H7S3L8? Debug Infrastructure Implementation


Conclusion:

In this article, we explored the trace and debug infrastructure of ARM Cortex-M processors, highlighting their advanced capabilities. We focused specifically on the Single Wire Output (SWO) pin, which is crucial for real-time debugging and trace data capture.

Excited to see SWO in action? Don’t miss our upcoming video tutorial, where we’ll show you step-by-step how to redirect printf output to SWO and unlock the full potential of these features!


Additional Resources

  1. How to Debug CoreSight: Basics An introduction to CoreSight debugging and trace technology. This blog post provides foundational knowledge on how to get started with ARM's debugging tools. Read the blog post
  2. ARM Debug Architecture (ARMv7 Architecture Technical Reference Manual) Detailed information about the ARM Debug Architecture, including insights into the various components and their functionalities within ARMv7 architectures. View the technical reference manual
  3. Webinar by iSYSTEM: Debug and Trace on Cortex-M4 Based Microcontrollers A comprehensive webinar discussing debugging and tracing techniques for Cortex-M4 based microcontrollers, presented by iSYSTEM. Watch the webinar
  4. YouTube Tutorial: Debug and Trace (in Arabic) A tutorial video in Arabic covering the basics of debugging and tracing for embedded systems. Watch the tutorial


要查看或添加评论,请登录