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_queue_ap_abort (struct adiv5_dap *dap, uint8_t *ack)
 
static int swd_queue_ap_bankselect (struct adiv5_ap *ap, unsigned reg)
 Select the AP register bank matching bits 7:4 of reg. More...
 
static int swd_queue_ap_read (struct adiv5_ap *ap, unsigned reg, uint32_t *data)
 
static int swd_queue_ap_write (struct adiv5_ap *ap, unsigned reg, uint32_t data)
 
static int swd_queue_dp_bankselect (struct adiv5_dap *dap, unsigned int reg)
 Select the DP register bank matching bits 7:4 of reg. More...
 
static int swd_queue_dp_read (struct adiv5_dap *dap, unsigned 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 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 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 support only.

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 719 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 706 of file adi_v5_swd.c.

References ERROR_OK.

◆ swd_multidrop_select()

◆ swd_multidrop_select_inner()

◆ 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  reg 
)
static

◆ swd_queue_ap_read()

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

◆ swd_queue_ap_write()

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

◆ swd_queue_dp_bankselect()

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

Select the DP register bank matching bits 7:4 of reg.

Definition at line 103 of file adi_v5_swd.c.

References DP_SELECT, DP_SELECT_INVALID, ERROR_OK, adiv5_dap::select, and swd_queue_dp_write_inner().

Referenced by swd_queue_dp_read_inner(), and swd_queue_dp_write_inner().

◆ swd_queue_dp_read()

static int swd_queue_dp_read ( struct adiv5_dap dap,
unsigned  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  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 606 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 594 of file adi_v5_swd.c.

References 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

◆ 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",
.jim_handler = jim_jtag_newtap,
.mode = COMMAND_CONFIG,
.help = "declare a new SWD DAP"
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_CONFIG
Definition: command.h:41
int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:715

Definition at line 606 of file adi_v5_swd.c.

◆ swd_dap_ops

const struct dap_ops swd_dap_ops
Initial value:
= {
.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:448
static int swd_queue_ap_write(struct adiv5_ap *ap, unsigned reg, uint32_t data)
Definition: adi_v5_swd.c:567
static int swd_connect(struct adiv5_dap *dap)
Definition: adi_v5_swd.c:389
static int swd_queue_dp_read(struct adiv5_dap *dap, unsigned reg, uint32_t *data)
Definition: adi_v5_swd.c:466
static int swd_run(struct adiv5_dap *dap)
Executes all queued DAP operations.
Definition: adi_v5_swd.c:594
static int swd_queue_ap_read(struct adiv5_ap *ap, unsigned reg, uint32_t *data)
Definition: adi_v5_swd.c:542
static int swd_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
Definition: adi_v5_swd.c:56
static void swd_quit(struct adiv5_dap *dap)
Put the SWJ-DP back to JTAG mode.
Definition: adi_v5_swd.c:606
static int swd_queue_dp_write(struct adiv5_dap *dap, unsigned reg, uint32_t data)
Definition: adi_v5_swd.c:480

Definition at line 606 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:650
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235

Definition at line 606 of file adi_v5_swd.c.

Referenced by swd_select().

◆ 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:706
static int swd_select(struct command_context *ctx)
Definition: adi_v5_swd.c:678

Definition at line 706 of file adi_v5_swd.c.

Referenced by transport_is_swd().