From 523a52ea723e88883533aa74ea423b2d8cb2d289 Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Sun, 2 Mar 2008 00:22:40 +0000 Subject: [PATCH] Added VREF detection to J-Link cable driver and a call to usb_reset when necessary. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1110 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 4 ++- jtag/src/tap/cable/jlink.c | 56 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index c5a64400..b9eda164 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -7,8 +7,10 @@ 2008-03-01 Kolja Waschk + * src/tap/cable/jlink.c: Added VREF detection and a call to usb_reset() + when cable initialization failed * src/tap/cable/xpc.c: Implemented much faster access method using GPIF - transfers via vendor request 0xA6. + transfers via vendor request 0xA6. Reportedly works with DLC9 now. 2008-02-28 Kolja Waschk diff --git a/jtag/src/tap/cable/jlink.c b/jtag/src/tap/cable/jlink.c index 69ca9fb0..33947a22 100644 --- a/jtag/src/tap/cable/jlink.c +++ b/jtag/src/tap/cable/jlink.c @@ -78,7 +78,15 @@ typedef struct jlink_usbconn_data_t; /* Constants for JLink command */ +#define JLINK_DO_TRST_CYCLE 0x02 #define JLINK_SPEED_COMMAND 0x05 +#define JLINK_GET_STATUS_COMMAND 0x07 +#define JLINK_GET_A 0xc1 +#define JLINK_GET_B 0xc2 +#define JLINK_SET_TMS_LOW_COMMAND 0xc9 +#define JLINK_SET_TMS_HIGH_COMMAND 0xca +#define JLINK_SET_TDI_LOW_COMMAND 0xcb +#define JLINK_SET_TDI_HIGH_COMMAND 0xcc #define JLINK_TAP_SEQUENCE_COMMAND 0xcd #define JLINK_SET_SRST_LOW_COMMAND 0xdc #define JLINK_SET_SRST_HIGH_COMMAND 0xdd @@ -102,7 +110,7 @@ static int jlink_usb_message( libusb_param_t *params, int, int ); static int jlink_usb_write( libusb_param_t *params, unsigned int ); static int jlink_usb_read( libusb_param_t *params ); -static void jlink_debug_buffer(uint8_t *buffer, int length); +static void jlink_debug_buffer(char *buffer, int length); /* API functions */ @@ -152,6 +160,41 @@ static void jlink_simple_command( libusb_param_t *params, uint8_t command) } } +static int jlink_get_status( libusb_param_t *params ) +{ + int result; + jlink_usbconn_data_t *data = params->data; + + jlink_simple_command( params, 0x07 ); + + result = jlink_usb_read( params ); + + if(result == 8) + { + int vref = data->usb_in_buffer[0] + (data->usb_in_buffer[1]<<8); + INFO("Vref = %d.%d TCK=%d TDI=%d TDO=%d TMS=%d TRES=%d TRST=%d\n", + vref / 1000, vref % 1000, + data->usb_in_buffer[2], + data->usb_in_buffer[3], + data->usb_in_buffer[4], + data->usb_in_buffer[5], + data->usb_in_buffer[6], + data->usb_in_buffer[7]); + if(vref < 1500) + { + ERROR("Vref too low. Eventually the target isn't powered or disconnected?\n"); + result = -15; + }; + } + else + { + ERROR("J-Link command 0x07 (get status) failed (%d)\n", result); + } + + return result; +} + + /***************************************************************************/ static void jlink_tap_init( jlink_usbconn_data_t *data ) @@ -337,7 +380,7 @@ static int jlink_usb_read( libusb_param_t *params ) #define BYTES_PER_LINE 16 -static void jlink_debug_buffer(uint8_t *buffer, int length) +static void jlink_debug_buffer(char *buffer, int length) { char line[81]; char s[4]; @@ -386,6 +429,14 @@ jlink_init( cable_t *cable ) INFO("J-Link initial read failed, don't worry (result=%d)\n", result); } + result = jlink_get_status( params ); + if (result < 0) + { + ERROR("Resetting J-Link. Please retry the cable command.\n"); + usb_reset ( params->handle ); + return -1; + } + INFO("J-Link JTAG Interface ready\n"); jlink_set_frequency( cable, 4E6 ); @@ -419,6 +470,7 @@ void jlink_set_frequency( cable_t *cable, uint32_t frequency ) if (1 <= speed && speed <= JLINK_MAX_SPEED) { data->usb_out_buffer[0] = JLINK_SPEED_COMMAND; + /* speed = 0xFFFF for automatic (probably needs RTCK) */ data->usb_out_buffer[1] = (speed >> 0) & 0xff; data->usb_out_buffer[2] = (speed >> 8) & 0xff;