Browse Source

drivers/arm-jtag-ew: switch to libusb1

Convert the driver from libusb0 to libusb1.

Change-Id: Idef0b6cf10fab583bc8d13b3b4fadd5cc368c090
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5990
Tested-by: jenkins
jim
Antonio Borneo 1 year ago
parent
commit
ef41652caf
2 changed files with 29 additions and 21 deletions
  1. +2
    -1
      configure.ac
  2. +27
    -20
      src/jtag/drivers/arm-jtag-ew.c

+ 2
- 1
configure.ac View File

@@ -122,12 +122,13 @@ m4_define([USB1_ADAPTERS],
[[cmsis_dap_v2], [CMSIS-DAP v2 Compliant Debugger], [CMSIS_DAP_USB]],
[[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]],
[[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]],
[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]],
[[rlink], [Raisonance RLink JTAG Programmer], [RLINK]],
[[usbprog], [USBProg JTAG Programmer], [USBPROG]],
[[aice], [Andes JTAG Programmer], [AICE]]])

m4_define([USB0_ADAPTERS],
[[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]])
[])

m4_define([HIDAPI_ADAPTERS],
[[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP_HID]],


+ 27
- 20
src/jtag/drivers/arm-jtag-ew.c View File

@@ -22,8 +22,7 @@

#include <jtag/interface.h>
#include <jtag/commands.h>
#include <usb.h>
#include "usb_common.h"
#include "libusb_helper.h"

#define USB_VID 0x15ba
#define USB_PID 0x001e
@@ -75,7 +74,7 @@ static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_c

/* ARM-JTAG-EW lowlevel functions */
struct armjtagew {
struct usb_dev_handle *usb_handle;
struct libusb_device_handle *usb_handle;
};

static struct armjtagew *armjtagew_usb_open(void);
@@ -684,35 +683,37 @@ static int armjtagew_tap_execute(void)

static struct armjtagew *armjtagew_usb_open(void)
{
usb_init();

const uint16_t vids[] = { USB_VID, 0 };
const uint16_t pids[] = { USB_PID, 0 };
struct usb_dev_handle *dev;
if (jtag_usb_open(vids, pids, &dev) != ERROR_OK)
struct libusb_device_handle *dev;

if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
return NULL;

struct armjtagew *result = malloc(sizeof(struct armjtagew));
result->usb_handle = dev;

#if 0
/* usb_set_configuration required under win32 */
usb_set_configuration(dev, dev->config[0].bConfigurationValue);
/* libusb_set_configuration required under win32 */
struct libusb_config_descriptor *config;
struct libusb_device *usb_dev = libusb_get_device(dev);
libusb_get_config_descriptor(usb_dev, 0, &config);
libusb_set_configuration(dev, config->bConfigurationValue);
#endif
usb_claim_interface(dev, 0);
libusb_claim_interface(dev, 0);
#if 0
/*
* This makes problems under Mac OS X. And is not needed
* under Windows. Hopefully this will not break a linux build
*/
usb_set_altinterface(dev, 0);
libusb_set_interface_alt_setting(dev, 0, 0);
#endif
return result;
}

static void armjtagew_usb_close(struct armjtagew *armjtagew)
{
usb_close(armjtagew->usb_handle);
libusb_close(armjtagew->usb_handle);
free(armjtagew);
}

@@ -725,13 +726,13 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
if (result == out_length) {
result = armjtagew_usb_read(armjtagew, in_length);
if (result != in_length) {
LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
LOG_ERROR("jtag_libusb_bulk_read failed (requested=%d, result=%d)",
in_length,
result);
return -1;
}
} else {
LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
LOG_ERROR("jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
return -1;
}
return 0;
@@ -741,6 +742,7 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
{
int result;
int transferred;

if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
@@ -749,29 +751,34 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
return -1;
}

result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT,
(char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT);
result = jtag_libusb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT,
(char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT, &transferred);

LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);

#ifdef _DEBUG_USB_COMMS_
armjtagew_debug_buffer(usb_out_buffer, out_length);
#endif
return result;
if (result != ERROR_OK)
return -1;
return transferred;
}

/* Read data from USB into in_buffer. */
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
{
int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN,
(char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT);
int transferred;
int result = jtag_libusb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN,
(char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT, &transferred);

LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result);

#ifdef _DEBUG_USB_COMMS_
armjtagew_debug_buffer(usb_in_buffer, result);
#endif
return result;
if (result != ERROR_OK)
return -1;
return transferred;
}

#ifdef _DEBUG_USB_COMMS_


Loading…
Cancel
Save