# 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 (actually performing debugging is then covered in the associated debugging topics).
# SWD Interface Definition
The SWD interface consists of the following pins.
Pin | Signal Type | Description |
---|---|---|
Vref | Output | 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 | Output | 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.
Pin | Signal Type | Description |
---|---|---|
SWO | Output | 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
Connect SWDIO
, SWCLK
and GND
pins on the debug probe to the corresponding pins on the autopilot.
In addition:
- Connect the
VRef
pin, if required by the debug adapter that is being used. - Connect the
SWO
pin, if present.
Some SWD debug probes come with adapters/cables for connecting to common Pixhawk debug ports. You can also create custom cables for connecting to different boards or probes.
Note
Some manufacturers provide cables to make it easy to connect the SWD interface and System Console. For example the CUAV V5nano and CUAV V5+ include this debug cable:
TIP
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 debug port that exposes both the SWD Interface and System Console.
The Pixhawk Connector Standards attempts to standardise this port. However since many boards use different pinouts or connectors, we recommend you check the documentation for your autopilot to confirm port location and pinout.
The debug port location and pinouts for a small subset of autopilots are linked below:
Autopilot | Connector |
---|---|
3DR Pixhawk | ARM 10-pin JTAG Connector (also used for FMUv2 boards including: mRo Pixhawk, HobbyKing HKPilot32). |
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) |
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) |
Drotek Pixhawk 3 Pro | Pixhawk 6-pin SH Debug |
Holybro Pixhawk 4 | Pixhawk 6-pin SH Debug |
Holybro Pixhawk 4 Mini | Pixhawk 6-pin SH Debug |
Holybro Kakute F7 | Solder pads |
Holybro Durandal | Pixhawk 6-pin SH Debug |
TIP
Check the autopilot topics if your flight controller is not listed.
# Pixhawk Standard Debug Ports
The Pixhawk project has defines a standard pinout and connector type for different Pixhawk FMU releases:
TIP
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 3 | 6 pin SH Debug |
FMUv5 | Pixhawk 4 FMUv5 | 6 pin SH Debug |
FMUv5X | Pixhawk 5X | 10 pin SH Debug |
FMUv6 | Pixhawk 6 | 10 pin SH Debug |
FMUv6X | Pixhawk 6 | 10 pin SH Debug |
Note
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 a 6-Pin SH Debug Port that provides access to both SWD pins and the System Console.
Note
This debug port is used in FMUv4 and FMUv5.
The pinout is as shown below (SWD pins highlighted):
Debug Port | Pin |
---|---|
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 Port | Pin | Voltage |
---|---|---|
Pad | Signal | Volt |
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).
# Pixhawk Debug Full (10-Pin SH Debug Port)
The Pixhawk Connector Standard (opens new window) defines 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 6-Pin SH Debug Port into the connector, and also adds an SWO pin.
Note
This port is specified for use in FMUv5x, FMUv6, FMUv6x.
The pinout is as shown below (SWD pins highlighted):
Debug Port | Pin |
---|---|
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).
# Debug Probes
The following section outlines some popular debug probes and adaptors for connecting them to autopilots running PX4.
# Segger JLink EDU Mini Debug Probe
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)).
The pin mapping to connect the J-Link Edu Mini to Pixhawk 6-Pin SH Debug Port is shown below (note, the -
indicates a pin that is not required for SWD).
Debug Port | J-Link Mini |
---|---|
1 (Vtref) | 1 |
2 (Console TX) | - |
3 (Console RX) | - |
4 (SWDIO) | 2 |
5 (SWDCLK) | 4 |
6 (GND) | 3 or 5 |
TIP
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 6-Pin SH Debug Port.
Note
The 6-pos DF13 connector that comes with the probe cannot be used for SWD debugging (it is for using the System Console).
Note
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:
- Drone Code Debug Adapter (opens new window) (1 BIT SQUARED).
# Next Steps
You've now connected the flight controller to an SWD debug probe!
The following topics explain how to start on-target debugging: