This is an automated email from Gerrit. Philip Craig ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/1447
-- gerrit commit a2cfb3197ddb8c86847a59aefa16a9fa75885bf0 Author: Philip Craig <[email protected]> Date: Mon Jun 17 13:56:33 2013 +1000 jlink: improve USB read during jlink_tap_execute Previously, when doing EMU_CMD_HW_JTAG3 commands we would do two reads, one to read the data, and one to read the result. However, we can just do a single larger read instead. The motivation for this change is a weird problem. If I run the Segger software before running OpenOCD, then the first read always fails: Error: usb_bulk_read failed (requested=1, result=0) Error: jlink_tap_execute, wrong result -107 (expected 1) Sniffing the USB traffic shows that the J-Link is returning an overflow error, meaning it is expecting to return the full result in a single read. Change-Id: I75e020d3b3732c9a74ee3d31838fdf17a7fac24c Signed-off-by: Philip Craig <[email protected]> diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index ae6a022..03f6a31 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -64,14 +64,12 @@ static unsigned int jlink_hw_jtag_version = 2; /*#define JLINK_TAP_BUFFER_SIZE 256*/ /*#define JLINK_TAP_BUFFER_SIZE 384*/ -#define JLINK_IN_BUFFER_SIZE 2048 +#define JLINK_IN_BUFFER_SIZE (2048 + 1) #define JLINK_OUT_BUFFER_SIZE (2*2048 + 4) -#define JLINK_EMU_RESULT_BUFFER_SIZE 64 /* Global USB buffers */ static uint8_t usb_in_buffer[JLINK_IN_BUFFER_SIZE]; static uint8_t usb_out_buffer[JLINK_OUT_BUFFER_SIZE]; -static uint8_t usb_emu_result_buffer[JLINK_EMU_RESULT_BUFFER_SIZE]; /* Constants for JLink command */ #define EMU_CMD_VERSION 0x01 @@ -227,11 +225,9 @@ struct jlink { static struct jlink *jlink_usb_open(void); static void jlink_usb_close(struct jlink *jlink); -static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length); static int jlink_usb_io(struct jlink *jlink, int out_length, int in_length); static int jlink_usb_write(struct jlink *jlink, int out_length); static int jlink_usb_read(struct jlink *jlink, int expected_size); -static int jlink_usb_read_emu_result(struct jlink *jlink); /* helper functions */ static int jlink_get_version_info(void); @@ -1425,14 +1421,20 @@ static int jlink_tap_execute(void) jlink_last_state = jtag_debug_state_machine(tms_buffer, tdi_buffer, tap_length, jlink_last_state); - result = jlink_usb_message(jlink_handle, 4 + 2 * byte_length, byte_length); - if (result != byte_length) { - LOG_ERROR("jlink_tap_execute, wrong result %d (expected %d)", - result, byte_length); + result = jlink_usb_io(jlink_handle, 4 + 2 * byte_length, + use_jtag3 ? byte_length + 1 : byte_length); + if (result != ERROR_OK) { + LOG_ERROR("jlink_tap_execute failed USB io (%d)", result); jlink_tap_init(); return ERROR_JTAG_QUEUE_FAILED; } + result = use_jtag3 ? usb_in_buffer[byte_length] : 0; + if (result != 0) { + LOG_ERROR("jlink_tap_execute failed, result %d", result); + return ERROR_JTAG_QUEUE_FAILED; + } + memcpy(tdo_buffer, usb_in_buffer, byte_length); for (i = 0; i < pending_scan_results_length; i++) { @@ -1530,59 +1532,6 @@ static void jlink_usb_close(struct jlink *jlink) free(jlink); } -/* Send a message and receive the reply. */ -static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length) -{ - int result; - - result = jlink_usb_write(jlink, out_length); - if (result != out_length) { - LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", - out_length, result); - return ERROR_JTAG_DEVICE_ERROR; - } - - result = jlink_usb_read(jlink, in_length); - if ((result != in_length) && (result != (in_length + 1))) { - LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", - in_length, result); - return ERROR_JTAG_DEVICE_ERROR; - } - - if (jlink_hw_jtag_version < 3) - return result; - - int result2 = ERROR_OK; - if (result == in_length) { - /* Must read the result from the EMU too */ - result2 = jlink_usb_read_emu_result(jlink); - if (1 != result2) { - LOG_ERROR("jlink_usb_read_emu_result retried requested = 1, " - "result=%d, in_length=%i", result2, in_length); - /* Try again once, should only happen if (in_length%64 == 0) */ - result2 = jlink_usb_read_emu_result(jlink); - if (1 != result2) { - LOG_ERROR("jlink_usb_read_emu_result failed " - "(requested = 1, result=%d)", result2); - return ERROR_JTAG_DEVICE_ERROR; - } - } - - /* Check the result itself */ - result2 = usb_emu_result_buffer[0]; - } else { - /* Save the result, then remove it from return value */ - result2 = usb_in_buffer[result--]; - } - - if (result2) { - LOG_ERROR("jlink_usb_message failed with result=%d)", result2); - return ERROR_JTAG_DEVICE_ERROR; - } - - return result; -} - /* calls the given usb_bulk_* function, allowing for the data to * trickle in with some timeouts */ static int usb_bulk_with_retries( @@ -1656,19 +1605,6 @@ static int jlink_usb_read(struct jlink *jlink, int expected_size) return result; } -/* Read the result from the previous EMU cmd into result_buffer. */ -static int jlink_usb_read_emu_result(struct jlink *jlink) -{ - int result = usb_bulk_read_ex(jlink->usb_handle, jlink_read_ep, - (char *)usb_emu_result_buffer, 1 /* JLINK_EMU_RESULT_BUFFER_SIZE */, - JLINK_USB_TIMEOUT); - - DEBUG_JTAG_IO("jlink_usb_read_result, result = %d", result); - - jlink_debug_buffer(usb_emu_result_buffer, result); - return result; -} - /* * Send a message and receive the reply - simple messages. * -- ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
