1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2007 by Juergen Stuber <juergen@jstuber.net> *
5 * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
7 * Copyright (C) 2008 by Spencer Oliver *
8 * spen@spen-soft.co.uk *
10 * Copyright (C) 2011 by Jean-Christophe PLAGNIOL-VIILARD *
11 * plagnioj@jcrosoft.com *
13 * Copyright (C) 2015 by Marc Schink *
14 * openocd-dev@marcschink.de *
16 * Copyright (C) 2015 by Paul Fertser *
17 * fercerpav@gmail.com *
19 * Copyright (C) 2015-2017 by Forest Crossman *
21 ***************************************************************************/
31 #include <jtag/interface.h>
33 #include <jtag/commands.h>
35 #include "libusb_helper.h"
43 #define CONTROL_TYPE_READ 0x01
44 #define CONTROL_TYPE_WRITE 0x02
46 #define CONTROL_COMMAND_PROGRAM 0x07
48 #define CONTROL_MODE_POLL_PROGRAMMER_STATUS 0x01
49 #define CONTROL_MODE_RESET_TARGET 0x04
50 #define CONTROL_MODE_SET_PROGRAMMER_PROTOCOL 0x40
51 #define CONTROL_MODE_SYNCHRONIZE_TRANSFER 0x41
52 #define CONTROL_MODE_ACQUIRE_SWD_TARGET 0x42
53 #define CONTROL_MODE_SEND_SWD_SEQUENCE 0x43
55 #define PROTOCOL_JTAG 0x00
56 #define PROTOCOL_SWD 0x01
58 #define DEVICE_PSOC4 0x00
59 #define DEVICE_PSOC3 0x01
60 #define DEVICE_UNKNOWN 0x02
61 #define DEVICE_PSOC5 0x03
63 #define ACQUIRE_MODE_RESET 0x00
64 #define ACQUIRE_MODE_POWER_CYCLE 0x01
66 #define SEQUENCE_LINE_RESET 0x00
67 #define SEQUENCE_JTAG_TO_SWD 0x01
69 #define PROGRAMMER_NOK_NACK 0x00
70 #define PROGRAMMER_OK_ACK 0x01
72 #define HID_TYPE_WRITE 0x00
73 #define HID_TYPE_READ 0x01
74 #define HID_TYPE_START 0x02
76 #define HID_COMMAND_POWER 0x80
77 #define HID_COMMAND_VERSION 0x81
78 #define HID_COMMAND_RESET 0x82
79 #define HID_COMMAND_CONFIGURE 0x8f
80 #define HID_COMMAND_BOOTLOADER 0xa0
82 /* 512 bytes seems to work reliably */
83 #define SWD_MAX_BUFFER_LENGTH 512
86 hid_device *hid_handle;
87 struct libusb_device_handle *usb_handle;
89 uint16_t packet_index;
90 uint8_t *packet_buffer;
92 uint8_t hardware_version;
93 uint8_t minor_version;
94 uint8_t major_version;
97 bool supports_jtag_to_swd;
100 struct pending_transfer_result {
106 static bool kitprog_init_acquire_psoc;
108 static int pending_transfer_count, pending_queue_len;
109 static struct pending_transfer_result *pending_transfers;
111 static int queued_retval;
113 static struct kitprog *kitprog_handle;
115 static int kitprog_usb_open(void);
116 static void kitprog_usb_close(void);
118 static int kitprog_hid_command(uint8_t *command, size_t command_length,
119 uint8_t *data, size_t data_length);
120 static int kitprog_get_version(void);
121 static int kitprog_get_millivolts(void);
122 static int kitprog_get_info(void);
123 static int kitprog_set_protocol(uint8_t protocol);
124 static int kitprog_get_status(void);
125 static int kitprog_set_unknown(void);
126 static int kitprog_acquire_psoc(uint8_t psoc_type, uint8_t acquire_mode,
127 uint8_t max_attempts);
128 static int kitprog_reset_target(void);
129 static int kitprog_swd_sync(void);
130 static int kitprog_swd_seq(uint8_t seq_type);
132 static int kitprog_generic_acquire(void);
134 static int kitprog_swd_run_queue(void);
135 static void kitprog_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data);
136 static int kitprog_swd_switch_seq(enum swd_special_seq seq);
139 static inline int mm_to_version(uint8_t major, uint8_t minor)
141 return (major << 8) | minor;
144 static int kitprog_init(void)
148 kitprog_handle = malloc(sizeof(struct kitprog));
149 if (!kitprog_handle) {
150 LOG_ERROR("Failed to allocate memory");
154 if (kitprog_usb_open() != ERROR_OK) {
155 LOG_ERROR("Can't find a KitProg device! Please check device connections and permissions.");
156 return ERROR_JTAG_INIT_FAILED;
159 /* Get the current KitProg version and target voltage */
160 if (kitprog_get_info() != ERROR_OK)
163 /* Compatibility check */
164 kitprog_handle->supports_jtag_to_swd = true;
165 int kitprog_version = mm_to_version(kitprog_handle->major_version, kitprog_handle->minor_version);
166 if (kitprog_version < mm_to_version(2, 14)) {
167 LOG_WARNING("KitProg firmware versions below v2.14 do not support sending JTAG to SWD sequences. These sequences will be substituted with SWD line resets.");
168 kitprog_handle->supports_jtag_to_swd = false;
171 /* I have no idea what this does */
172 if (kitprog_set_unknown() != ERROR_OK)
175 /* SWD won't work unless we do this */
176 if (kitprog_swd_sync() != ERROR_OK)
179 /* Set the protocol to SWD */
180 if (kitprog_set_protocol(PROTOCOL_SWD) != ERROR_OK)
183 /* Reset the SWD bus */
184 if (kitprog_swd_seq(SEQUENCE_LINE_RESET) != ERROR_OK)
187 if (kitprog_init_acquire_psoc) {
188 /* Try to acquire any device that will respond */
189 retval = kitprog_generic_acquire();
190 if (retval != ERROR_OK) {
191 LOG_ERROR("No PSoC devices found");
196 /* Allocate packet buffers and queues */
197 kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH;
198 kitprog_handle->packet_buffer = malloc(SWD_MAX_BUFFER_LENGTH);
199 if (!kitprog_handle->packet_buffer) {
200 LOG_ERROR("Failed to allocate memory for the packet buffer");
204 pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5;
205 pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers));
206 if (!pending_transfers) {
207 LOG_ERROR("Failed to allocate memory for the SWD transfer queue");
214 static int kitprog_quit(void)
218 free(kitprog_handle->packet_buffer);
219 free(kitprog_handle->serial);
220 free(kitprog_handle);
221 free(pending_transfers);
226 /*************** kitprog usb functions *********************/
228 static int kitprog_get_usb_serial(void)
231 const uint8_t str_index = 128; /* This seems to be a constant */
232 char desc_string[256+1]; /* Max size of string descriptor */
234 retval = libusb_get_string_descriptor_ascii(kitprog_handle->usb_handle,
235 str_index, (unsigned char *)desc_string, sizeof(desc_string)-1);
237 LOG_ERROR("libusb_get_string_descriptor_ascii() failed with %d", retval);
241 /* Null terminate descriptor string */
242 desc_string[retval] = '\0';
244 /* Allocate memory for the serial number */
245 kitprog_handle->serial = calloc(retval + 1, sizeof(char));
246 if (!kitprog_handle->serial) {
247 LOG_ERROR("Failed to allocate memory for the serial number");
251 /* Store the serial number */
252 strncpy(kitprog_handle->serial, desc_string, retval + 1);
257 static int kitprog_usb_open(void)
259 const uint16_t vids[] = { VID, 0 };
260 const uint16_t pids[] = { PID, 0 };
262 if (jtag_libusb_open(vids, pids, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
263 LOG_ERROR("Failed to open or find the device");
267 /* Get the serial number for the device */
268 if (kitprog_get_usb_serial() != ERROR_OK)
269 LOG_WARNING("Failed to get KitProg serial number");
271 /* Convert the ASCII serial number into a (wchar_t *) */
272 size_t len = strlen(kitprog_handle->serial);
273 wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t));
275 LOG_ERROR("Failed to allocate memory for the serial number");
278 if (mbstowcs(hid_serial, kitprog_handle->serial, len + 1) == (size_t)-1) {
280 LOG_ERROR("Failed to convert serial number");
284 /* Use HID for the KitBridge interface */
285 kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial);
287 if (!kitprog_handle->hid_handle) {
288 LOG_ERROR("Failed to open KitBridge (HID) interface");
292 /* Claim the KitProg Programmer (bulk transfer) interface */
293 if (libusb_claim_interface(kitprog_handle->usb_handle, 1) != ERROR_OK) {
294 LOG_ERROR("Failed to claim KitProg Programmer (bulk transfer) interface");
301 static void kitprog_usb_close(void)
303 if (kitprog_handle->hid_handle) {
304 hid_close(kitprog_handle->hid_handle);
308 jtag_libusb_close(kitprog_handle->usb_handle);
311 /*************** kitprog lowlevel functions *********************/
313 static int kitprog_hid_command(uint8_t *command, size_t command_length,
314 uint8_t *data, size_t data_length)
318 ret = hid_write(kitprog_handle->hid_handle, command, command_length);
320 LOG_DEBUG("HID write returned %i", ret);
324 ret = hid_read(kitprog_handle->hid_handle, data, data_length);
326 LOG_DEBUG("HID read returned %i", ret);
333 static int kitprog_get_version(void)
337 unsigned char command[3] = {HID_TYPE_START | HID_TYPE_WRITE, 0x00, HID_COMMAND_VERSION};
338 unsigned char data[64];
340 ret = kitprog_hid_command(command, sizeof(command), data, sizeof(data));
344 kitprog_handle->hardware_version = data[1];
345 kitprog_handle->minor_version = data[2];
346 kitprog_handle->major_version = data[3];
351 static int kitprog_get_millivolts(void)
355 unsigned char command[3] = {HID_TYPE_START | HID_TYPE_READ, 0x00, HID_COMMAND_POWER};
356 unsigned char data[64];
358 ret = kitprog_hid_command(command, sizeof(command), data, sizeof(data));
362 kitprog_handle->millivolts = (data[4] << 8) | data[3];
367 static int kitprog_get_info(void)
369 /* Get the device version information */
370 if (kitprog_get_version() == ERROR_OK) {
371 LOG_INFO("KitProg v%u.%02u",
372 kitprog_handle->major_version, kitprog_handle->minor_version);
373 LOG_INFO("Hardware version: %u",
374 kitprog_handle->hardware_version);
376 LOG_ERROR("Failed to get KitProg version");
380 /* Get the current reported target voltage */
381 if (kitprog_get_millivolts() == ERROR_OK) {
382 LOG_INFO("VTARG = %u.%03u V",
383 kitprog_handle->millivolts / 1000, kitprog_handle->millivolts % 1000);
385 LOG_ERROR("Failed to get target voltage");
392 static int kitprog_set_protocol(uint8_t protocol)
395 char status = PROGRAMMER_NOK_NACK;
397 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
398 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
400 (CONTROL_MODE_SET_PROGRAMMER_PROTOCOL << 8) | CONTROL_COMMAND_PROGRAM,
401 protocol, &status, 1, 0);
403 if (transferred == 0) {
404 LOG_DEBUG("Zero bytes transferred");
408 if (status != PROGRAMMER_OK_ACK) {
409 LOG_DEBUG("Programmer did not respond OK");
416 static int kitprog_get_status(void)
419 char status = PROGRAMMER_NOK_NACK;
421 /* Try a maximum of three times */
422 for (int i = 0; (i < 3) && (transferred == 0); i++) {
423 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
424 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
426 (CONTROL_MODE_POLL_PROGRAMMER_STATUS << 8) | CONTROL_COMMAND_PROGRAM,
431 if (transferred == 0) {
432 LOG_DEBUG("Zero bytes transferred");
436 if (status != PROGRAMMER_OK_ACK) {
437 LOG_DEBUG("Programmer did not respond OK");
444 static int kitprog_set_unknown(void)
447 char status = PROGRAMMER_NOK_NACK;
449 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
450 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
455 if (transferred == 0) {
456 LOG_DEBUG("Zero bytes transferred");
460 if (status != PROGRAMMER_OK_ACK) {
461 LOG_DEBUG("Programmer did not respond OK");
468 static int kitprog_acquire_psoc(uint8_t psoc_type, uint8_t acquire_mode,
469 uint8_t max_attempts)
472 char status = PROGRAMMER_NOK_NACK;
474 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
475 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
477 (CONTROL_MODE_ACQUIRE_SWD_TARGET << 8) | CONTROL_COMMAND_PROGRAM,
478 (max_attempts << 8) | (acquire_mode << 4) | psoc_type, &status, 1, 0);
480 if (transferred == 0) {
481 LOG_DEBUG("Zero bytes transferred");
485 if (status != PROGRAMMER_OK_ACK) {
486 LOG_DEBUG("Programmer did not respond OK");
493 static int kitprog_reset_target(void)
496 char status = PROGRAMMER_NOK_NACK;
498 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
499 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
501 (CONTROL_MODE_RESET_TARGET << 8) | CONTROL_COMMAND_PROGRAM,
504 if (transferred == 0) {
505 LOG_DEBUG("Zero bytes transferred");
509 if (status != PROGRAMMER_OK_ACK) {
510 LOG_DEBUG("Programmer did not respond OK");
517 static int kitprog_swd_sync(void)
520 char status = PROGRAMMER_NOK_NACK;
522 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
523 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
525 (CONTROL_MODE_SYNCHRONIZE_TRANSFER << 8) | CONTROL_COMMAND_PROGRAM,
528 if (transferred == 0) {
529 LOG_DEBUG("Zero bytes transferred");
533 if (status != PROGRAMMER_OK_ACK) {
534 LOG_DEBUG("Programmer did not respond OK");
541 static int kitprog_swd_seq(uint8_t seq_type)
544 char status = PROGRAMMER_NOK_NACK;
546 transferred = jtag_libusb_control_transfer(kitprog_handle->usb_handle,
547 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
549 (CONTROL_MODE_SEND_SWD_SEQUENCE << 8) | CONTROL_COMMAND_PROGRAM,
550 seq_type, &status, 1, 0);
552 if (transferred == 0) {
553 LOG_DEBUG("Zero bytes transferred");
557 if (status != PROGRAMMER_OK_ACK) {
558 LOG_DEBUG("Programmer did not respond OK");
565 static int kitprog_generic_acquire(void)
567 const uint8_t devices[] = {DEVICE_PSOC4, DEVICE_PSOC3, DEVICE_PSOC5};
570 int acquire_count = 0;
572 /* Due to the way the SWD port is shared between the Test Controller (TC)
573 * and the Cortex-M3 DAP on the PSoC 5LP, the TC is the default SWD target
574 * after power is applied. To access the DAP, the PSoC 5LP requires at least
575 * one acquisition sequence to be run (which switches the SWD mux from the
576 * TC to the DAP). However, after the mux is switched, the Cortex-M3 will be
577 * held in reset until a series of registers are written to (see section 5.2
578 * of the PSoC 5LP Device Programming Specifications for details).
580 * Instead of writing the registers in this function, we just do what the
581 * Cypress tools do and run the acquisition sequence a second time. This
582 * will take the Cortex-M3 out of reset and enable debugging.
584 for (int i = 0; i < 2; i++) {
585 for (uint8_t j = 0; j < sizeof(devices) && acquire_count == i; j++) {
586 retval = kitprog_acquire_psoc(devices[j], ACQUIRE_MODE_RESET, 3);
587 if (retval != ERROR_OK) {
588 LOG_DEBUG("Acquisition function failed for device 0x%02x.", devices[j]);
592 if (kitprog_get_status() == ERROR_OK)
599 if (acquire_count < 2)
605 /*************** swd wrapper functions *********************/
607 static int kitprog_swd_init(void)
612 static void kitprog_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
614 assert(!(cmd & SWD_CMD_RNW));
615 kitprog_swd_queue_cmd(cmd, NULL, value);
618 static void kitprog_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
620 assert(cmd & SWD_CMD_RNW);
621 kitprog_swd_queue_cmd(cmd, value, 0);
624 /*************** swd lowlevel functions ********************/
626 static int kitprog_swd_switch_seq(enum swd_special_seq seq)
630 if (kitprog_handle->supports_jtag_to_swd) {
631 LOG_DEBUG("JTAG to SWD");
632 if (kitprog_swd_seq(SEQUENCE_JTAG_TO_SWD) != ERROR_OK)
636 LOG_DEBUG("JTAG to SWD not supported");
637 /* Fall through to fix target reset issue */
641 LOG_DEBUG("SWD line reset");
642 if (kitprog_swd_seq(SEQUENCE_LINE_RESET) != ERROR_OK)
646 LOG_ERROR("Sequence %d not supported.", seq);
653 static int kitprog_swd_run_queue(void)
657 size_t read_count = 0;
658 size_t read_index = 0;
659 size_t write_count = 0;
660 uint8_t *buffer = kitprog_handle->packet_buffer;
663 LOG_DEBUG_IO("Executing %d queued transactions", pending_transfer_count);
665 if (queued_retval != ERROR_OK) {
666 LOG_DEBUG("Skipping due to previous errors: %d", queued_retval);
670 if (!pending_transfer_count)
673 for (int i = 0; i < pending_transfer_count; i++) {
674 uint8_t cmd = pending_transfers[i].cmd;
675 uint32_t data = pending_transfers[i].data;
677 /* When proper WAIT handling is implemented in the
678 * common SWD framework, this kludge can be
679 * removed. However, this might lead to minor
680 * performance degradation as the adapter wouldn't be
681 * able to automatically retry anything (because ARM
682 * has forgotten to implement sticky error flags
683 * clearing). See also comments regarding
684 * cmsis_dap_cmd_DAP_TFER_Configure() and
685 * cmsis_dap_cmd_DAP_SWD_Configure() in
688 if (!(cmd & SWD_CMD_RNW) &&
689 !(cmd & SWD_CMD_APNDP) &&
690 (cmd & SWD_CMD_A32) >> 1 == DP_CTRL_STAT &&
691 (data & CORUNDETECT)) {
692 LOG_DEBUG("refusing to enable sticky overrun detection");
693 data &= ~CORUNDETECT;
696 LOG_DEBUG_IO("%s %s reg %x %"PRIx32,
697 cmd & SWD_CMD_APNDP ? "AP" : "DP",
698 cmd & SWD_CMD_RNW ? "read" : "write",
699 (cmd & SWD_CMD_A32) >> 1, data);
701 buffer[write_count++] = (cmd | SWD_CMD_START | SWD_CMD_PARK) & ~SWD_CMD_STOP;
703 if (!(cmd & SWD_CMD_RNW)) {
704 buffer[write_count++] = (data) & 0xff;
705 buffer[write_count++] = (data >> 8) & 0xff;
706 buffer[write_count++] = (data >> 16) & 0xff;
707 buffer[write_count++] = (data >> 24) & 0xff;
713 if (jtag_libusb_bulk_write(kitprog_handle->usb_handle,
714 BULK_EP_OUT, (char *)buffer,
715 write_count, 0, &ret)) {
716 LOG_ERROR("Bulk write failed");
717 queued_retval = ERROR_FAIL;
720 queued_retval = ERROR_OK;
723 /* KitProg firmware does not send a zero length packet
724 * after the bulk-in transmission of a length divisible by bulk packet
725 * size (64 bytes) as required by the USB specification.
726 * Therefore libusb would wait for continuation of transmission.
727 * Workaround: Limit bulk read size to expected number of bytes
728 * for problematic transfer sizes. Otherwise use the maximum buffer
729 * size here because the KitProg sometimes doesn't like bulk reads
730 * of fewer than 62 bytes. (?!?!)
732 size_t read_count_workaround = SWD_MAX_BUFFER_LENGTH;
733 if (read_count % 64 == 0)
734 read_count_workaround = read_count;
736 if (jtag_libusb_bulk_read(kitprog_handle->usb_handle,
737 BULK_EP_IN | LIBUSB_ENDPOINT_IN, (char *)buffer,
738 read_count_workaround, 1000, &ret)) {
739 LOG_ERROR("Bulk read failed");
740 queued_retval = ERROR_FAIL;
743 /* Handle garbage data by offsetting the initial read index */
744 if ((unsigned int)ret > read_count)
745 read_index = ret - read_count;
746 queued_retval = ERROR_OK;
749 for (int i = 0; i < pending_transfer_count; i++) {
750 if (pending_transfers[i].cmd & SWD_CMD_RNW) {
751 uint32_t data = le_to_h_u32(&buffer[read_index]);
753 LOG_DEBUG_IO("Read result: %"PRIx32, data);
755 if (pending_transfers[i].buffer)
756 *(uint32_t *)pending_transfers[i].buffer = data;
761 uint8_t ack = buffer[read_index] & 0x07;
762 if (ack != SWD_ACK_OK || (buffer[read_index] & 0x08)) {
763 LOG_DEBUG("SWD ack not OK: %d %s", i,
764 ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK");
765 queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL;
772 pending_transfer_count = 0;
773 int retval = queued_retval;
774 queued_retval = ERROR_OK;
779 static void kitprog_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
781 if (pending_transfer_count == pending_queue_len) {
782 /* Not enough room in the queue. Run the queue. */
783 queued_retval = kitprog_swd_run_queue();
786 if (queued_retval != ERROR_OK)
789 pending_transfers[pending_transfer_count].data = data;
790 pending_transfers[pending_transfer_count].cmd = cmd;
791 if (cmd & SWD_CMD_RNW) {
792 /* Queue a read transaction */
793 pending_transfers[pending_transfer_count].buffer = dst;
795 pending_transfer_count++;
798 /*************** jtag lowlevel functions ********************/
800 static int kitprog_reset(int trst, int srst)
802 int retval = ERROR_OK;
805 LOG_ERROR("KitProg: Interface has no TRST");
810 retval = kitprog_reset_target();
811 /* Since the previous command also disables SWCLK output, we need to send an
812 * SWD bus reset command to re-enable it. For some reason, running
813 * kitprog_swd_seq() immediately after kitprog_reset_target() won't
814 * actually fix this. Instead, kitprog_swd_seq() will be run once OpenOCD
815 * tries to send a JTAG-to-SWD sequence, which should happen during
816 * swd_check_reconnect (see the JTAG_TO_SWD case in kitprog_swd_switch_seq).
820 if (retval != ERROR_OK)
821 LOG_ERROR("KitProg: Interface reset failed");
825 COMMAND_HANDLER(kitprog_handle_info_command)
827 int retval = kitprog_get_info();
833 COMMAND_HANDLER(kitprog_handle_acquire_psoc_command)
835 int retval = kitprog_generic_acquire();
840 COMMAND_HANDLER(kitprog_handle_init_acquire_psoc_command)
842 kitprog_init_acquire_psoc = true;
847 static const struct command_registration kitprog_subcommand_handlers[] = {
850 .handler = &kitprog_handle_info_command,
851 .mode = COMMAND_EXEC,
853 .help = "show KitProg info",
856 .name = "acquire_psoc",
857 .handler = &kitprog_handle_acquire_psoc_command,
858 .mode = COMMAND_EXEC,
860 .help = "try to acquire a PSoC",
862 COMMAND_REGISTRATION_DONE
865 static const struct command_registration kitprog_command_handlers[] = {
869 .help = "perform KitProg management",
871 .chain = kitprog_subcommand_handlers,
874 .name = "kitprog_init_acquire_psoc",
875 .handler = &kitprog_handle_init_acquire_psoc_command,
876 .mode = COMMAND_CONFIG,
877 .help = "try to acquire a PSoC during init",
880 COMMAND_REGISTRATION_DONE
883 static const struct swd_driver kitprog_swd = {
884 .init = kitprog_swd_init,
885 .switch_seq = kitprog_swd_switch_seq,
886 .read_reg = kitprog_swd_read_reg,
887 .write_reg = kitprog_swd_write_reg,
888 .run = kitprog_swd_run_queue,
891 static const char * const kitprog_transports[] = { "swd", NULL };
893 struct adapter_driver kitprog_adapter_driver = {
895 .transports = kitprog_transports,
896 .commands = kitprog_command_handlers,
898 .init = kitprog_init,
899 .quit = kitprog_quit,
900 .reset = kitprog_reset,
902 .swd_ops = &kitprog_swd,