OpenOCD
adi_v5_swd.c File Reference

Utilities to support ARM "Serial Wire Debug" (SWD), a low pin-count debug link protocol used in cases where JTAG is not wanted. More...

Include dependency graph for adi_v5_swd.c:

Go to the source code of this file.

Functions

static int check_sync (struct adiv5_dap *dap)
 
static int swd_check_reconnect (struct adiv5_dap *dap)
 
static void swd_clear_sticky_errors (struct adiv5_dap *dap)
 
static int swd_connect (struct adiv5_dap *dap)
 
static int swd_connect_multidrop (struct adiv5_dap *dap)
 
static int swd_connect_single (struct adiv5_dap *dap)
 
static void swd_constructor (void)
 
static void swd_finish_read (struct adiv5_dap *dap)
 
static int swd_init (struct command_context *ctx)
 
static int swd_multidrop_select (struct adiv5_dap *dap)
 
static int swd_multidrop_select_inner (struct adiv5_dap *dap, uint32_t *dpidr_ptr, uint32_t *dlpidr_ptr, bool clear_sticky)
 
static int swd_pre_connect (struct adiv5_dap *dap)
 
static int swd_queue_ap_abort (struct adiv5_dap *dap, uint8_t *ack)
 
static int swd_queue_ap_bankselect (struct adiv5_ap *ap, unsigned int reg)
 Select the AP register bank. More...
 
static int swd_queue_ap_read (struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
 
static int swd_queue_ap_write (struct adiv5_ap *ap, unsigned int reg, uint32_t data)
 
static int swd_queue_dp_bankselect (struct adiv5_dap *dap, unsigned int reg)
 Select the DP register bank. More...
 
static int swd_queue_dp_read (struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
 
static int swd_queue_dp_read_inner (struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
 
static int swd_queue_dp_write (struct adiv5_dap *dap, unsigned int reg, uint32_t data)
 
static int swd_queue_dp_write_inner (struct adiv5_dap *dap, unsigned int reg, uint32_t data)
 
static void swd_quit (struct adiv5_dap *dap)
 Put the SWJ-DP back to JTAG mode. More...
 
static int swd_run (struct adiv5_dap *dap)
 Executes all queued DAP operations. More...
 
static int swd_run_inner (struct adiv5_dap *dap)
 
static int swd_select (struct command_context *ctx)
 
static int swd_send_sequence (struct adiv5_dap *dap, enum swd_special_seq seq)
 
bool transport_is_swd (void)
 Returns true if the current debug session is using SWD as its transport. More...
 

Variables

static bool do_sync
 
static const struct command_registration swd_commands []
 
const struct dap_ops swd_dap_ops
 
static const struct command_registration swd_handlers []
 
static bool swd_multidrop_in_swd_state
 
static struct adiv5_dapswd_multidrop_selected_dap
 
static struct transport swd_transport
 

Detailed Description

Utilities to support ARM "Serial Wire Debug" (SWD), a low pin-count debug link protocol used in cases where JTAG is not wanted.

This is coupled to recent versions of ARM's "CoreSight" debug framework. This specific code is a transport level interface, with "target/arm_adi_v5.[hc]" code understanding operation semantics, shared with the JTAG transport.

Single DAP and multidrop-SWD support.

for details, see "ARM IHI 0031A" ARM Debug Interface v5 Architecture Specification especially section 5.3 for SWD protocol and "ARM IHI 0074C" ARM Debug Interface Architecture Specification ADIv6.0

On many chips (most current Cortex-M3 parts) SWD is a run-time alternative to JTAG. Boards may support one or both. There are also SWD-only chips, (using SW-DP not SWJ-DP).

Even boards that also support JTAG can benefit from SWD support, because usually there's no way to access the SWO trace view mechanism in JTAG mode. That is, trace access may require SWD support.

Definition in file adi_v5_swd.c.

Function Documentation

◆ check_sync()

static int check_sync ( struct adiv5_dap dap)
inlinestatic

◆ swd_check_reconnect()

static int swd_check_reconnect ( struct adiv5_dap dap)
static

◆ swd_clear_sticky_errors()

static void swd_clear_sticky_errors ( struct adiv5_dap dap)
static

◆ swd_connect()

◆ swd_connect_multidrop()

◆ swd_connect_single()

◆ swd_constructor()

static void swd_constructor ( void  )
static

Definition at line 767 of file adi_v5_swd.c.

◆ swd_finish_read()

static void swd_finish_read ( struct adiv5_dap dap)
static

◆ swd_init()

static int swd_init ( struct command_context ctx)
static

Definition at line 754 of file adi_v5_swd.c.

References ERROR_OK.

◆ swd_multidrop_select()

◆ swd_multidrop_select_inner()

◆ swd_pre_connect()

static int swd_pre_connect ( struct adiv5_dap dap)
static

Definition at line 404 of file adi_v5_swd.c.

References ERROR_OK, and swd_multidrop_in_swd_state.

◆ swd_queue_ap_abort()

static int swd_queue_ap_abort ( struct adiv5_dap dap,
uint8_t *  ack 
)
static

◆ swd_queue_ap_bankselect()

static int swd_queue_ap_bankselect ( struct adiv5_ap ap,
unsigned int  reg 
)
static

◆ swd_queue_ap_read()

static int swd_queue_ap_read ( struct adiv5_ap ap,
unsigned int  reg,
uint32_t *  data 
)
static

◆ swd_queue_ap_write()

static int swd_queue_ap_write ( struct adiv5_ap ap,
unsigned int  reg,
uint32_t  data 
)
static

◆ swd_queue_dp_bankselect()

static int swd_queue_dp_bankselect ( struct adiv5_dap dap,
unsigned int  reg 
)
static

◆ swd_queue_dp_read()

static int swd_queue_dp_read ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t *  data 
)
static

◆ swd_queue_dp_read_inner()

static int swd_queue_dp_read_inner ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t *  data 
)
static

◆ swd_queue_dp_write()

static int swd_queue_dp_write ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t  data 
)
static

◆ swd_queue_dp_write_inner()

◆ swd_quit()

static void swd_quit ( struct adiv5_dap dap)
static

Put the SWJ-DP back to JTAG mode.

Definition at line 640 of file adi_v5_swd.c.

◆ swd_run()

static int swd_run ( struct adiv5_dap dap)
static

Executes all queued DAP operations.

Definition at line 622 of file adi_v5_swd.c.

References adiv5_dap::do_reconnect, ERROR_OK, swd_finish_read(), swd_multidrop_select(), and swd_run_inner().

◆ swd_run_inner()

static int swd_run_inner ( struct adiv5_dap dap)
static

◆ swd_select()

◆ swd_send_sequence()

static int swd_send_sequence ( struct adiv5_dap dap,
enum swd_special_seq  seq 
)
static

Definition at line 58 of file adi_v5_swd.c.

References adiv5_dap_swd_driver(), and swd_driver::switch_seq.

Referenced by swd_connect_single(), and swd_multidrop_select_inner().

◆ transport_is_swd()

bool transport_is_swd ( void  )

Variable Documentation

◆ do_sync

bool do_sync
static

Definition at line 47 of file adi_v5_swd.c.

Referenced by check_sync().

◆ swd_commands

const struct command_registration swd_commands[]
static
Initial value:
= {
{
.name = "newdap",
.handler = handle_jtag_newtap,
.mode = COMMAND_CONFIG,
.help = "declare a new SWD DAP",
.usage = "basename dap_type ['-irlen' count] "
"['-enable'|'-disable'] "
"['-expected_id' number] "
"['-ignore-version'] "
"['-ignore-bypass'] "
"['-ircapture' number] "
"['-ir-bypass' number] "
"['-mask' number]",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 640 of file adi_v5_swd.c.

◆ swd_dap_ops

const struct dap_ops swd_dap_ops
Initial value:
= {
.pre_connect_init = swd_pre_connect,
.connect = swd_connect,
.send_sequence = swd_send_sequence,
.queue_dp_read = swd_queue_dp_read,
.queue_dp_write = swd_queue_dp_write,
.queue_ap_read = swd_queue_ap_read,
.queue_ap_write = swd_queue_ap_write,
.queue_ap_abort = swd_queue_ap_abort,
.run = swd_run,
.quit = swd_quit,
}
static int swd_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
Definition: adi_v5_swd.c:470
static int swd_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
Definition: adi_v5_swd.c:570
static int swd_queue_dp_write(struct adiv5_dap *dap, unsigned int reg, uint32_t data)
Definition: adi_v5_swd.c:502
static int swd_connect(struct adiv5_dap *dap)
Definition: adi_v5_swd.c:411
static int swd_pre_connect(struct adiv5_dap *dap)
Definition: adi_v5_swd.c:404
static int swd_run(struct adiv5_dap *dap)
Executes all queued DAP operations.
Definition: adi_v5_swd.c:622
static int swd_queue_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data)
Definition: adi_v5_swd.c:595
static int swd_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
Definition: adi_v5_swd.c:58
static void swd_quit(struct adiv5_dap *dap)
Put the SWJ-DP back to JTAG mode.
Definition: adi_v5_swd.c:640
static int swd_queue_dp_read(struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
Definition: adi_v5_swd.c:488

Definition at line 640 of file adi_v5_swd.c.

Referenced by dap_init_all().

◆ swd_handlers

const struct command_registration swd_handlers[]
static
Initial value:
= {
{
.name = "swd",
.mode = COMMAND_ANY,
.help = "SWD command group",
.chain = swd_commands,
.usage = "",
},
}
static const struct command_registration swd_commands[]
Definition: adi_v5_swd.c:690
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241

Definition at line 640 of file adi_v5_swd.c.

Referenced by swd_select().

◆ swd_multidrop_in_swd_state

bool swd_multidrop_in_swd_state
static

Definition at line 51 of file adi_v5_swd.c.

Referenced by swd_connect_multidrop(), swd_multidrop_select_inner(), and swd_pre_connect().

◆ swd_multidrop_selected_dap

struct adiv5_dap* swd_multidrop_selected_dap
static

◆ swd_transport

struct transport swd_transport
static
Initial value:
= {
.name = "swd",
.select = swd_select,
.init = swd_init,
}
static int swd_init(struct command_context *ctx)
Definition: adi_v5_swd.c:754
static int swd_select(struct command_context *ctx)
Definition: adi_v5_swd.c:726

Definition at line 754 of file adi_v5_swd.c.

Referenced by transport_is_swd().