43 #if BUILD_CMSIS_DAP_USB == 1
47 #if BUILD_CMSIS_DAP_HID == 1
73 #define CMD_DAP_INFO 0x00
74 #define CMD_DAP_LED 0x01
75 #define CMD_DAP_CONNECT 0x02
76 #define CMD_DAP_DISCONNECT 0x03
77 #define CMD_DAP_WRITE_ABORT 0x08
78 #define CMD_DAP_DELAY 0x09
79 #define CMD_DAP_RESET_TARGET 0x0A
82 #define INFO_ID_VENDOR 0x01
83 #define INFO_ID_PRODUCT 0x02
84 #define INFO_ID_SERNUM 0x03
85 #define INFO_ID_FW_VER 0x04
86 #define INFO_ID_TD_VEND 0x05
87 #define INFO_ID_TD_NAME 0x06
88 #define INFO_ID_CAPS 0xf0
89 #define INFO_ID_PKT_CNT 0xfe
90 #define INFO_ID_PKT_SZ 0xff
91 #define INFO_ID_SWO_BUF_SZ 0xfd
93 #define INFO_CAPS_SWD BIT(0)
94 #define INFO_CAPS_JTAG BIT(1)
95 #define INFO_CAPS_SWO_UART BIT(2)
96 #define INFO_CAPS_SWO_MANCHESTER BIT(3)
97 #define INFO_CAPS_ATOMIC_CMDS BIT(4)
98 #define INFO_CAPS_TEST_DOMAIN_TIMER BIT(5)
99 #define INFO_CAPS_SWO_STREAMING_TRACE BIT(6)
100 #define INFO_CAPS_UART_PORT BIT(7)
101 #define INFO_CAPS_USB_COM_PORT BIT(8)
102 #define INFO_CAPS__NUM_CAPS 9
105 #define LED_ID_CONNECT 0x00
106 #define LED_ID_RUN 0x01
112 #define CONNECT_DEFAULT 0x00
113 #define CONNECT_SWD 0x01
114 #define CONNECT_JTAG 0x02
117 #define CMD_DAP_DELAY 0x09
118 #define CMD_DAP_SWJ_PINS 0x10
119 #define CMD_DAP_SWJ_CLOCK 0x11
120 #define CMD_DAP_SWJ_SEQ 0x12
132 #define SWJ_PIN_TCK (1<<0)
133 #define SWJ_PIN_TMS (1<<1)
134 #define SWJ_PIN_TDI (1<<2)
135 #define SWJ_PIN_TDO (1<<3)
136 #define SWJ_PIN_TRST (1<<5)
137 #define SWJ_PIN_SRST (1<<7)
140 #define CMD_DAP_SWD_CONFIGURE 0x13
141 #define CMD_DAP_SWD_SEQUENCE 0x1D
144 #define CMD_DAP_JTAG_SEQ 0x14
145 #define CMD_DAP_JTAG_CONFIGURE 0x15
146 #define CMD_DAP_JTAG_IDCODE 0x16
150 #define DAP_JTAG_SEQ_TCK 0x3F
152 #define DAP_JTAG_SEQ_TMS 0x40
154 #define DAP_JTAG_SEQ_TDO 0x80
158 #define CMD_DAP_TFER_CONFIGURE 0x04
159 #define CMD_DAP_TFER 0x05
160 #define CMD_DAP_TFER_BLOCK 0x06
161 #define CMD_DAP_TFER_ABORT 0x07
166 #define CMD_DAP_TFER_BLOCK_MIN_OPS 4
170 #define DAP_ERROR 0xFF
173 #define CMD_DAP_SWO_TRANSPORT 0x17
174 #define CMD_DAP_SWO_MODE 0x18
175 #define CMD_DAP_SWO_BAUDRATE 0x19
176 #define CMD_DAP_SWO_CONTROL 0x1A
177 #define CMD_DAP_SWO_STATUS 0x1B
178 #define CMD_DAP_SWO_DATA 0x1C
179 #define CMD_DAP_SWO_EX_STATUS 0x1E
182 #define DAP_SWO_TRANSPORT_NONE 0
183 #define DAP_SWO_TRANSPORT_DATA 1
184 #define DAP_SWO_TRANSPORT_WINUSB 2
187 #define DAP_SWO_MODE_OFF 0
188 #define DAP_SWO_MODE_UART 1
189 #define DAP_SWO_MODE_MANCHESTER 2
192 #define DAP_SWO_CONTROL_STOP 0
193 #define DAP_SWO_CONTROL_START 1
196 #define DAP_SWO_STATUS_CAPTURE_INACTIVE 0
197 #define DAP_SWO_STATUS_CAPTURE_ACTIVE 1
198 #define DAP_SWO_STATUS_CAPTURE_MASK BIT(0)
199 #define DAP_SWO_STATUS_STREAM_ERROR_MASK BIT(6)
200 #define DAP_SWO_STATUS_BUFFER_OVERRUN_MASK BIT(7)
208 "SWO-UART supported",
209 "SWO-MANCHESTER supported",
210 "Atomic commands supported",
211 "Test domain timer supported",
212 "SWO streaming trace supported",
213 "UART communication port supported",
214 "UART via USB COM port supported",
234 #define MAX_PENDING_SCAN_RESULTS 256
239 #define QUEUED_SEQ_BUF_LEN (cmsis_dap_handle->packet_usable_size - 3)
281 LOG_ERROR(
"unable to find a matching CMSIS-DAP device");
317 for (i = 0; i < 64; i++) {
330 LOG_ERROR(
"internal: queue not empty before xfer");
342 uint8_t current_cmd = dap->
command[0];
354 LOG_ERROR(
"CMSIS-DAP command 0x%" PRIx8
" not implemented", current_cmd);
358 if (resp[0] != current_cmd) {
359 LOG_ERROR(
"CMSIS-DAP command mismatch. Sent 0x%" PRIx8
360 " received 0x%" PRIx8, current_cmd, resp[0]);
381 LOG_ERROR(
"CMSIS-DAP command CMD_DAP_SWJ_PINS failed.");
403 LOG_ERROR(
"CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.");
415 #ifdef CMSIS_DAP_JTAG_DEBUG
416 LOG_DEBUG(
"cmsis-dap TMS sequence: len=%d", s_len);
417 for (
unsigned int i = 0; i <
DIV_ROUND_UP(s_len, 8); ++i)
443 LOG_ERROR(
"CMSIS-DAP command CMD_INFO failed.");
462 LOG_ERROR(
"CMSIS-DAP command CMD_LED failed.");
478 LOG_ERROR(
"CMSIS-DAP command CMD_CONNECT failed.");
498 LOG_ERROR(
"CMSIS-DAP command CMD_DISCONNECT failed.");
516 LOG_ERROR(
"CMSIS-DAP command CMD_TFER_Configure failed.");
532 LOG_ERROR(
"CMSIS-DAP command CMD_SWD_Configure failed.");
540 static int cmsis_dap_cmd_dap_delay(uint16_t
delay_us)
549 LOG_ERROR(
"CMSIS-DAP command CMD_Delay failed.");
560 const uint32_t seq_rd = 0x80, seq_wr = 0x00;
569 LOG_DEBUG_IO(
"DP write reg TARGETSEL %" PRIx32, instance_id);
583 command[idx++] = seq_wr | (32 + 1);
590 LOG_ERROR(
"CMSIS-DAP command SWD_Sequence failed.");
631 LOG_ERROR(
"CMSIS-DAP: command CMD_SWO_Mode(%d) failed.",
mode);
648 uint32_t in_baudrate,
649 uint32_t *dev_baudrate)
658 if (retval !=
ERROR_OK || rvbr == 0) {
659 LOG_ERROR(
"CMSIS-DAP: command CMD_SWO_Baudrate(%u) -> %u failed.", in_baudrate, rvbr);
666 *dev_baudrate = rvbr;
686 LOG_ERROR(
"CMSIS-DAP: command CMD_SWO_Control(%d) failed.", control);
711 LOG_ERROR(
"CMSIS-DAP: command CMD_SWO_Status failed.");
731 size_t max_trace_count,
743 LOG_ERROR(
"CMSIS-DAP: command CMD_SWO_Data failed.");
750 if (*trace_count > 0)
784 LOG_DEBUG_IO(
"Executing %d queued transactions from FIFO index %u%s",
794 LOG_ERROR(
"internal: write an empty queue?!");
816 uint8_t
cmd = transfer->
cmd;
839 LOG_DEBUG(
"refusing to enable sticky overrun detection");
843 if (!block_cmd || i == 0)
876 LOG_ERROR(
"internal: no pending write when reading?!");
899 LOG_DEBUG(
"error reading adapter response");
911 if (resp[0] != block->
command) {
912 LOG_ERROR(
"CMSIS-DAP command mismatch. Expected 0x%x received 0x%" PRIx8,
928 if (resp[idx] & 0x08) {
933 uint8_t ack = resp[idx++] & 0x07;
943 LOG_ERROR(
"CMSIS-DAP transfer count mismatch: expected %d, got %d",
950 LOG_DEBUG_IO(
"Received results of %d queued transactions FIFO index %u, %s mode",
952 blocking ?
"blocking" :
"nonblocking");
957 static uint32_t last_read;
972 *(uint32_t *)(transfer->
buffer) = tmp;
1005 unsigned int read_count,
bool block_tfer)
1010 size += write_count * 4;
1013 size += write_count * (1 + 4);
1020 unsigned int read_count,
bool block_tfer)
1028 size += read_count * 4;
1062 unsigned int max_transfer_count = block_cmd ? 65535 : 255;
1067 || write_count + read_count > max_transfer_count) {
1155 if (
data[0] == 1 ||
data[0] == 2) {
1185 LOG_INFO(
"CMSIS-DAP: SWO Trace Buffer Size = %u bytes", *swo_buf_sz);
1197 LOG_INFO(
"SWCLK/TCK = %d SWDIO/TMS = %d TDI = %d TDO = %d nTRST = %d nRESET = %d",
1272 LOG_ERROR(
"Sequence %d not supported", seq);
1288 LOG_ERROR(
"CMSIS-DAP: SWD not supported");
1298 LOG_INFO(
"CMSIS-DAP: Interface Initialised (SWD)");
1331 LOG_ERROR(
"CMSIS-DAP: JTAG not supported");
1339 LOG_INFO(
"CMSIS-DAP: Interface Initialised (JTAG)");
1352 uint16_t pkt_sz =
data[1] + (
data[2] << 8);
1359 LOG_DEBUG(
"CMSIS-DAP: Packet Size = %" PRIu16, pkt_sz);
1379 unsigned int pkt_cnt =
data[1];
1383 LOG_DEBUG(
"CMSIS-DAP: Packet Count = %u", pkt_cnt);
1391 LOG_ERROR(
"Unable to allocate memory for CMSIS-DAP queue");
1435 LOG_INFO(
"Connecting under reset");
1438 LOG_INFO(
"CMSIS-DAP: Interface ready");
1479 LOG_ERROR(
"CMSIS-DAP: Interface reset failed");
1486 int retval = cmsis_dap_cmd_dap_delay(
cmd->cmd.sleep->us);
1495 LOG_INFO(
"cmsis-dap JTAG TLR_RESET");
1515 #ifdef SPRINT_BINARY
1516 static void sprint_binary(
char *s,
const uint8_t *buf,
unsigned int offset,
unsigned int len)
1528 uint8_t c = buf[i / 8],
mask = 1 << (i % 8);
1529 if ((i !=
offset) && !(i % 8))
1531 *s++ = (c &
mask) ?
'1' :
'0';
1537 #ifdef CMSIS_DAP_JTAG_DEBUG
1538 static void debug_parse_cmsis_buf(
const uint8_t *
cmd,
int cmdlen)
1541 printf(
"cmsis-dap buffer (%d b): ", cmdlen);
1542 for (
int i = 0; i < cmdlen; ++i)
1543 printf(
" %02x",
cmd[i]);
1547 printf(
"cmsis-dap jtag sequence command %02x (n=%d)\n",
cmd[0],
cmd[1]);
1556 for (
int seq = 0; seq <
cmd[1]; ++seq) {
1561 printf(
" sequence %d starting %d: info %02x (len=%d tms=%d read_tdo=%d): ",
1564 printf(
" %02x",
cmd[pos+i]);
1568 if (pos != cmdlen) {
1569 printf(
"BUFFER LENGTH MISMATCH looks like %d but %d specified", pos, cmdlen);
1587 LOG_DEBUG_IO(
"Flushing %d queued sequences (%d bytes) with %d pending scan results to capture",
1596 #ifdef CMSIS_DAP_JTAG_DEBUG
1605 LOG_ERROR(
"CMSIS-DAP command CMD_DAP_JTAG_SEQ failed.");
1609 #ifdef CMSIS_DAP_JTAG_DEBUG
1612 printf(
"%02X ", resp[c]);
1619 LOG_DEBUG_IO(
"Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits",
1621 #ifdef CMSIS_DAP_JTAG_DEBUG
1623 printf(
"%02X ", resp[2+
scan->first+b]);
1642 unsigned int s_offset,
bool tms,
1643 uint8_t *
tdo_buffer,
unsigned int tdo_buffer_offset)
1645 LOG_DEBUG_IO(
"[at %d] %u bits, tms %s, seq offset %u, tdo buf %p, tdo offset %u",
1647 s_len, tms ?
"HIGH" :
"LOW", s_offset,
tdo_buffer, tdo_buffer_offset);
1655 unsigned int len = s_len -
offset;
1658 LOG_DEBUG_IO(
"Splitting long jtag sequence: %u-bit chunk starting at offset %u", len,
offset);
1683 (s_len == 64 ? 0 : s_len);
1696 scan->length = s_len;
1698 scan->buffer_offset = tdo_buffer_offset;
1711 for (
int i = 0; i < s_len; ++i) {
1712 bool bit = (
sequence[i / 8] & (1 << (i % 8))) != 0;
1723 LOG_DEBUG_IO(
"state move from %s to %s: %d clocks, %02X on tms",
1725 tms_scan_bits, tms_scan);
1735 LOG_DEBUG_IO(
"%s type:%d",
cmd->cmd.scan->ir_scan ?
"IRSCAN" :
"DRSCAN",
1739 while (
cmd->cmd.scan->num_fields > 0
1740 &&
cmd->cmd.scan->fields[
cmd->cmd.scan->num_fields - 1].num_bits == 0) {
1741 cmd->cmd.scan->num_fields--;
1742 LOG_DEBUG(
"discarding trailing empty field");
1745 if (!
cmd->cmd.scan->num_fields) {
1750 if (
cmd->cmd.scan->ir_scan) {
1765 unsigned int scan_size = 0;
1767 for (
unsigned int i = 0; i <
cmd->cmd.scan->num_fields; i++, field++) {
1773 cmd->cmd.scan->num_fields,
1777 LOG_DEBUG_IO(
"Last field and have to move out of SHIFT state");
1789 uint8_t last_bit = 0;
1811 LOG_DEBUG_IO(
"Internal field, staying in SHIFT state afterwards");
1830 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR", scan_size,
1836 uint8_t tms0 = 0x00;
1837 uint8_t tms1 = 0xff;
1839 for (
int i = 0; i < num_states; i++) {
1845 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition.",
1859 cmd->cmd.pathmove->num_states,
1860 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
1870 for (
unsigned int i = 0; i < num_cycles; i++)
1894 LOG_DEBUG_IO(
"runtest %u cycles, end in %i",
cmd->cmd.runtest->num_cycles,
1895 cmd->cmd.runtest->end_state);
1917 switch (
cmd->type) {
1942 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X encountered",
cmd->type);
1964 LOG_ERROR(
"RTCK not supported. Set nonzero \"adapter speed\".");
1984 uint32_t trace_freq, uint16_t *prescaler)
1986 unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1991 unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1992 if (presc * trace_freq < traceclkin_freq - max_deviation ||
1993 presc * trace_freq > traceclkin_freq + max_deviation)
2008 unsigned int *swo_freq,
2009 unsigned int traceclkin_hz,
2010 uint16_t *swo_prescaler)
2018 LOG_ERROR(
"Failed to disable the SWO-trace.");
2029 LOG_ERROR(
"SWO-trace is not supported by the device.");
2041 LOG_ERROR(
"Selected pin protocol is not supported.");
2045 if (*swo_freq == 0) {
2046 LOG_INFO(
"SWO-trace frequency autodetection not implemented.");
2074 LOG_ERROR(
"SWO frequency is not suitable. Please choose a "
2075 "different frequency or use auto-detection.");
2079 LOG_INFO(
"SWO frequency: %u Hz.", *swo_freq);
2080 LOG_INFO(
"SWO prescaler: %u.", *swo_prescaler);
2111 size_t read_so_far = 0;
2115 uint32_t remaining = *
size - read_so_far;
2116 if (remaining < packet_size)
2117 packet_size = remaining;
2129 }
while (read_so_far < *
size);
2146 for (
unsigned int i = 0; i <
CMD_ARGC; i++)
2157 LOG_INFO(
"Returned data %02" PRIx8
" %02" PRIx8
" %02" PRIx8
" %02" PRIx8,
2158 resp[1], resp[2], resp[3], resp[4]);
2166 LOG_WARNING(
"ignoring extra IDs in cmsis-dap vid_pid "
2171 LOG_WARNING(
"incomplete cmsis-dap vid_pid configuration directive");
2179 for (i = 0; i <
CMD_ARGC; i += 2) {
2196 if (strcmp(
CMD_ARGV[0],
"auto") == 0) {
2206 command_print(
CMD,
"invalid backend argument to cmsis-dap backend <backend>");
2232 .handler = &cmsis_dap_handle_info_command,
2235 .help =
"show cmsis-dap info",
2239 .handler = &cmsis_dap_handle_cmd_command,
2242 .help =
"issue cmsis-dap command",
2246 .handler = &cmsis_dap_handle_vid_pid_command,
2248 .help =
"the vendor ID and product ID of the CMSIS-DAP device",
2249 .usage =
"(vid pid)*",
2253 .handler = &cmsis_dap_handle_backend_command,
2255 .help =
"set the communication backend to use (USB bulk or HID).",
2256 .usage =
"(auto | usb_bulk | hid)",
2260 .handler = &cmsis_dap_handle_quirk_command,
2262 .help =
"allow expensive workarounds of known adapter quirks.",
2263 .usage =
"[enable | disable]",
2265 #if BUILD_CMSIS_DAP_USB
2270 .help =
"USB bulk backend-specific commands",
2280 .
name =
"cmsis-dap",
2282 .help =
"perform CMSIS-DAP management",
2305 .
name =
"cmsis-dap",
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
@ TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER
asynchronous output with Manchester coding
@ TPIU_PIN_PROTOCOL_ASYNC_UART
asynchronous output with NRZ coding
static void bit_copy(uint8_t *dst, unsigned int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int bit_count)
static int cmsis_dap_init(void)
static int cmsis_dap_cmd_dap_swo_status(uint8_t *trace_status, size_t *trace_count)
Reads the SWO trace status.
static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, enum cmsis_dap_blocking blocking)
static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
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.
#define DAP_SWO_MODE_MANCHESTER
#define MAX_PENDING_SCAN_RESULTS
static int cmsis_dap_get_status(void)
static int cmsis_dap_reset(int trst, int srst)
static int cmsis_dap_get_caps_info(void)
static void cmsis_dap_stableclocks(unsigned int num_cycles)
#define INFO_CAPS__NUM_CAPS
static int cmsis_dap_swd_switch_seq(enum swd_special_seq seq)
static uint16_t cmsis_dap_vid[MAX_USB_IDS+1]
static void cmsis_dap_execute_runtest(struct jtag_command *cmd)
static struct jtag_interface cmsis_dap_interface
static int cmsis_dap_swd_open(void)
#define DAP_SWO_STATUS_CAPTURE_MASK
static int cmsis_dap_cmd_dap_swo_control(uint8_t control)
Controls the SWO trace data capture.
static struct cmsis_dap * cmsis_dap_handle
static int cmsis_dap_cmd_dap_info(uint8_t info, uint8_t **data)
static struct pending_scan_result pending_scan_results[MAX_PENDING_SCAN_RESULTS]
static int cmsis_dap_cmd_dap_swj_pins(uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input)
static unsigned int cmsis_dap_tfer_cmd_size(unsigned int write_count, unsigned int read_count, bool block_tfer)
static int cmsis_dap_cmd_dap_swo_baudrate(uint32_t in_baudrate, uint32_t *dev_baudrate)
Sets the baudrate for capturing SWO trace data.
static unsigned int tfer_max_response_size
static int cmsis_dap_speed_div(int speed, int *khz)
#define CMD_DAP_SWJ_CLOCK
static int cmsis_dap_cmd_dap_swd_configure(uint8_t cfg)
static bool calculate_swo_prescaler(unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler)
#define INFO_ID_SWO_BUF_SZ
static int queued_seq_buf_end
#define DAP_SWO_STATUS_CAPTURE_ACTIVE
static int queued_seq_count
static void cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
struct adapter_driver cmsis_dap_adapter_driver
static int cmsis_dap_cmd_dap_swj_clock(uint32_t swj_clock)
static void cmsis_dap_swd_discard_all_pending(struct cmsis_dap *dap)
static void cmsis_dap_flush(void)
static int cmsis_dap_execute_queue(struct jtag_command *cmd_queue)
#define CMD_DAP_TFER_CONFIGURE
#define INFO_CAPS_SWO_UART
#define CMD_DAP_SWO_STATUS
#define CMD_DAP_SWD_CONFIGURE
static int cmsis_dap_quit(void)
static const struct swd_driver cmsis_dap_swd_driver
#define DAP_SWO_TRANSPORT_DATA
#define CMD_DAP_DISCONNECT
static void cmsis_dap_swd_cancel_transfers(struct cmsis_dap *dap)
static int cmsis_dap_cmd_dap_disconnect(void)
static const char *const cmsis_dap_transport[]
static int cmsis_dap_cmd_dap_tfer_configure(uint8_t idle, uint16_t retry_count, uint16_t match_retry)
static void cmsis_dap_execute_stableclocks(struct jtag_command *cmd)
static uint8_t queued_seq_buf[1024]
static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
static int cmsis_dap_get_serial_info(void)
static void cmsis_dap_flush_read(struct cmsis_dap *dap)
static int pending_scan_result_count
#define CMD_DAP_TFER_BLOCK
static void cmsis_dap_execute_scan(struct jtag_command *cmd)
static void cmsis_dap_execute_command(struct jtag_command *cmd)
#define CMD_DAP_SWO_CONTROL
static void cmsis_dap_end_state(tap_state_t state)
static int cmsis_dap_swd_run_queue(void)
static int cmsis_dap_cmd_dap_connect(uint8_t mode)
static unsigned int tfer_max_command_size
#define CMD_DAP_SWO_TRANSPORT
static void cmsis_dap_runtest(unsigned int num_cycles)
#define CMD_DAP_TFER_BLOCK_MIN_OPS
static void cmsis_dap_execute_tms(struct jtag_command *cmd)
static unsigned int pending_queue_len
static const struct cmsis_dap_backend *const cmsis_dap_backends[]
#define INFO_CAPS_SWO_MANCHESTER
static int queued_seq_tdo_ptr
static const char *const info_caps_str[INFO_CAPS__NUM_CAPS]
static const struct command_registration cmsis_dap_subcommand_handlers[]
static void cmsis_dap_state_move(void)
static int cmsis_dap_cmd_dap_swo_mode(uint8_t mode)
Sets the SWO trace capture mode.
static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
static uint8_t output_pins
#define CMD_DAP_SWD_SEQUENCE
static int cmsis_dap_cmd_dap_swj_sequence(uint8_t s_len, const uint8_t *sequence)
static int cmsis_dap_khz(int khz, int *jtag_speed)
static int cmsis_dap_metacmd_targetsel(uint32_t instance_id)
static int cmsis_dap_backend
static void cmsis_dap_close(struct cmsis_dap *dap)
static int cmsis_dap_poll_trace(uint8_t *buf, size_t *size)
#define CMD_DAP_SWO_BAUDRATE
static int cmsis_dap_swd_init(void)
static void cmsis_dap_execute_sleep(struct jtag_command *cmd)
static int cmsis_dap_open(void)
COMMAND_HANDLER(cmsis_dap_handle_info_command)
static int cmsis_dap_speed(int speed)
#define QUEUED_SEQ_BUF_LEN
static void cmsis_dap_pathmove(int num_states, tap_state_t *path)
static int cmsis_dap_cmd_dap_led(uint8_t led, uint8_t state)
static unsigned int cmsis_dap_tfer_resp_size(unsigned int write_count, unsigned int read_count, bool block_tfer)
static int cmsis_dap_cmd_dap_swo_transport(uint8_t transport)
Sets the SWO transport mode.
#define DAP_SWO_CONTROL_STOP
static void cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static void cmsis_dap_execute_pathmove(struct jtag_command *cmd)
static const struct command_registration cmsis_dap_command_handlers[]
#define DAP_SWO_CONTROL_START
static int cmsis_dap_execute_tlr_reset(struct jtag_command *cmd)
static int cmsis_dap_get_swo_buf_sz(uint32_t *swo_buf_sz)
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)
#define DAP_SWO_MODE_UART
static void cmsis_dap_add_jtag_sequence(unsigned int s_len, const uint8_t *sequence, unsigned int s_offset, bool tms, uint8_t *tdo_buffer, unsigned int tdo_buffer_offset)
static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len)
static uint16_t cmsis_dap_pid[MAX_USB_IDS+1]
static int cmsis_dap_get_version_info(void)
#define MAX_PENDING_REQUESTS
const struct cmsis_dap_backend cmsis_dap_usb_backend
const struct command_registration cmsis_dap_usb_subcommand_handlers[]
const struct cmsis_dap_backend cmsis_dap_hid_backend
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
enum scan_type jtag_scan_type(const struct scan_command *cmd)
#define TPIU_ACPR_MAX_SWOSCALER
void delay_us(uint16_t delay)
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#define DEBUG_CAP_TMS_SEQ
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]
static bool trace_enabled
static enum reset_types jtag_reset_config
void jtag_sleep(uint32_t us)
enum reset_types jtag_get_reset_config(void)
#define ERROR_JTAG_DEVICE_ERROR
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define ERROR_JTAG_NOT_IMPLEMENTED
static struct scan_blk scan
#define LIBUSB_TIMEOUT_MS
#define ERROR_NOT_IMPLEMENTED
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define ERROR_TIMEOUT_REACHED
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t bit(uint32_t value, unsigned int b)
size_t size
Size of the control block search area.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
int(* read)(struct cmsis_dap *dap, int transfer_timeout_ms, enum cmsis_dap_blocking blocking)
void(* cancel_all)(struct cmsis_dap *dap)
int(* packet_buffer_alloc)(struct cmsis_dap *dap, unsigned int pkt_sz)
void(* close)(struct cmsis_dap *dap)
void(* packet_buffer_free)(struct cmsis_dap *dap)
int(* open)(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial)
int(* write)(struct cmsis_dap *dap, int len, int timeout_ms)
unsigned int packet_usable_size
struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS]
unsigned int pending_fifo_put_idx
unsigned int pending_fifo_block_count
unsigned int packet_count
const struct cmsis_dap_backend * backend
unsigned int pending_fifo_get_idx
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
struct pending_transfer_result * transfers
unsigned int transfer_count
unsigned int buffer_offset
Offset in the destination buffer.
unsigned int first
Offset in bytes in the CMD_DAP_JTAG_SEQ response buffer.
unsigned int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Wrapper for transport lifecycle operations.
static const unsigned int swd_seq_dormant_to_swd_len
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
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....
static const unsigned int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const unsigned int swd_seq_dormant_to_jtag_len
static const unsigned int swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const unsigned int swd_seq_swd_to_jtag_len
static const unsigned int swd_seq_jtag_to_dormant_len
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
static uint16_t le_to_h_u16(const uint8_t *buf)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static void h_u16_to_le(uint8_t *buf, uint16_t val)
static uint32_t le_to_h_u32(const uint8_t *buf)
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static struct ublast_lowlevel_priv info