OpenOCD
swd.h File Reference
Include dependency graph for swd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  swd_driver
 

Macros

#define ERROR_SWD_FAIL   (-400) /** protocol or parity error */
 
#define ERROR_SWD_FAULT   (-401) /** device returned FAULT in ACK field */
 
#define SWD_CMD_A32   (3 << 3) /* bits A[3:2] of register addr */
 
#define SWD_CMD_APNDP   (1 << 1) /* set only for AP access */
 
#define SWD_CMD_PARITY   (1 << 5) /* parity of APnDP|RnW|A32 */
 
#define SWD_CMD_PARK   (1 << 7) /* driven high by host */
 
#define SWD_CMD_RNW   (1 << 2) /* set only for read access */
 
#define SWD_CMD_START   (1 << 0) /* always set */
 
#define SWD_CMD_STOP   (0 << 6) /* always clear for synch SWD */
 

Functions

static int swd_ack_to_error_code (uint8_t ack)
 Convert SWD ACK value returned from DP to OpenOCD error code. More...
 
static uint8_t swd_cmd (bool is_read, bool is_ap, uint8_t regnum)
 Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver.write_reg() methods will use directly. More...
 
static bool swd_cmd_returns_ack (uint8_t cmd)
 Test if we can rely on ACK returned by SWD command. More...
 
int swd_init_reset (struct command_context *cmd_ctx)
 

Variables

static const uint8_t swd_seq_dormant_to_jtag []
 Dormant-to-JTAG sequence. More...
 
static const unsigned swd_seq_dormant_to_jtag_len = 160
 
static const uint8_t swd_seq_dormant_to_swd []
 Dormant-to-SWD sequence. More...
 
static const unsigned swd_seq_dormant_to_swd_len = 224
 
static const uint8_t swd_seq_jtag_to_dormant []
 JTAG-to-dormant sequence. More...
 
static const unsigned swd_seq_jtag_to_dormant_len = 40
 
static const uint8_t swd_seq_jtag_to_swd []
 JTAG-to-SWD sequence. More...
 
static const unsigned swd_seq_jtag_to_swd_len = 136
 
static const uint8_t swd_seq_line_reset []
 SWD Line reset. More...
 
static const unsigned swd_seq_line_reset_len = 64
 
static const uint8_t swd_seq_swd_to_dormant []
 SWD-to-dormant sequence. More...
 
static const unsigned swd_seq_swd_to_dormant_len = 72
 
static const uint8_t swd_seq_swd_to_jtag []
 SWD-to-JTAG sequence. More...
 
static const unsigned swd_seq_swd_to_jtag_len = 80
 

Macro Definition Documentation

◆ ERROR_SWD_FAIL

#define ERROR_SWD_FAIL   (-400) /** protocol or parity error */

Definition at line 28 of file swd.h.

◆ ERROR_SWD_FAULT

#define ERROR_SWD_FAULT   (-401) /** device returned FAULT in ACK field */

Definition at line 29 of file swd.h.

◆ SWD_CMD_A32

#define SWD_CMD_A32   (3 << 3) /* bits A[3:2] of register addr */

Definition at line 19 of file swd.h.

◆ SWD_CMD_APNDP

#define SWD_CMD_APNDP   (1 << 1) /* set only for AP access */

Definition at line 17 of file swd.h.

◆ SWD_CMD_PARITY

#define SWD_CMD_PARITY   (1 << 5) /* parity of APnDP|RnW|A32 */

Definition at line 20 of file swd.h.

◆ SWD_CMD_PARK

#define SWD_CMD_PARK   (1 << 7) /* driven high by host */

Definition at line 22 of file swd.h.

◆ SWD_CMD_RNW

#define SWD_CMD_RNW   (1 << 2) /* set only for read access */

Definition at line 18 of file swd.h.

◆ SWD_CMD_START

#define SWD_CMD_START   (1 << 0) /* always set */

Definition at line 16 of file swd.h.

◆ SWD_CMD_STOP

#define SWD_CMD_STOP   (0 << 6) /* always clear for synch SWD */

Definition at line 21 of file swd.h.

Function Documentation

◆ swd_ack_to_error_code()

static int swd_ack_to_error_code ( uint8_t  ack)
inlinestatic

Convert SWD ACK value returned from DP to OpenOCD error code.

Parameters
ack
Returns
error code

Definition at line 72 of file swd.h.

References ERROR_OK, ERROR_SWD_FAIL, ERROR_SWD_FAULT, ERROR_WAIT, SWD_ACK_FAULT, SWD_ACK_OK, and SWD_ACK_WAIT.

Referenced by bitbang_swd_read_reg(), bitbang_swd_write_reg(), and ftdi_swd_run_queue().

◆ swd_cmd()

static uint8_t swd_cmd ( bool  is_read,
bool  is_ap,
uint8_t  regnum 
)
inlinestatic

◆ swd_cmd_returns_ack()

static bool swd_cmd_returns_ack ( uint8_t  cmd)
inlinestatic

Test if we can rely on ACK returned by SWD command.

Parameters
cmdByte constructed by swd_cmd(), START, STOP and TRN are filtered off
Returns
true if ACK should be checked, false if should be ignored

Definition at line 58 of file swd.h.

References cmd, DP_TARGETSEL, swd_cmd(), SWD_CMD_A32, SWD_CMD_APNDP, and SWD_CMD_RNW.

Referenced by bitbang_swd_write_reg(), and ftdi_swd_run_queue().

◆ swd_init_reset()

int swd_init_reset ( struct command_context cmd_ctx)

Variable Documentation

◆ swd_seq_dormant_to_jtag

const uint8_t swd_seq_dormant_to_jtag[]
static
Initial value:
= {
0xff,
0x92, 0xf3, 0x09, 0x62, 0x95, 0x2d, 0x85, 0x86,
0xe9, 0xaf, 0xdd, 0xe3, 0xa2, 0x0e, 0xbc, 0x19,
0x00, 0x00,
0x00,
}

Dormant-to-JTAG sequence.

This is at least 8 TCK/SWCLK cycles with TMS/SWDIO high to abort any ongoing selection alert sequence, followed by a specific 128-bit selection alert sequence, followed by 4 TCK/SWCLK cycles with TMS/SWDIO low, followed by a specific protocol-dependent activation code. For JTAG there are two possible activation codes:

  • "JTAG-Serial": 12 bits 0x00, 0x00
  • "Arm CoreSight JTAG-DP": 8 bits 0x0a We use "JTAG-Serial" only, which seams more generic. Since the target TAP can be either in Run/Test Idle or in Test-Logic-Reset states, Arm recommends to put the TAP in Run/Test Idle using one TCK cycle with TMS low. To keep the sequence length multiple of 8, 8 TCK cycle with TMS low are sent (allowed by JTAG state machine). Bits are stored (and transmitted) LSB-first.

Definition at line 230 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_dormant_to_jtag_len

const unsigned swd_seq_dormant_to_jtag_len = 160
static

Definition at line 244 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_dormant_to_swd

const uint8_t swd_seq_dormant_to_swd[]
static
Initial value:
= {
0xff,
0x92, 0xf3, 0x09, 0x62, 0x95, 0x2d, 0x85, 0x86,
0xe9, 0xaf, 0xdd, 0xe3, 0xa2, 0x0e, 0xbc, 0x19,
0xa0,
0xf1,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00,
}

Dormant-to-SWD sequence.

This is at least 8 TCK/SWCLK cycles with TMS/SWDIO high to abort any ongoing selection alert sequence, followed by a specific 128-bit selection alert sequence, followed by 4 TCK/SWCLK cycles with TMS/SWDIO low, followed by a specific protocol-dependent activation code. For SWD the activation code is an 8-bit sequence. The sequence ends with a line reset. Bits are stored (and transmitted) LSB-first.

Definition at line 171 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_dormant_to_swd_len

const unsigned swd_seq_dormant_to_swd_len = 224
static

Definition at line 190 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_jtag_to_dormant

const uint8_t swd_seq_jtag_to_dormant[]
static
Initial value:
= {
0xff,
0x75,
0x77,
0x77,
0x67,
}

JTAG-to-dormant sequence.

This is at least 5 TCK cycles with TMS high to put the interface in test-logic-reset state, followed by a specific 31-bit sequence. Bits are stored (and transmitted) LSB-first.

Definition at line 199 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_jtag_to_dormant_len

const unsigned swd_seq_jtag_to_dormant_len = 40
static

Definition at line 211 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_jtag_to_swd

const uint8_t swd_seq_jtag_to_swd[]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x9e, 0xe7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00,
}

JTAG-to-SWD sequence.

The JTAG-to-SWD sequence is at least 50 TCK/SWCLK cycles with TMS/SWDIO high, putting either interface logic into reset state, followed by a specific 16-bit sequence and finally a line reset in case the SWJ-DP was already in SWD mode. Bits are stored (and transmitted) LSB-first.

Definition at line 115 of file swd.h.

Referenced by bitbang_swd_switch_seq(), buspirate_swd_switch_seq(), cmsis_dap_swd_switch_seq(), jlink_swd_switch_seq(), jtag_send_sequence(), vsllink_swd_switch_seq(), and xlnx_pcie_xvc_swd_switch_seq().

◆ swd_seq_jtag_to_swd_len

◆ swd_seq_line_reset

const uint8_t swd_seq_line_reset[]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00,
}

SWD Line reset.

SWD Line reset is at least 50 SWCLK cycles with SWDIO driven high, followed by at least two idle (low) cycle. Bits are stored (and transmitted) LSB-first.

Definition at line 98 of file swd.h.

Referenced by bitbang_swd_switch_seq(), buspirate_swd_switch_seq(), cmsis_dap_swd_switch_seq(), jlink_swd_switch_seq(), vsllink_swd_switch_seq(), and xlnx_pcie_xvc_swd_switch_seq().

◆ swd_seq_line_reset_len

const unsigned swd_seq_line_reset_len = 64
static

◆ swd_seq_swd_to_dormant

const uint8_t swd_seq_swd_to_dormant[]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xbc, 0xe3,
}

SWD-to-dormant sequence.

This is at least 50 SWCLK cycles with SWDIO high to put the interface in reset state, followed by a specific 16-bit sequence. Bits are stored (and transmitted) LSB-first.

Definition at line 153 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_swd_to_dormant_len

const unsigned swd_seq_swd_to_dormant_len = 72
static

Definition at line 159 of file swd.h.

Referenced by bitbang_swd_switch_seq(), cmsis_dap_swd_switch_seq(), and jlink_swd_switch_seq().

◆ swd_seq_swd_to_jtag

const uint8_t swd_seq_swd_to_jtag[]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x3c, 0xe7,
0xff,
}

SWD-to-JTAG sequence.

The SWD-to-JTAG sequence is at least 50 TCK/SWCLK cycles with TMS/SWDIO high, putting either interface logic into reset state, followed by a specific 16-bit sequence and finally at least 5 TCK/SWCLK cycles with TMS/SWDIO high to put the JTAG TAP in Test-Logic-Reset state. Bits are stored (and transmitted) LSB-first.

Definition at line 136 of file swd.h.

Referenced by bitbang_swd_switch_seq(), buspirate_swd_switch_seq(), cmsis_dap_swd_switch_seq(), jlink_swd_switch_seq(), jtag_send_sequence(), vsllink_swd_switch_seq(), and xlnx_pcie_xvc_swd_switch_seq().

◆ swd_seq_swd_to_jtag_len