From aa43c22d9206a9a990e5b8e782925bfe199cfc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Tue, 26 Feb 2008 22:31:07 +0000 Subject: [PATCH] enhanced init sequence in *_mpsse_open() git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1101 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 6 ++++++ jtag/src/tap/cable/ft2232.c | 28 ---------------------------- jtag/src/tap/parport/ftd2xx.c | 26 ++++++++++++++++++++++++-- jtag/src/tap/parport/ftdi.c | 29 ++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 457f5105..94e524c5 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2008-02-26 Arnim Laeuger + + * src/tap/cable/ft2232.c (send_and_receive): loopback_off moved to ftdi.c/ftd2xx.c + * src/tap/parport/ftd2xx.c (ftd2xx_mpsse_open): set TCK, loopback_off, reset, purge + * src/tap/parport/ftdi.c (ftdi_mpsse_open): set TCK, loopback_off, reset, purge + 2008-02-24 Mike Frysinger * src/jtag.c: allow people to disable startup message (1901877), diff --git a/jtag/src/tap/cable/ft2232.c b/jtag/src/tap/cable/ft2232.c index 5775ad65..e8559a25 100644 --- a/jtag/src/tap/cable/ft2232.c +++ b/jtag/src/tap/cable/ft2232.c @@ -341,10 +341,6 @@ ft2232_generic_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* safe default values */ params->low_byte_value = 0; params->low_byte_dir = 0; @@ -379,10 +375,6 @@ ft2232_jtagkey_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction: set nOE to '0' -> activate output enables */ params->low_byte_value = 0; @@ -428,10 +420,6 @@ ft2232_armusbocd_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction: set nOE to '0' -> activate output enables */ params->low_byte_value = 0; @@ -481,10 +469,6 @@ ft2232_oocdlinks_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction */ params->low_byte_value = 0; params->low_byte_dir = 0; @@ -530,10 +514,6 @@ ft2232_turtelizer2_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction: set nJTAGOE to '0' -> activate output enables set RST to 0 -> inactive nSRST */ @@ -574,10 +554,6 @@ ft2232_usbtojtagif_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction: nTRST = 1, RST = 1, DBGRQ = 0 */ params->low_byte_value = BITMASK_USBTOJTAGIF_nTRST | BITMASK_USBTOJTAGIF_RST; @@ -619,10 +595,6 @@ ft2232_signalyzer_init( cable_t *cable ) if (parport_open( p )) return -1; - /* set loopback off */ - push_to_send( params, LOOPBACK_END ); - send_and_receive( cable, COMPLETELY ); - /* static low byte value and direction: nTRST = 1, RST = 1, DBGRQ = 0 */ params->low_byte_value = BITMASK_SIGNALYZER_nTRST | BITMASK_SIGNALYZER_nSRST; diff --git a/jtag/src/tap/parport/ftd2xx.c b/jtag/src/tap/parport/ftd2xx.c index 064cba49..7a400d12 100644 --- a/jtag/src/tap/parport/ftd2xx.c +++ b/jtag/src/tap/parport/ftd2xx.c @@ -74,6 +74,8 @@ typedef struct { int outbuf_len; } ftd2xx_params_t; +static int ftd2xx_set_data ( parport_t *parport, uint8_t data ); +static int ftd2xx_set_control ( parport_t *parport, uint8_t data ); static int ftd2xx_flush_output ( ftd2xx_params_t *p ); static parport_t * @@ -283,7 +285,7 @@ ftd2xx_mpsse_open( parport_t *parport ) Ref. FTCJTAGPG10.pdf Intermittent problems will occur when certain steps are skipped. */ if ((status = FT_ResetDevice(fc)) != FT_OK) { - fprintf(stderr, "Can't reset 1 device: %li\n", status); + fprintf(stderr, "Can't reset device: %li\n", status); FT_Close(fc); return -1; } @@ -311,7 +313,27 @@ ftd2xx_mpsse_open( parport_t *parport ) return -1; } if ((status = FT_ResetDevice(fc)) != FT_OK) { - fprintf(stderr, "Can't reset 2 device: %li\n", status); + fprintf(stderr, "Can't reset device: %li\n", status); + FT_Close(fc); + return -1; + } + if ((status = FT_Purge(fc, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK) { + fprintf(stderr, "Can't purge buffers: %li\n", status); + FT_Close(fc); + return -1; + } + /* set TCK Divisor */ + ftd2xx_set_data(parport, 0x86); + ftd2xx_set_data(parport, 0x00); + ftd2xx_set_data(parport, 0x00); + ftd2xx_set_control(parport, 1); + ftd2xx_set_control(parport, 0); + /* switch off loopback */ + ftd2xx_set_data(parport, 0x85); + ftd2xx_set_control(parport, 1); + ftd2xx_set_control(parport, 0); + if ((status = FT_ResetDevice(fc)) != FT_OK) { + fprintf(stderr, "Can't reset device: %li\n", status); FT_Close(fc); return -1; } diff --git a/jtag/src/tap/parport/ftdi.c b/jtag/src/tap/parport/ftdi.c index 2d52bf5c..677691f9 100644 --- a/jtag/src/tap/parport/ftdi.c +++ b/jtag/src/tap/parport/ftdi.c @@ -69,6 +69,8 @@ typedef struct { int outbuf_len; } ftdi_params_t; +static int ftdi_set_data ( parport_t *parport, uint8_t data ); +static int ftdi_set_control ( parport_t *parport, uint8_t data ); static int ftdi_flush_output ( ftdi_params_t *p ); static parport_t * @@ -367,7 +369,32 @@ ftdi_mpsse_open( parport_t *parport ) ftdi_deinit(fc); return -1; } - + /* set TCK Divisor */ + ftdi_set_data(parport, TCK_DIVISOR); + ftdi_set_data(parport, 0x00); + ftdi_set_data(parport, 0x00); + ftdi_set_control(parport, 1); + ftdi_set_control(parport, 0); + /* switch off loopback */ + ftdi_set_data(parport, LOOPBACK_END); + ftdi_set_control(parport, 1); + ftdi_set_control(parport, 0); + if (ftdi_usb_reset(fc) < 0) + { + fprintf (stderr, "Can't reset USB: %s\n", + ftdi_get_error_string (fc)); + ftdi_usb_close(fc); + ftdi_deinit(fc); + return -1; + } + if (ftdi_usb_purge_buffers(fc) < 0) + { + fprintf (stderr, "Can't purge USB buffers: %s\n", + ftdi_get_error_string (fc)); + ftdi_usb_close(fc); + ftdi_deinit(fc); + return -1; + } return 0; }