From c1bb903b99fd4be16902f1f1d4f3725c9d6570e9 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Tue, 15 Jun 2010 12:56:20 +1200 Subject: [PATCH] Try to use JTAG mode 2 with UIF devices. --- fet.c | 42 +++++++++++++++++++++++++++++++++--------- main.c | 2 +- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/fet.c b/fet.c index 0907f87..ce41520 100644 --- a/fet.c +++ b/fet.c @@ -771,6 +771,38 @@ static int fet_breakpoint(device_t dev_base, int enabled, uint16_t addr) return 0; } +static int do_configure(struct fet_device *dev, int proto_flags) +{ + if (proto_flags & FET_PROTO_SPYBIWIRE) { + if (!xfer(dev, C_CONFIGURE, NULL, 0, + 2, FET_CONFIG_PROTOCOL, 1)) { + printf("Configured for Spy-bi-wire\n"); + return 0; + } + + fprintf(stderr, "fet: Spy-bi-wire configuration failed\n"); + return -1; + } + + if (!xfer(dev, C_CONFIGURE, NULL, 0, + 2, FET_CONFIG_PROTOCOL, 2)) { + printf("Configured for JTAG (2)\n"); + return 0; + } + + fprintf(stderr, "fet: warning: JTAG configuration failed -- " + "retrying\n"); + + if (!xfer(dev, C_CONFIGURE, NULL, 0, + 2, FET_CONFIG_PROTOCOL, 0)) { + printf("Configured for JTAG (0)\n"); + return 0; + } + + fprintf(stderr, "fet: JTAG configuration failed\n"); + return -1; +} + device_t fet_open(transport_t transport, int proto_flags, int vcc_mv, const char *force_id) { @@ -809,16 +841,8 @@ device_t fet_open(transport_t transport, int proto_flags, int vcc_mv, goto fail; } - /* configure: Spy-Bi-Wire or JTAG */ - if (xfer(dev, C_CONFIGURE, NULL, 0, - 2, FET_CONFIG_PROTOCOL, - (proto_flags & FET_PROTO_SPYBIWIRE) ? 1 : 0) < 0) { - fprintf(stderr, "fet: configure failed\n"); + if (do_configure(dev, proto_flags) < 0) goto fail; - } - - printf("Configured for %s\n", - (proto_flags & FET_PROTO_SPYBIWIRE) ? "Spy-Bi-Wire" : "JTAG"); /* set VCC */ if (xfer(dev, C_VCC, NULL, 0, 1, vcc_mv) < 0) { diff --git a/main.c b/main.c index 69cf90f..101dff6 100644 --- a/main.c +++ b/main.c @@ -130,7 +130,7 @@ static void usage(const char *progname) " -u device\n" " Open the given tty device (MSP430 UIF compatible devices).\n" " -j\n" -" Use JTAG, rather than spy-bi-wire (UIF devices only).\n" +" Use JTAG, rather than Spy-bi-wire (UIF devices only).\n" " -v voltage\n" " Set the supply voltage, in millivolts.\n" " -B device\n"