OpenOCD
cmsis_dap.c File Reference
Include dependency graph for cmsis_dap.c:

Go to the source code of this file.

Data Structures

struct  pending_request_block
 
struct  pending_scan_result
 
struct  pending_transfer_result
 

Macros

#define CMD_DAP_CONNECT   0x02
 
#define CMD_DAP_DELAY   0x09
 
#define CMD_DAP_DELAY   0x09
 
#define CMD_DAP_DISCONNECT   0x03
 
#define CMD_DAP_INFO   0x00
 
#define CMD_DAP_JTAG_CONFIGURE   0x15
 
#define CMD_DAP_JTAG_IDCODE   0x16
 
#define CMD_DAP_JTAG_SEQ   0x14
 
#define CMD_DAP_LED   0x01
 
#define CMD_DAP_RESET_TARGET   0x0A
 
#define CMD_DAP_SWD_CONFIGURE   0x13
 
#define CMD_DAP_SWD_SEQUENCE   0x1D
 
#define CMD_DAP_SWJ_CLOCK   0x11
 
#define CMD_DAP_SWJ_PINS   0x10
 
#define CMD_DAP_SWJ_SEQ   0x12
 
#define CMD_DAP_SWO_BAUDRATE   0x19
 
#define CMD_DAP_SWO_CONTROL   0x1A
 
#define CMD_DAP_SWO_DATA   0x1C
 
#define CMD_DAP_SWO_EX_STATUS   0x1E
 
#define CMD_DAP_SWO_MODE   0x18
 
#define CMD_DAP_SWO_STATUS   0x1B
 
#define CMD_DAP_SWO_TRANSPORT   0x17
 
#define CMD_DAP_TFER   0x05
 
#define CMD_DAP_TFER_ABORT   0x07
 
#define CMD_DAP_TFER_BLOCK   0x06
 
#define CMD_DAP_TFER_CONFIGURE   0x04
 
#define CMD_DAP_WRITE_ABORT   0x08
 
#define CONNECT_DEFAULT   0x00
 
#define CONNECT_JTAG   0x02
 
#define CONNECT_SWD   0x01
 
#define DAP_ERROR   0xFF
 
#define DAP_JTAG_SEQ_TCK   0x3F
 
#define DAP_JTAG_SEQ_TDO   0x80
 
#define DAP_JTAG_SEQ_TMS   0x40
 
#define DAP_OK   0
 
#define DAP_SWO_CONTROL_START   1
 
#define DAP_SWO_CONTROL_STOP   0
 
#define DAP_SWO_MODE_MANCHESTER   2
 
#define DAP_SWO_MODE_OFF   0
 
#define DAP_SWO_MODE_UART   1
 
#define DAP_SWO_STATUS_BUFFER_OVERRUN_MASK   BIT(7)
 
#define DAP_SWO_STATUS_CAPTURE_ACTIVE   1
 
#define DAP_SWO_STATUS_CAPTURE_INACTIVE   0
 
#define DAP_SWO_STATUS_CAPTURE_MASK   BIT(0)
 
#define DAP_SWO_STATUS_STREAM_ERROR_MASK   BIT(6)
 
#define DAP_SWO_TRANSPORT_DATA   1
 
#define DAP_SWO_TRANSPORT_NONE   0
 
#define DAP_SWO_TRANSPORT_WINUSB   2
 
#define INFO_CAPS__NUM_CAPS   9
 
#define INFO_CAPS_ATOMIC_CMDS   BIT(4)
 
#define INFO_CAPS_JTAG   BIT(1)
 
#define INFO_CAPS_SWD   BIT(0)
 
#define INFO_CAPS_SWO_MANCHESTER   BIT(3)
 
#define INFO_CAPS_SWO_STREAMING_TRACE   BIT(6)
 
#define INFO_CAPS_SWO_UART   BIT(2)
 
#define INFO_CAPS_TEST_DOMAIN_TIMER   BIT(5)
 
#define INFO_CAPS_UART_PORT   BIT(7)
 
#define INFO_CAPS_USB_COM_PORT   BIT(8)
 
#define INFO_ID_CAPS   0xf0 /* byte */
 
#define INFO_ID_FW_VER   0x04 /* string */
 
#define INFO_ID_PKT_CNT   0xfe /* byte */
 
#define INFO_ID_PKT_SZ   0xff /* short */
 
#define INFO_ID_PRODUCT   0x02 /* string */
 
#define INFO_ID_SERNUM   0x03 /* string */
 
#define INFO_ID_SWO_BUF_SZ   0xfd /* word */
 
#define INFO_ID_TD_NAME   0x06 /* string */
 
#define INFO_ID_TD_VEND   0x05 /* string */
 
#define INFO_ID_VENDOR   0x01 /* string */
 
#define LED_ID_CONNECT   0x00
 
#define LED_ID_RUN   0x01
 
#define LED_OFF   0x00
 
#define LED_ON   0x01
 
#define MAX_PENDING_REQUESTS   3
 
#define MAX_PENDING_SCAN_RESULTS   256
 
#define MAX_USB_IDS   8
 
#define QUEUED_SEQ_BUF_LEN   (cmsis_dap_handle->packet_size - 3)
 
#define SWJ_PIN_SRST   (1<<7)
 
#define SWJ_PIN_TCK   (1<<0)
 
#define SWJ_PIN_TDI   (1<<2)
 
#define SWJ_PIN_TDO   (1<<3)
 
#define SWJ_PIN_TMS   (1<<1)
 
#define SWJ_PIN_TRST   (1<<5)
 

Functions

static bool calculate_swo_prescaler (unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler)
 
static void cmsis_dap_add_jtag_sequence (int s_len, const uint8_t *sequence, int s_offset, bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset)
 
static void cmsis_dap_add_tms_sequence (const uint8_t *sequence, int s_len)
 
static void cmsis_dap_close (struct cmsis_dap *dap)
 
static int cmsis_dap_cmd_dap_connect (uint8_t mode)
 
static int cmsis_dap_cmd_dap_disconnect (void)
 
static int cmsis_dap_cmd_dap_info (uint8_t info, uint8_t **data)
 
static int cmsis_dap_cmd_dap_led (uint8_t led, uint8_t state)
 
static int cmsis_dap_cmd_dap_swd_configure (uint8_t cfg)
 
static int cmsis_dap_cmd_dap_swj_clock (uint32_t swj_clock)
 
static int cmsis_dap_cmd_dap_swj_pins (uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input)
 
static int cmsis_dap_cmd_dap_swj_sequence (uint8_t s_len, const uint8_t *sequence)
 
static int cmsis_dap_cmd_dap_swo_baudrate (uint32_t in_baudrate, uint32_t *dev_baudrate)
 Sets the baudrate for capturing SWO trace data. More...
 
static int cmsis_dap_cmd_dap_swo_control (uint8_t control)
 Controls the SWO trace data capture. More...
 
static int cmsis_dap_cmd_dap_swo_data (size_t max_trace_count, uint8_t *trace_status, size_t *trace_count, uint8_t *data)
 Reads the captured SWO trace data from Trace Buffer. More...
 
static int cmsis_dap_cmd_dap_swo_mode (uint8_t mode)
 Sets the SWO trace capture mode. More...
 
static int cmsis_dap_cmd_dap_swo_status (uint8_t *trace_status, size_t *trace_count)
 Reads the SWO trace status. More...
 
static int cmsis_dap_cmd_dap_swo_transport (uint8_t transport)
 Sets the SWO transport mode. More...
 
static int cmsis_dap_cmd_dap_tfer_configure (uint8_t idle, uint16_t retry_count, uint16_t match_retry)
 
static int cmsis_dap_config_trace (bool trace_enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *swo_freq, unsigned int traceclkin_hz, uint16_t *swo_prescaler)
 
static void cmsis_dap_end_state (tap_state_t state)
 
static void cmsis_dap_execute_command (struct jtag_command *cmd)
 
static void cmsis_dap_execute_pathmove (struct jtag_command *cmd)
 
static int cmsis_dap_execute_queue (void)
 
static void cmsis_dap_execute_runtest (struct jtag_command *cmd)
 
static void cmsis_dap_execute_scan (struct jtag_command *cmd)
 
static void cmsis_dap_execute_sleep (struct jtag_command *cmd)
 
static void cmsis_dap_execute_stableclocks (struct jtag_command *cmd)
 
static int cmsis_dap_execute_tlr_reset (struct jtag_command *cmd)
 
static void cmsis_dap_execute_tms (struct jtag_command *cmd)
 
static void cmsis_dap_flush (void)
 
static void cmsis_dap_flush_read (struct cmsis_dap *dap)
 
static int cmsis_dap_get_caps_info (void)
 
static int cmsis_dap_get_serial_info (void)
 
static int cmsis_dap_get_status (void)
 
static int cmsis_dap_get_swo_buf_sz (uint32_t *swo_buf_sz)
 
static int cmsis_dap_get_version_info (void)
 
static int cmsis_dap_init (void)
 
static int cmsis_dap_khz (int khz, int *jtag_speed)
 
static int cmsis_dap_metacmd_targetsel (uint32_t instance_id)
 
static int cmsis_dap_open (void)
 
static void cmsis_dap_pathmove (int num_states, tap_state_t *path)
 
static int cmsis_dap_poll_trace (uint8_t *buf, size_t *size)
 
static int cmsis_dap_quit (void)
 
static int cmsis_dap_reset (int trst, int srst)
 
static void cmsis_dap_runtest (int num_cycles)
 
static int cmsis_dap_speed (int speed)
 
static int cmsis_dap_speed_div (int speed, int *khz)
 
static void cmsis_dap_stableclocks (int num_cycles)
 
static void cmsis_dap_state_move (void)
 
static int cmsis_dap_swd_init (void)
 
static int cmsis_dap_swd_open (void)
 
static void cmsis_dap_swd_queue_cmd (uint8_t cmd, uint32_t *dst, uint32_t data)
 
static void cmsis_dap_swd_read_process (struct cmsis_dap *dap, int timeout_ms)
 
static void cmsis_dap_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 
static int cmsis_dap_swd_run_queue (void)
 
static int cmsis_dap_swd_switch_seq (enum swd_special_seq seq)
 
static void cmsis_dap_swd_write_from_queue (struct cmsis_dap *dap)
 
static void cmsis_dap_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 
static int cmsis_dap_xfer (struct cmsis_dap *dap, int txlen)
 
 COMMAND_HANDLER (cmsis_dap_handle_backend_command)
 
 COMMAND_HANDLER (cmsis_dap_handle_cmd_command)
 
 COMMAND_HANDLER (cmsis_dap_handle_info_command)
 
 COMMAND_HANDLER (cmsis_dap_handle_vid_pid_command)
 

Variables

struct adapter_driver cmsis_dap_adapter_driver
 
static int cmsis_dap_backend = -1
 
static const struct cmsis_dap_backend *const cmsis_dap_backends []
 
static const struct command_registration cmsis_dap_command_handlers []
 
static struct cmsis_dapcmsis_dap_handle
 
static struct jtag_interface cmsis_dap_interface
 
static uint16_t cmsis_dap_pid [MAX_USB_IDS+1] = { 0 }
 
static const struct command_registration cmsis_dap_subcommand_handlers []
 
static const struct swd_driver cmsis_dap_swd_driver
 
static const char *const cmsis_dap_transport [] = { "swd", "jtag", NULL }
 
static uint16_t cmsis_dap_vid [MAX_USB_IDS+1] = { 0 }
 
static const char *const info_caps_str [INFO_CAPS__NUM_CAPS]
 
static uint8_t output_pins = SWJ_PIN_SRST | SWJ_PIN_TRST
 
static struct pending_request_block pending_fifo [MAX_PENDING_REQUESTS]
 
static int pending_fifo_block_count
 
static int pending_fifo_get_idx
 
static int pending_fifo_put_idx
 
static int pending_queue_len
 
static int pending_scan_result_count
 
static struct pending_scan_result pending_scan_results [MAX_PENDING_SCAN_RESULTS]
 
static int queued_retval
 
static uint8_t queued_seq_buf [1024]
 
static int queued_seq_buf_end
 
static int queued_seq_count
 
static int queued_seq_tdo_ptr
 
static bool swd_mode
 

Macro Definition Documentation

◆ CMD_DAP_CONNECT

#define CMD_DAP_CONNECT   0x02

Definition at line 75 of file cmsis_dap.c.

◆ CMD_DAP_DELAY [1/2]

#define CMD_DAP_DELAY   0x09

Definition at line 117 of file cmsis_dap.c.

◆ CMD_DAP_DELAY [2/2]

#define CMD_DAP_DELAY   0x09

Definition at line 117 of file cmsis_dap.c.

◆ CMD_DAP_DISCONNECT

#define CMD_DAP_DISCONNECT   0x03

Definition at line 76 of file cmsis_dap.c.

◆ CMD_DAP_INFO

#define CMD_DAP_INFO   0x00

Definition at line 73 of file cmsis_dap.c.

◆ CMD_DAP_JTAG_CONFIGURE

#define CMD_DAP_JTAG_CONFIGURE   0x15

Definition at line 145 of file cmsis_dap.c.

◆ CMD_DAP_JTAG_IDCODE

#define CMD_DAP_JTAG_IDCODE   0x16

Definition at line 146 of file cmsis_dap.c.

◆ CMD_DAP_JTAG_SEQ

#define CMD_DAP_JTAG_SEQ   0x14

Definition at line 144 of file cmsis_dap.c.

◆ CMD_DAP_LED

#define CMD_DAP_LED   0x01

Definition at line 74 of file cmsis_dap.c.

◆ CMD_DAP_RESET_TARGET

#define CMD_DAP_RESET_TARGET   0x0A

Definition at line 79 of file cmsis_dap.c.

◆ CMD_DAP_SWD_CONFIGURE

#define CMD_DAP_SWD_CONFIGURE   0x13

Definition at line 140 of file cmsis_dap.c.

◆ CMD_DAP_SWD_SEQUENCE

#define CMD_DAP_SWD_SEQUENCE   0x1D

Definition at line 141 of file cmsis_dap.c.

◆ CMD_DAP_SWJ_CLOCK

#define CMD_DAP_SWJ_CLOCK   0x11

Definition at line 119 of file cmsis_dap.c.

◆ CMD_DAP_SWJ_PINS

#define CMD_DAP_SWJ_PINS   0x10

Definition at line 118 of file cmsis_dap.c.

◆ CMD_DAP_SWJ_SEQ

#define CMD_DAP_SWJ_SEQ   0x12

Definition at line 120 of file cmsis_dap.c.

◆ CMD_DAP_SWO_BAUDRATE

#define CMD_DAP_SWO_BAUDRATE   0x19

Definition at line 170 of file cmsis_dap.c.

◆ CMD_DAP_SWO_CONTROL

#define CMD_DAP_SWO_CONTROL   0x1A

Definition at line 171 of file cmsis_dap.c.

◆ CMD_DAP_SWO_DATA

#define CMD_DAP_SWO_DATA   0x1C

Definition at line 173 of file cmsis_dap.c.

◆ CMD_DAP_SWO_EX_STATUS

#define CMD_DAP_SWO_EX_STATUS   0x1E

Definition at line 174 of file cmsis_dap.c.

◆ CMD_DAP_SWO_MODE

#define CMD_DAP_SWO_MODE   0x18

Definition at line 169 of file cmsis_dap.c.

◆ CMD_DAP_SWO_STATUS

#define CMD_DAP_SWO_STATUS   0x1B

Definition at line 172 of file cmsis_dap.c.

◆ CMD_DAP_SWO_TRANSPORT

#define CMD_DAP_SWO_TRANSPORT   0x17

Definition at line 168 of file cmsis_dap.c.

◆ CMD_DAP_TFER

#define CMD_DAP_TFER   0x05

Definition at line 159 of file cmsis_dap.c.

◆ CMD_DAP_TFER_ABORT

#define CMD_DAP_TFER_ABORT   0x07

Definition at line 161 of file cmsis_dap.c.

◆ CMD_DAP_TFER_BLOCK

#define CMD_DAP_TFER_BLOCK   0x06

Definition at line 160 of file cmsis_dap.c.

◆ CMD_DAP_TFER_CONFIGURE

#define CMD_DAP_TFER_CONFIGURE   0x04

Definition at line 158 of file cmsis_dap.c.

◆ CMD_DAP_WRITE_ABORT

#define CMD_DAP_WRITE_ABORT   0x08

Definition at line 77 of file cmsis_dap.c.

◆ CONNECT_DEFAULT

#define CONNECT_DEFAULT   0x00

Definition at line 112 of file cmsis_dap.c.

◆ CONNECT_JTAG

#define CONNECT_JTAG   0x02

Definition at line 114 of file cmsis_dap.c.

◆ CONNECT_SWD

#define CONNECT_SWD   0x01

Definition at line 113 of file cmsis_dap.c.

◆ DAP_ERROR

#define DAP_ERROR   0xFF

Definition at line 165 of file cmsis_dap.c.

◆ DAP_JTAG_SEQ_TCK

#define DAP_JTAG_SEQ_TCK   0x3F

Definition at line 150 of file cmsis_dap.c.

◆ DAP_JTAG_SEQ_TDO

#define DAP_JTAG_SEQ_TDO   0x80

Definition at line 154 of file cmsis_dap.c.

◆ DAP_JTAG_SEQ_TMS

#define DAP_JTAG_SEQ_TMS   0x40

Definition at line 152 of file cmsis_dap.c.

◆ DAP_OK

#define DAP_OK   0

Definition at line 164 of file cmsis_dap.c.

◆ DAP_SWO_CONTROL_START

#define DAP_SWO_CONTROL_START   1

Definition at line 188 of file cmsis_dap.c.

◆ DAP_SWO_CONTROL_STOP

#define DAP_SWO_CONTROL_STOP   0

Definition at line 187 of file cmsis_dap.c.

◆ DAP_SWO_MODE_MANCHESTER

#define DAP_SWO_MODE_MANCHESTER   2

Definition at line 184 of file cmsis_dap.c.

◆ DAP_SWO_MODE_OFF

#define DAP_SWO_MODE_OFF   0

Definition at line 182 of file cmsis_dap.c.

◆ DAP_SWO_MODE_UART

#define DAP_SWO_MODE_UART   1

Definition at line 183 of file cmsis_dap.c.

◆ DAP_SWO_STATUS_BUFFER_OVERRUN_MASK

#define DAP_SWO_STATUS_BUFFER_OVERRUN_MASK   BIT(7)

Definition at line 195 of file cmsis_dap.c.

◆ DAP_SWO_STATUS_CAPTURE_ACTIVE

#define DAP_SWO_STATUS_CAPTURE_ACTIVE   1

Definition at line 192 of file cmsis_dap.c.

◆ DAP_SWO_STATUS_CAPTURE_INACTIVE

#define DAP_SWO_STATUS_CAPTURE_INACTIVE   0

Definition at line 191 of file cmsis_dap.c.

◆ DAP_SWO_STATUS_CAPTURE_MASK

#define DAP_SWO_STATUS_CAPTURE_MASK   BIT(0)

Definition at line 193 of file cmsis_dap.c.

◆ DAP_SWO_STATUS_STREAM_ERROR_MASK

#define DAP_SWO_STATUS_STREAM_ERROR_MASK   BIT(6)

Definition at line 194 of file cmsis_dap.c.

◆ DAP_SWO_TRANSPORT_DATA

#define DAP_SWO_TRANSPORT_DATA   1

Definition at line 178 of file cmsis_dap.c.

◆ DAP_SWO_TRANSPORT_NONE

#define DAP_SWO_TRANSPORT_NONE   0

Definition at line 177 of file cmsis_dap.c.

◆ DAP_SWO_TRANSPORT_WINUSB

#define DAP_SWO_TRANSPORT_WINUSB   2

Definition at line 179 of file cmsis_dap.c.

◆ INFO_CAPS__NUM_CAPS

#define INFO_CAPS__NUM_CAPS   9

Definition at line 102 of file cmsis_dap.c.

◆ INFO_CAPS_ATOMIC_CMDS

#define INFO_CAPS_ATOMIC_CMDS   BIT(4)

Definition at line 97 of file cmsis_dap.c.

◆ INFO_CAPS_JTAG

#define INFO_CAPS_JTAG   BIT(1)

Definition at line 94 of file cmsis_dap.c.

◆ INFO_CAPS_SWD

#define INFO_CAPS_SWD   BIT(0)

Definition at line 93 of file cmsis_dap.c.

◆ INFO_CAPS_SWO_MANCHESTER

#define INFO_CAPS_SWO_MANCHESTER   BIT(3)

Definition at line 96 of file cmsis_dap.c.

◆ INFO_CAPS_SWO_STREAMING_TRACE

#define INFO_CAPS_SWO_STREAMING_TRACE   BIT(6)

Definition at line 99 of file cmsis_dap.c.

◆ INFO_CAPS_SWO_UART

#define INFO_CAPS_SWO_UART   BIT(2)

Definition at line 95 of file cmsis_dap.c.

◆ INFO_CAPS_TEST_DOMAIN_TIMER

#define INFO_CAPS_TEST_DOMAIN_TIMER   BIT(5)

Definition at line 98 of file cmsis_dap.c.

◆ INFO_CAPS_UART_PORT

#define INFO_CAPS_UART_PORT   BIT(7)

Definition at line 100 of file cmsis_dap.c.

◆ INFO_CAPS_USB_COM_PORT

#define INFO_CAPS_USB_COM_PORT   BIT(8)

Definition at line 101 of file cmsis_dap.c.

◆ INFO_ID_CAPS

#define INFO_ID_CAPS   0xf0 /* byte */

Definition at line 88 of file cmsis_dap.c.

◆ INFO_ID_FW_VER

#define INFO_ID_FW_VER   0x04 /* string */

Definition at line 85 of file cmsis_dap.c.

◆ INFO_ID_PKT_CNT

#define INFO_ID_PKT_CNT   0xfe /* byte */

Definition at line 89 of file cmsis_dap.c.

◆ INFO_ID_PKT_SZ

#define INFO_ID_PKT_SZ   0xff /* short */

Definition at line 90 of file cmsis_dap.c.

◆ INFO_ID_PRODUCT

#define INFO_ID_PRODUCT   0x02 /* string */

Definition at line 83 of file cmsis_dap.c.

◆ INFO_ID_SERNUM

#define INFO_ID_SERNUM   0x03 /* string */

Definition at line 84 of file cmsis_dap.c.

◆ INFO_ID_SWO_BUF_SZ

#define INFO_ID_SWO_BUF_SZ   0xfd /* word */

Definition at line 91 of file cmsis_dap.c.

◆ INFO_ID_TD_NAME

#define INFO_ID_TD_NAME   0x06 /* string */

Definition at line 87 of file cmsis_dap.c.

◆ INFO_ID_TD_VEND

#define INFO_ID_TD_VEND   0x05 /* string */

Definition at line 86 of file cmsis_dap.c.

◆ INFO_ID_VENDOR

#define INFO_ID_VENDOR   0x01 /* string */

Definition at line 82 of file cmsis_dap.c.

◆ LED_ID_CONNECT

#define LED_ID_CONNECT   0x00

Definition at line 105 of file cmsis_dap.c.

◆ LED_ID_RUN

#define LED_ID_RUN   0x01

Definition at line 106 of file cmsis_dap.c.

◆ LED_OFF

#define LED_OFF   0x00

Definition at line 108 of file cmsis_dap.c.

◆ LED_ON

#define LED_ON   0x01

Definition at line 109 of file cmsis_dap.c.

◆ MAX_PENDING_REQUESTS

#define MAX_PENDING_REQUESTS   3

Definition at line 236 of file cmsis_dap.c.

◆ MAX_PENDING_SCAN_RESULTS

#define MAX_PENDING_SCAN_RESULTS   256

Definition at line 246 of file cmsis_dap.c.

◆ MAX_USB_IDS

#define MAX_USB_IDS   8

Definition at line 65 of file cmsis_dap.c.

◆ QUEUED_SEQ_BUF_LEN

#define QUEUED_SEQ_BUF_LEN   (cmsis_dap_handle->packet_size - 3)

Definition at line 251 of file cmsis_dap.c.

◆ SWJ_PIN_SRST

#define SWJ_PIN_SRST   (1<<7)

Definition at line 137 of file cmsis_dap.c.

◆ SWJ_PIN_TCK

#define SWJ_PIN_TCK   (1<<0)

Definition at line 132 of file cmsis_dap.c.

◆ SWJ_PIN_TDI

#define SWJ_PIN_TDI   (1<<2)

Definition at line 134 of file cmsis_dap.c.

◆ SWJ_PIN_TDO

#define SWJ_PIN_TDO   (1<<3)

Definition at line 135 of file cmsis_dap.c.

◆ SWJ_PIN_TMS

#define SWJ_PIN_TMS   (1<<1)

Definition at line 133 of file cmsis_dap.c.

◆ SWJ_PIN_TRST

#define SWJ_PIN_TRST   (1<<5)

Definition at line 136 of file cmsis_dap.c.

Function Documentation

◆ calculate_swo_prescaler()

static bool calculate_swo_prescaler ( unsigned int  traceclkin_freq,
uint32_t  trace_freq,
uint16_t *  prescaler 
)
static

Definition at line 1836 of file cmsis_dap.c.

References TPIU_ACPR_MAX_SWOSCALER.

Referenced by cmsis_dap_config_trace().

◆ cmsis_dap_add_jtag_sequence()

static void cmsis_dap_add_jtag_sequence ( int  s_len,
const uint8_t *  sequence,
int  s_offset,
bool  tms,
uint8_t *  tdo_buffer,
int  tdo_buffer_offset 
)
static

◆ cmsis_dap_add_tms_sequence()

static void cmsis_dap_add_tms_sequence ( const uint8_t *  sequence,
int  s_len 
)
static

◆ cmsis_dap_close()

static void cmsis_dap_close ( struct cmsis_dap dap)
static

◆ cmsis_dap_cmd_dap_connect()

static int cmsis_dap_cmd_dap_connect ( uint8_t  mode)
static

◆ cmsis_dap_cmd_dap_disconnect()

static int cmsis_dap_cmd_dap_disconnect ( void  )
static

◆ cmsis_dap_cmd_dap_info()

◆ cmsis_dap_cmd_dap_led()

static int cmsis_dap_cmd_dap_led ( uint8_t  led,
uint8_t  state 
)
static

◆ cmsis_dap_cmd_dap_swd_configure()

static int cmsis_dap_cmd_dap_swd_configure ( uint8_t  cfg)
static

◆ cmsis_dap_cmd_dap_swj_clock()

static int cmsis_dap_cmd_dap_swj_clock ( uint32_t  swj_clock)
static

◆ cmsis_dap_cmd_dap_swj_pins()

static int cmsis_dap_cmd_dap_swj_pins ( uint8_t  pins,
uint8_t  mask,
uint32_t  delay,
uint8_t *  input 
)
static

◆ cmsis_dap_cmd_dap_swj_sequence()

static int cmsis_dap_cmd_dap_swj_sequence ( uint8_t  s_len,
const uint8_t *  sequence 
)
static

◆ cmsis_dap_cmd_dap_swo_baudrate()

static int cmsis_dap_cmd_dap_swo_baudrate ( uint32_t  in_baudrate,
uint32_t *  dev_baudrate 
)
static

Sets the baudrate for capturing SWO trace data.

Can be called iteratively to determine supported baudrates.

Parameters
[in]in_baudrateRequested baudrate.
[out]dev_baudrateActual baudrate or 0 (baudrate not configured). When requested baudrate is not achievable the closest configured baudrate can be returned or 0 which indicates that baudrate was not configured.

Definition at line 654 of file cmsis_dap.c.

References CMD_DAP_SWO_BAUDRATE, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, h_u32_to_le(), le_to_h_u32(), LOG_ERROR, and cmsis_dap::response.

Referenced by cmsis_dap_config_trace().

◆ cmsis_dap_cmd_dap_swo_control()

static int cmsis_dap_cmd_dap_swo_control ( uint8_t  control)
static

Controls the SWO trace data capture.

Parameters
[in]controlStart or stop a trace. Starting capture automatically flushes any existing trace data in buffers which has not yet been read.

Definition at line 684 of file cmsis_dap.c.

References CMD_DAP_SWO_CONTROL, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, DAP_OK, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, LOG_ERROR, and cmsis_dap::response.

Referenced by cmsis_dap_config_trace().

◆ cmsis_dap_cmd_dap_swo_data()

static int cmsis_dap_cmd_dap_swo_data ( size_t  max_trace_count,
uint8_t *  trace_status,
size_t *  trace_count,
uint8_t *  data 
)
static

Reads the captured SWO trace data from Trace Buffer.

Parameters
[in]max_trace_countMaximum number of Trace Data bytes to read.
[out]trace_statusThe trace's status.
[out]trace_countNumber of Trace Data bytes read.
[out]dataTrace Data bytes read.

Definition at line 737 of file cmsis_dap.c.

References CMD_DAP_SWO_DATA, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, h_u16_to_le(), le_to_h_u16(), LOG_ERROR, and cmsis_dap::response.

Referenced by cmsis_dap_poll_trace().

◆ cmsis_dap_cmd_dap_swo_mode()

static int cmsis_dap_cmd_dap_swo_mode ( uint8_t  mode)
static

Sets the SWO trace capture mode.

Parameters
[in]modeTrace capture mode. Can be UART or MANCHESTER.

Definition at line 629 of file cmsis_dap.c.

References CMD_DAP_SWO_MODE, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, DAP_OK, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, LOG_ERROR, mode, and cmsis_dap::response.

Referenced by cmsis_dap_config_trace().

◆ cmsis_dap_cmd_dap_swo_status()

static int cmsis_dap_cmd_dap_swo_status ( uint8_t *  trace_status,
size_t *  trace_count 
)
static

Reads the SWO trace status.

Parameters
[out]trace_statusThe trace's status. Bit0: Trace Capture (1 - active, 0 - inactive). Bit6: Trace Stream Error. Bit7: Trace Buffer Overrun.
[out]trace_countNumber of bytes in Trace Buffer (not yet read).

Definition at line 708 of file cmsis_dap.c.

References CMD_DAP_SWO_STATUS, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, le_to_h_u32(), LOG_ERROR, and cmsis_dap::response.

Referenced by cmsis_dap_poll_trace().

◆ cmsis_dap_cmd_dap_swo_transport()

static int cmsis_dap_cmd_dap_swo_transport ( uint8_t  transport)
static

Sets the SWO transport mode.

Parameters
[in]transportThe transport mode. Can be None, SWO_Data or WinUSB (requires CMSIS-DAP v2).

Definition at line 609 of file cmsis_dap.c.

References CMD_DAP_SWO_TRANSPORT, cmsis_dap_handle, cmsis_dap_xfer(), cmsis_dap::command, DAP_OK, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, LOG_ERROR, and cmsis_dap::response.

Referenced by cmsis_dap_config_trace().

◆ cmsis_dap_cmd_dap_tfer_configure()

static int cmsis_dap_cmd_dap_tfer_configure ( uint8_t  idle,
uint16_t  retry_count,
uint16_t  match_retry 
)
static

◆ cmsis_dap_config_trace()

◆ cmsis_dap_end_state()

static void cmsis_dap_end_state ( tap_state_t  state)
static

◆ cmsis_dap_execute_command()

◆ cmsis_dap_execute_pathmove()

static void cmsis_dap_execute_pathmove ( struct jtag_command cmd)
static

Definition at line 1709 of file cmsis_dap.c.

References cmd, cmsis_dap_pathmove(), and LOG_DEBUG_IO.

Referenced by cmsis_dap_execute_command().

◆ cmsis_dap_execute_queue()

static int cmsis_dap_execute_queue ( void  )
static

◆ cmsis_dap_execute_runtest()

static void cmsis_dap_execute_runtest ( struct jtag_command cmd)
static

Definition at line 1745 of file cmsis_dap.c.

References cmd, cmsis_dap_end_state(), cmsis_dap_runtest(), and LOG_DEBUG_IO.

Referenced by cmsis_dap_execute_command().

◆ cmsis_dap_execute_scan()

◆ cmsis_dap_execute_sleep()

static void cmsis_dap_execute_sleep ( struct jtag_command cmd)
static

Definition at line 1337 of file cmsis_dap.c.

References cmd, ERROR_OK, and jtag_sleep().

Referenced by cmsis_dap_execute_command().

◆ cmsis_dap_execute_stableclocks()

static void cmsis_dap_execute_stableclocks ( struct jtag_command cmd)
static

Definition at line 1754 of file cmsis_dap.c.

References cmd, cmsis_dap_stableclocks(), and LOG_DEBUG_IO.

Referenced by cmsis_dap_execute_command().

◆ cmsis_dap_execute_tlr_reset()

static int cmsis_dap_execute_tlr_reset ( struct jtag_command cmd)
static

◆ cmsis_dap_execute_tms()

static void cmsis_dap_execute_tms ( struct jtag_command cmd)
static

Definition at line 1760 of file cmsis_dap.c.

References cmd, cmsis_dap_cmd_dap_swj_sequence(), and LOG_DEBUG_IO.

Referenced by cmsis_dap_execute_command().

◆ cmsis_dap_flush()

◆ cmsis_dap_flush_read()

static void cmsis_dap_flush_read ( struct cmsis_dap dap)
static

◆ cmsis_dap_get_caps_info()

static int cmsis_dap_get_caps_info ( void  )
static

◆ cmsis_dap_get_serial_info()

static int cmsis_dap_get_serial_info ( void  )
static

◆ cmsis_dap_get_status()

static int cmsis_dap_get_status ( void  )
static

◆ cmsis_dap_get_swo_buf_sz()

static int cmsis_dap_get_swo_buf_sz ( uint32_t *  swo_buf_sz)
static

◆ cmsis_dap_get_version_info()

static int cmsis_dap_get_version_info ( void  )
static

◆ cmsis_dap_init()

◆ cmsis_dap_khz()

static int cmsis_dap_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 1830 of file cmsis_dap.c.

References ERROR_OK.

◆ cmsis_dap_metacmd_targetsel()

◆ cmsis_dap_open()

◆ cmsis_dap_pathmove()

static void cmsis_dap_pathmove ( int  num_states,
tap_state_t path 
)
static

◆ cmsis_dap_poll_trace()

◆ cmsis_dap_quit()

static int cmsis_dap_quit ( void  )
static

◆ cmsis_dap_reset()

static int cmsis_dap_reset ( int  trst,
int  srst 
)
static

◆ cmsis_dap_runtest()

static void cmsis_dap_runtest ( int  num_cycles)
static

◆ cmsis_dap_speed()

static int cmsis_dap_speed ( int  speed)
static

◆ cmsis_dap_speed_div()

static int cmsis_dap_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 1824 of file cmsis_dap.c.

References ERROR_OK.

◆ cmsis_dap_stableclocks()

static void cmsis_dap_stableclocks ( int  num_cycles)
static

◆ cmsis_dap_state_move()

static void cmsis_dap_state_move ( void  )
static

◆ cmsis_dap_swd_init()

static int cmsis_dap_swd_init ( void  )
static

Definition at line 1300 of file cmsis_dap.c.

References ERROR_OK, and swd_mode.

◆ cmsis_dap_swd_open()

static int cmsis_dap_swd_open ( void  )
static

◆ cmsis_dap_swd_queue_cmd()

◆ cmsis_dap_swd_read_process()

◆ cmsis_dap_swd_read_reg()

static void cmsis_dap_swd_read_reg ( uint8_t  cmd,
uint32_t *  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 974 of file cmsis_dap.c.

References cmd, cmsis_dap_swd_queue_cmd(), and SWD_CMD_RNW.

◆ cmsis_dap_swd_run_queue()

◆ cmsis_dap_swd_switch_seq()

◆ cmsis_dap_swd_write_from_queue()

◆ cmsis_dap_swd_write_reg()

static void cmsis_dap_swd_write_reg ( uint8_t  cmd,
uint32_t  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 968 of file cmsis_dap.c.

References cmd, cmsis_dap_swd_queue_cmd(), NULL, and SWD_CMD_RNW.

◆ cmsis_dap_xfer()

◆ COMMAND_HANDLER() [1/4]

COMMAND_HANDLER ( cmsis_dap_handle_backend_command  )

Definition at line 2046 of file cmsis_dap.c.

◆ COMMAND_HANDLER() [2/4]

COMMAND_HANDLER ( cmsis_dap_handle_cmd_command  )

◆ COMMAND_HANDLER() [3/4]

COMMAND_HANDLER ( cmsis_dap_handle_info_command  )

Definition at line 1987 of file cmsis_dap.c.

References cmsis_dap_get_status(), cmsis_dap_get_version_info(), and ERROR_OK.

◆ COMMAND_HANDLER() [4/4]

COMMAND_HANDLER ( cmsis_dap_handle_vid_pid_command  )

Variable Documentation

◆ cmsis_dap_adapter_driver

struct adapter_driver cmsis_dap_adapter_driver
Initial value:
= {
.name = "cmsis-dap",
.transports = cmsis_dap_transport,
.init = cmsis_dap_init,
.quit = cmsis_dap_quit,
.reset = cmsis_dap_reset,
.speed = cmsis_dap_speed,
.khz = cmsis_dap_khz,
.speed_div = cmsis_dap_speed_div,
.config_trace = cmsis_dap_config_trace,
.poll_trace = cmsis_dap_poll_trace,
.jtag_ops = &cmsis_dap_interface,
.swd_ops = &cmsis_dap_swd_driver,
}
static int cmsis_dap_init(void)
Definition: cmsis_dap.c:1160
static int cmsis_dap_reset(int trst, int srst)
Definition: cmsis_dap.c:1319
static struct jtag_interface cmsis_dap_interface
Definition: cmsis_dap.c:2131
static int cmsis_dap_speed_div(int speed, int *khz)
Definition: cmsis_dap.c:1824
static int cmsis_dap_quit(void)
Definition: cmsis_dap.c:1306
static const struct swd_driver cmsis_dap_swd_driver
Definition: cmsis_dap.c:2121
static const char *const cmsis_dap_transport[]
Definition: cmsis_dap.c:2129
static int cmsis_dap_khz(int khz, int *jtag_speed)
Definition: cmsis_dap.c:1830
static int cmsis_dap_poll_trace(uint8_t *buf, size_t *size)
Definition: cmsis_dap.c:1947
static int cmsis_dap_speed(int speed)
Definition: cmsis_dap.c:1814
static const struct command_registration cmsis_dap_command_handlers[]
Definition: cmsis_dap.c:2087
static int cmsis_dap_config_trace(bool trace_enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *swo_freq, unsigned int traceclkin_hz, uint16_t *swo_prescaler)
Definition: cmsis_dap.c:1857

Definition at line 2129 of file cmsis_dap.c.

◆ cmsis_dap_backend

int cmsis_dap_backend = -1
static

Definition at line 69 of file cmsis_dap.c.

Referenced by cmsis_dap_open().

◆ cmsis_dap_backends

const struct cmsis_dap_backend* const cmsis_dap_backends[]
static
Initial value:
= {
}

Definition at line 42 of file cmsis_dap.c.

Referenced by cmsis_dap_open().

◆ cmsis_dap_command_handlers

const struct command_registration cmsis_dap_command_handlers[]
static

Definition at line 2046 of file cmsis_dap.c.

◆ cmsis_dap_handle

◆ cmsis_dap_interface

struct jtag_interface cmsis_dap_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = cmsis_dap_execute_queue,
}
static int cmsis_dap_execute_queue(void)
Definition: cmsis_dap.c:1800
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189

Definition at line 2129 of file cmsis_dap.c.

◆ cmsis_dap_pid

uint16_t cmsis_dap_pid[MAX_USB_IDS+1] = { 0 }
static

Definition at line 68 of file cmsis_dap.c.

Referenced by cmsis_dap_open(), and COMMAND_HANDLER().

◆ cmsis_dap_subcommand_handlers

const struct command_registration cmsis_dap_subcommand_handlers[]
static
Initial value:
= {
{
.name = "info",
.handler = &cmsis_dap_handle_info_command,
.mode = COMMAND_EXEC,
.usage = "",
.help = "show cmsis-dap info",
},
{
.name = "cmd",
.handler = &cmsis_dap_handle_cmd_command,
.mode = COMMAND_EXEC,
.usage = "",
.help = "issue cmsis-dap command",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 2046 of file cmsis_dap.c.

◆ cmsis_dap_swd_driver

const struct swd_driver cmsis_dap_swd_driver
static
Initial value:
= {
.switch_seq = cmsis_dap_swd_switch_seq,
}
static int cmsis_dap_swd_switch_seq(enum swd_special_seq seq)
Definition: cmsis_dap.c:1072
static void cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: cmsis_dap.c:968
static int cmsis_dap_swd_run_queue(void)
Definition: cmsis_dap.c:914
static int cmsis_dap_swd_init(void)
Definition: cmsis_dap.c:1300
static void cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: cmsis_dap.c:974

Definition at line 2046 of file cmsis_dap.c.

◆ cmsis_dap_transport

const char* const cmsis_dap_transport[] = { "swd", "jtag", NULL }
static

Definition at line 2129 of file cmsis_dap.c.

◆ cmsis_dap_vid

uint16_t cmsis_dap_vid[MAX_USB_IDS+1] = { 0 }
static

Definition at line 67 of file cmsis_dap.c.

Referenced by cmsis_dap_open(), and COMMAND_HANDLER().

◆ info_caps_str

const char* const info_caps_str[INFO_CAPS__NUM_CAPS]
static
Initial value:
= {
"SWD supported",
"JTAG supported",
"SWO-UART supported",
"SWO-MANCHESTER supported",
"Atomic commands supported",
"Test domain timer supported",
"SWO streaming trace supported",
"UART communication port supported",
"UART via USB COM port supported",
}

Definition at line 200 of file cmsis_dap.c.

Referenced by cmsis_dap_get_caps_info().

◆ output_pins

uint8_t output_pins = SWJ_PIN_SRST | SWJ_PIN_TRST
static

Definition at line 259 of file cmsis_dap.c.

Referenced by cmsis_dap_reset(), and cmsis_dap_swd_switch_seq().

◆ pending_fifo

◆ pending_fifo_block_count

int pending_fifo_block_count
static

◆ pending_fifo_get_idx

int pending_fifo_get_idx
static

◆ pending_fifo_put_idx

int pending_fifo_put_idx
static

◆ pending_queue_len

int pending_queue_len
static

Definition at line 240 of file cmsis_dap.c.

Referenced by cmsis_dap_init(), and cmsis_dap_swd_queue_cmd().

◆ pending_scan_result_count

int pending_scan_result_count
static

Definition at line 247 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ pending_scan_results

struct pending_scan_result pending_scan_results[MAX_PENDING_SCAN_RESULTS]
static

Definition at line 247 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ queued_retval

◆ queued_seq_buf

uint8_t queued_seq_buf[1024]
static

Definition at line 255 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ queued_seq_buf_end

int queued_seq_buf_end
static

Definition at line 253 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ queued_seq_count

int queued_seq_count
static

Definition at line 252 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ queued_seq_tdo_ptr

int queued_seq_tdo_ptr
static

Definition at line 254 of file cmsis_dap.c.

Referenced by cmsis_dap_add_jtag_sequence(), and cmsis_dap_flush().

◆ swd_mode

bool swd_mode
static

Definition at line 70 of file cmsis_dap.c.

Referenced by cmsis_dap_init(), and cmsis_dap_swd_init().