SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What is the ARM SWD protocol?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What is the ARM SWD protocol?

Neil Salmon
Last updated: September 16, 2023 8:55 am
Neil Salmon 8 Min Read
Share
SHARE

The ARM Serial Wire Debug (SWD) protocol is a two-pin debug interface standard developed by ARM for debugging ARM Cortex microcontrollers. It provides a low-pin-count, high-performance alternative to JTAG for accessing and debugging ARM cores.

Contents
Overview of ARM SWDKey Capabilities of ARM SWDSWD vs JTAGHow ARM SWD WorksSWD Packet FormatDebug Components Used by SWDDAP (Debug Access Port)BreakpointsWatchpointsJTAG-DPDebug Probes for ARM SWDUsing ARM SWDConclusion

Overview of ARM SWD

ARM SWD uses just two signals for bidirectional communication – SWCLK and SWDIO. SWCLK (Serial Wire Clock) is the clock signal, while SWDIO (Serial Wire Data Input/Output) carries all data in and out of the target system. By combining data and clock together on a single wire, SWD achieves high-speed communication and debugging while minimizing pin count.

The SWD interface connects the debug probe to the target microcontroller’s dedicated debug port. This port provides access to key debug components like the Debug Access Port (DAP), breakpoints, watchpoints, and various registers within the ARM core like program counter, memory, and peripherals.

Using the SWD interface and debug port, programmers can halt and resume code execution, set software and hardware breakpoints, read/write memory and registers, flash new firmware, and more – all critical capabilities for debugging ARM chips.

Key Capabilities of ARM SWD

Here are some of the major capabilities provided by ARM’s SWD protocol:

  • Halting and resuming code execution: SWD allows debug tools to halt a running program, examine processor state, memory, peripherals etc., and resume execution.
  • Breakpoints: Set software and hardware breakpoints to pause execution at specific code addresses or conditions.
  • Registers access: Read and write ARM core registers like program counter, stack pointer, general purpose registers, and more.
  • Memory access: Read and write contents of memory including Flash, SRAM, and device peripherals.
  • Flash programming: SWD allows flashing new firmware onto the target device’s memory.
  • Real-time code debugging: View mixed C and assembly code, local variables, call stack, threads, etc. while programs run.
  • Trace buffer streaming: Some SWD implementations support streaming trace/log data in real-time for advanced debugging.

SWD vs JTAG

SWD was designed by ARM as a successor to the long-standing JTAG (Joint Test Action Group) interface. While JTAG provides robust debugging, it requires at least 5 pins on the target device. SWD achieves similar debugging capabilities using just 2 pins – saving silicon area and cost.

Here’s a quick comparison between JTAG and SWD:

  • JTAG uses a 5+ wire interface (TDI, TDO, TCK, TMS, TRSTn). SWD uses just 2 wires (SWCLK, SWDIO).
  • JTAG supports advanced features like boundary scan testing. SWD focuses only on debug/programming.
  • Maximum clock speed is generally faster on SWD vs JTAG.
  • JTAG requires target chips to include a special JTAG circuitry called TAP. SWD uses simpler debug components like DAP.
  • SWD uses fewer wires and pins, making routing on complex SoCs easier.

For most debugging purposes, SWD provides all the necessary capabilities while minimizing complexity and cost. Hence it is commonly used for debugging ARM Cortex-M and Cortex-R series cores where pin count is important.

How ARM SWD Works

The SWD protocol establishes a bidirectional communication channel between the debug probe and the target device’s debug port. It works as follows:

  1. The debug probe (host) connects to the target’s SWCLK and SWDIO pins.
  2. A handshake is established by syncing clock signals and exchanging version information.
  3. The host sends requests to read/write registers and memory on the target system.
  4. Target responds with acknowledgements and data.
  5. All data is timed and synchronized using the SWCLK clock signal.
  6. Parity and CRC checks help ensure data validity and prevent synchronization loss.

By packaging both data and clock together in SWDIO, SWD achieves high throughput while using very few pins. The bidirectional nature of SWDIO allows both the host and target to exchange packets as needed.

SWD Packet Format

All data on SWD is wrapped in specially formatted packets. Each packet has a few key elements:

  • Start bit – Indicates start of a new packet.
  • AP/DP select bit – Selects Access Port (AP) or Debug Port (DP).
  • Read/Write bit – Specifies a read or write operation.
  • Address – Register or memory being accessed.
  • Parity – Odd parity bit for error checking.
  • Stop bit – Marks end of packet.
  • Park bit – Added by host between packets.

The target system responds by sending acknowledgement packets paired with data for read requests.

Debug Components Used by SWD

SWD relies on a few key components built into ARM chips to enable effective debugging:

DAP (Debug Access Port)

The Debug Access Port manages the connection between the SWD host and the chip’s internal buses and debug components. It has registers for debugger authentication, access control, and more.

Breakpoints

Up to 16 hardware breakpoints can be set that halt execution when a certain memory address is accessed.

Watchpoints

Watchpoints are similar to breakpoints but trigger on data accesses like reads or writes to specific memory locations.

JTAG-DP

The JTAG-DP module provides seamless SWD to JTAG translation in chips that support both interfaces.

Debug Probes for ARM SWD

To interface with the target device’s SWD port, a debugging tool called a debug probe is needed. These probes handle the SWD protocol and packet generation to communicate with the chip. They allow programmers to access the target core in easy ways using a debugger GUI on a host machine.

Some common SWD debug probes include:

  • ST-LINK by STMicroelectronics
  • J-Link by Segger
  • ULINKplus by Keil
  • Redlink by NXP
  • OpenOCD and RPi SWD tools for DIY probes

Each probe vendor provides software to control the debugging process from a host computer, such as STMCubeIDE, Keil MDK, Segger J-Link tools etc.

Using ARM SWD

To use SWD to debug and program an ARM chip, follow these basic steps:

  1. Connect the SWCLK and SWDIO pins on the target board to the debug probe.
  2. Connect the GND pins between the target and probe for a common ground.
  3. Connect the debug probe to the host PC via USB or Ethernet.
  4. Launch the debug software and browse for the target device.
  5. The software will connect to the target using the SWD interface.
  6. You can now view registers, set breakpoints, program memory, and debug as needed!

The wide adoption of SWD by ARM and its partners has made embedded debugging highly accessible. Debug probes like ST-LINK are inexpensive yet provide professional-grade JTAG-like debugging via SWD. With the help of SWD, even hobbyists can efficiently debug ARM chips right from their laptops.

Conclusion

ARM’s Serial Wire Debug provides a fast 2-pin debug interface for ARM cores. It minimizes the pin count and provides real-time access to critical debugging components like breakpoints, watchpoints, and DAP. By packaging clock and data together, SWD achieves high throughput and efficient synchronization. The widespread availability of SWD debug probes has enabled ARM’s dominance in the 32-bit embedded market.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Cortex M0+ MSP/PSP Context Switching
Next Article What is the difference between JTAG and SWD?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

What are SP (stack) and LR in ARM?

The stack pointer (SP) and link register (LR) are important…

8 Min Read

ARM Cortex-M4 DSP

The ARM Cortex-M4 processor is a 32-bit RISC CPU that…

5 Min Read

What is core lockup?

Core lockup refers to a situation where a CPU core…

10 Min Read

Why ARM Processors are Low Power?

ARM processors are designed to be power-efficient and low-power for…

6 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account