From a87ad8b834055eef27d365da63b2b71eeeb1719d Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Wed, 19 May 2010 11:54:15 +1200 Subject: [PATCH] Added --fet-force-id command-line option. --- fet.c | 18 +++++++++++------- fet.h | 3 ++- main.c | 22 +++++++++++++++++----- mspdebug.man | 4 ++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/fet.c b/fet.c index 53db9f7..8437480 100644 --- a/fet.c +++ b/fet.c @@ -455,7 +455,7 @@ static int xfer(struct fet_device *dev, * MSP430 high-level control functions */ -static int do_identify(struct fet_device *dev) +static int do_identify(struct fet_device *dev, const char *force_id) { if (dev->version < 20300000) { char idtext[64]; @@ -488,16 +488,19 @@ static int do_identify(struct fet_device *dev) printf("Device ID: 0x%02x%02x\n", dev->fet_reply.data[0], dev->fet_reply.data[1]); - r = fet_db_find_by_msg28(dev->fet_reply.data, - dev->fet_reply.datalen); - - printf("Device: %s\n", r->name); + if (force_id) + r = fet_db_find_by_name(force_id); + else + r = fet_db_find_by_msg28(dev->fet_reply.data, + dev->fet_reply.datalen); if (!r) { fprintf(stderr, "fet: unknown device\n"); return -1; } + printf("Device: %s\n", r->name); + if (xfer(dev, 0x2b, r->msg2b_data, FET_DB_MSG2B_LEN, 0) < 0) { fprintf(stderr, "fet: message 0x2b failed\n"); return -1; @@ -743,7 +746,8 @@ static int fet_breakpoint(device_t dev_base, int enabled, uint16_t addr) return 0; } -device_t fet_open(transport_t transport, int proto_flags, int vcc_mv) +device_t fet_open(transport_t transport, int proto_flags, int vcc_mv, + const char *force_id) { struct fet_device *dev = malloc(sizeof(*dev)); @@ -799,7 +803,7 @@ device_t fet_open(transport_t transport, int proto_flags, int vcc_mv) printf("Set Vcc: %d mV\n", vcc_mv); /* Identify the chip */ - if (do_identify(dev) < 0) { + if (do_identify(dev, force_id) < 0) { fprintf(stderr, "fet: identify failed\n"); goto fail; } diff --git a/fet.h b/fet.h index c5472a9..f939486 100644 --- a/fet.h +++ b/fet.h @@ -26,6 +26,7 @@ #define FET_PROTO_SPYBIWIRE 0x01 #define FET_PROTO_RF2500 0x02 -device_t fet_open(transport_t transport, int proto_flags, int vcc_mv); +device_t fet_open(transport_t transport, int proto_flags, int vcc_mv, + const char *force_id); #endif diff --git a/main.c b/main.c index 6a0e4d7..fa8d827 100644 --- a/main.c +++ b/main.c @@ -142,6 +142,8 @@ static void usage(const char *progname) " Show this help text.\n" " --fet-list\n" " Show a list of devices supported by the FET driver.\n" +" --fet-force-id string\n" +" Override the device ID returned by the FET.\n" "\n" "By default, the first RF2500 device on the USB bus is opened.\n" "\n" @@ -171,6 +173,7 @@ static void process_rc_file(cproc_t cp) struct cmdline_args { const char *uif_device; const char *bsl_device; + const char *fet_force_id; int mode; int want_jtag; int no_rc; @@ -188,8 +191,9 @@ static int parse_cmdline_args(int argc, char **argv, { int opt; const static struct option longopts[] = { - {"help", 0, 0, '?'}, - {"fet-list", 0, 0, 'L'}, + {"help", 0, 0, 'H'}, + {"fet-list", 0, 0, 'L'}, + {"fet-force-id", 1, 0, 'F'}, {NULL, 0, 0, 0} }; @@ -201,6 +205,14 @@ static int parse_cmdline_args(int argc, char **argv, fet_db_enum(show_fet_device, NULL); exit(0); + case 'F': + args->fet_force_id = optarg; + break; + + case 'H': + usage(argv[0]); + exit(0); + case 'R': args->mode |= MODE_RF2500; break; @@ -232,8 +244,7 @@ static int parse_cmdline_args(int argc, char **argv, break; case '?': - usage(argv[0]); - exit(0); + return -1; default: fprintf(stderr, "Invalid argument: %c\n" @@ -286,7 +297,8 @@ device_t setup_device(const struct cmdline_args *args, if (!args->want_jtag) flags |= FET_PROTO_SPYBIWIRE; - msp430_dev = fet_open(trans, flags, args->vcc_mv); + msp430_dev = fet_open(trans, flags, args->vcc_mv, + args->fet_force_id); } if (!msp430_dev) { diff --git a/mspdebug.man b/mspdebug.man index f83f9a1..3b22323 100644 --- a/mspdebug.man +++ b/mspdebug.man @@ -91,6 +91,10 @@ Display a brief help message and exit. .IP "\-\-fet\-list" Display a list of devices supported by the FET driver (the driver used for \fB\-R\fB and \fB\-u\fR operating modes). +.IP "\-\-fet\-force\-id \fIstring\fR" +When using a FET device, force the connected chip to be recognised by +MSPDebug as one of the given type during initialization. This overrides +the device ID returned by the FET. .SH COMMANDS MSPDebug can accept commands either through an interactive prompt, or non-interactively when specified on the command line. The supported