# SWD (JTAG) Hardware Debugging Interface

PX4 usually runs on autopilot controller hardware that provides an ARM Serial Wire Debug (SWD) interface. SWD is a low pin-count physical interface for JTAG debugging on ARM-processors. It can be used with an SWD-compatible debug probe (e.g. Segger J-Link EDU Mini, Dronecode Probe, etc.) to set breakpoints in PX4 and step through the code running on a real device.

The SWD interface can also be used to add a new bootloader and/or firmware on a completely empty board (one that does not have the USB bootloader installed).

This topic explains how to connect the SWD interface on different boards (debugging itself is then covered in the associated debugging topics).

# SWD Interface Definition

The SWD interface consists of the following pins.

针脚 Signal Type 参数描述
参考压 输出 Target reference voltage.
Some JTAG adapters require the Vref voltage to set the voltage on the SWD lines. For example, SEGGER J-Link Debug Probes require Vref.
SWDIO I/O Single bi-directional data pin.
SWCLK 输出 Clock signal.
GND - Ground pin.

While not "part" of SWD, an autopilot may also have an Serial Wire Output (SWO) trace output pin. If present this should also be connected.

针脚 Signal Type 参数描述
SWO 输出 Serial Wire Output trace output pin. This may be used in combination with SWD to emit real-time trace data.

# Connecting SWD Debuggers to PX4 Hardware

Flight controllers commonly provide a single debug port that exposes both the SWD Interface and System Console. This must be connected to an SWD debug probe using an "appropriate" connector.

This connector may come with your flight controller or debug probe. Other options are given below.

# Holybro Pixhawk Debug Adapter

The Holybro Pixhawk Debug Adapter (opens new window) is highly recommended when debugging controllers that use one of the Pixhawk-standard debug connectors.

It is the easiest way to connect:

  • Flight controllers that use either the Pixhawk Debug Full (10-pin SH) or Pixhawk Debug Mini (6-pin SH) debug port, and
  • SWD debug probes that support the 10-pin ARM compatible interface standard used by the Segger JLink Mini or 20-pin compatible with the Segger Jlink or STLink.

Holybro Pixhawk Debug Adapter

# Debug Probe Adapters

Some SWD debug probes come with adapters/cables for connecting to common Pixhawk debug ports. Probes that are known to come with connectors are listed below:

# Board-specific Adapters

Some manufacturers provide cables to make it easy to connect the SWD interface and System Console.

6-pin JST SH Cable

# Custom Cables

You can also create custom cables for connecting to different boards or probes:

  • Connect SWDIO, SWCLK and GND pins on the debug probe to the corresponding pins on the autopilot.
  • Connect the VRef pin, if required by the debug adapter that is being used.
  • Connect the SWO pin, if present.

提示

Where possible, we highly recommend that you create or obtain an adapter board rather than custom cables for connecting to SWD/JTAG debuggers and computers. This reduces the risk or poor wiring contributing to debugging problems, and has the benefit that adapters usually provide a common interface for connecting to multiple popular flight controller boards.

# Autopilot Debug Ports

Flight controllers commonly provide a single debug port that exposes both the SWD Interface and System Console.

The Pixhawk Connector Standards formalize the port that must be used in each FMU version. However there are still many boards that use different pinouts or connectors, so we recommend you check the documentation for your autopilot to confirm port location and pinout.

The debug port location and pinouts for a subset of autopilots are linked below:

飞控 Connector
Holybro Pixhawk 5X (FMUv5x) Pixhawk Debug Full
Holybro Durandal Pixhawk Debug Mini
Holybro Kakute F7 Solder pads
Holybro Pixhawk 4 Mini (FMUv5) Pixhawk Debug Mini
Holybro Pixhawk 4 (FMUv5) Pixhawk Debug Mini
Drotek Pixhawk 3 Pro (FMU-v4pro) Pixhawk Debug Mini
CUAV V5+ 6-pin JST GH
Digikey: BM06B-GHS-TBT(LF)(SN)(N) (opens new window) (vertical mount), SM06B-GHS-TBT(LF)(SN)(N) (opens new window) (side mount)
CUAV V5nano 6-pin JST GH
Digikey: BM06B-GHS-TBT(LF)(SN)(N) (opens new window) (vertical mount), SM06B-GHS-TBT(LF)(SN)(N) (opens new window) (side mount)
3DR Pixhawk ARM 10-pin JTAG Connector (also used for FMUv2 boards including: mRo Pixhawk, HobbyKing HKPilot32).

# Pixhawk Connector Standard Debug Ports

The Pixhawk project has defines a standard pinout and connector type for different Pixhawk FMU releases:

提示

Check your specific board to confirm the port used.

FMU Version Pixhawk Ver. Debug Interface
FMUv2 Pixhawk / Pixhawk 1 10 pin ARM Debug
FMUv3 Pixhawk 2 6 pin SUR Debug
FMUv4 Pixhawk 1/2 Pixhawk Debug Mini
FMUv5 Pixhawk 4 FMUv5 Pixhawk Debug Mini
FMUv5X Pixhawk 5X Pixhawk Debug Full
FMUv6 Pixhawk 6 Pixhawk Debug Full
FMUv6X Pixhawk 6X Pixhawk Debug Full

注解

There FMU and Pixhawk versions are (only) consistent after FMUv5X.

# Pixhawk Debug Mini (6-Pin SH Debug Port)

The Pixhawk Connector Standard (opens new window) defines the Pixhawk Debug Mini, a 6-Pin SH Debug Port that provides access to both SWD pins and the System Console.

This is used in FMUv4 and FMUv5.

The pinout is as shown below (SWD pins highlighted):

Debug调试端口 针脚
1 Vtref
2 Console TX
3 Console RX
4 SWDIO
5 SWDCLK
6 GND

The debug port definition includes the following solder pads (on board next to connector):

Debug调试端口 针脚 Voltage
Pad 信号 电压
1 NRST (reset) +3.3V
2 GPIO1 (free GPIO) +3.3V
3 GPIO2 (free GPIO) +3.3V

The socket is a 6-pin JST SH - Digikey number: BM06B-SRSS-TBT(LF)(SN) (opens new window) (vertical mount), SM06B-SRSS-TBT(LF)(SN) (opens new window)(side mount).

You can connect to the debug port using a cable like this one (opens new window).

6-pin JST SH Cable

# Pixhawk Debug Full (10-Pin SH Debug Port)

The Pixhawk Connector Standard (opens new window) defines Pixhawk Debug Full, a 10-Pin SH Debug Port that provides access to both SWD pins and the System Console. This essentially moves the solder pads from beside the Pixhawk Debug Mini into the connector, and also adds an SWO pin.

This port is specified for use in FMUv5x, FMUv6, FMUv6x.

The pinout is as shown below (SWD pins highlighted):

Debug调试端口 针脚
1 Vtref
2 Console TX
3 Console RX
4 SWDIO
5 SWDCLK
6 SWO
7 NFC GPIO
8 PH11
9 nRST
10 GND

The socket is a 10-pin JST SH - Digikey number: BM10B-SRSS-TB(LF)(SN) (opens new window) (vertical mount) or SM10B-SRSS-TB(LF)(SN) (opens new window) (side mount).

You can connect to the debug port using a cable like this one (opens new window).

10-pin JST SH Cable

# Debug Probes

The following section outlines some popular debug probes and adaptors for connecting them to autopilots running PX4.

The Segger JLink EDU Mini (opens new window) is an inexpensive and popular SWD debug probe. The probe's connector pinout looks like the image below (connect to this using an ARM 10-pin mini connector like FTSH-105-01-F-DV-K (opens new window)).

connector_jlink_mini.png

The pin mapping to connect the J-Link Edu Mini to Pixhawk Debug Mini is shown below (note, the - indicates a pin that is not required for SWD).

Debug调试端口 J-Link Mini
1 (Vtref) 1
2 (Console TX) -
3 (Console RX) -
4 (SWDIO) 2
5 (SWDCLK) 4
6 (GND) 3 or 5

提示

From the table above you can infer the connections for autopilots that do not use the standard port.

# Dronecode Probe

The Dronecode Probe (opens new window) is a generic JTAG/SWD + UART console adapter compatible with most ARM Cortex based designs, and in particular with Pixhawk series flight controllers (and other hardware that PX4 supports).

The probe's USB interface exposes two separate virtual serial port interfaces: one for connecting to the System Console (UART) and the other for an embedded GDB server (SWD interface).

The probe provides a DCD-M connector cable for attaching to the Pixhawk Debug Mini.

注解

The 6-pos DF13 connector that comes with the probe cannot be used for SWD debugging (it is for using the System Console).

注解

The Dronecode Probe is based on the Black Magic Probe.

# Black Magic Probe

The Black Magic Probe (opens new window) is much like the Dronecode probe but does not come with the same adapters for directly connecting to Pixhawk series flight controllers.

Adapters can be purchased separately:

# 后续步骤

You've now connected the flight controller to an SWD debug probe!

The following topics explain how to start on-target debugging: