diff --git a/drivers/bsl.c b/drivers/bsl.c index c2fa678..0d4c11c 100644 --- a/drivers/bsl.c +++ b/drivers/bsl.c @@ -364,7 +364,8 @@ static device_t bsl_open(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) dev->serial = comport_open(args->path, 460800); else - dev->serial = ti3410_open(args->path, args->requested_serial); + dev->serial = ti3410_open(args->path, args->requested_serial, + (args->flags & DEVICE_FLAG_HAS_VID_PID), args->vid, args->pid); if (!dev->serial) { free(dev); diff --git a/drivers/device.h b/drivers/device.h index 2ac099d..14c0654 100644 --- a/drivers/device.h +++ b/drivers/device.h @@ -75,6 +75,7 @@ struct device_breakpoint { #define DEVICE_FLAG_DO_FWUPDATE 0x10 #define DEVICE_FLAG_SKIP_CLOSE 0x20 #define DEVICE_FLAG_BSL_NME 0x40 /* BSL no-mass-erase */ +#define DEVICE_FLAG_HAS_VID_PID 0x80 struct device_args { int flags; @@ -88,6 +89,7 @@ struct device_args { int bsl_gpio_rts; int bsl_gpio_dtr; uint8_t bsl_entry_password[32]; + uint16_t vid, pid; }; struct device_class { diff --git a/drivers/fet.c b/drivers/fet.c index 51a03f2..0309b11 100644 --- a/drivers/fet.c +++ b/drivers/fet.c @@ -44,9 +44,11 @@ static device_t fet_open_rf2500(const struct device_args *args) } #if defined(__APPLE__) - trans = rf2500hidapi_open(args->path, args->requested_serial); + trans = rf2500hidapi_open(args->path, args->requested_serial, + (args->flags & DEVICE_FLAG_HAS_VID_PID), args->vid, args->pid); #else - trans = rf2500_open(args->path, args->requested_serial); + trans = rf2500_open(args->path, args->requested_serial, + (args->flags & DEVICE_FLAG_HAS_VID_PID), args->vid, args->pid); #endif if (!trans) return NULL; @@ -79,8 +81,9 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) trans = comport_open(args->path, 115200); else - trans = cdc_acm_open(args->path, args->requested_serial, - 115200, 0x15ba, 0x0100); + trans = cdc_acm_open(args->path, args->requested_serial, 115200, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->vid : 0x15ba, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->pid : 0x0100); if (!trans) return NULL; @@ -100,9 +103,9 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) trans = comport_open(args->path, 115200); else - trans = cdc_acm_open(args->path, - args->requested_serial, - 115200, 0x15ba, 0x0100); + trans = cdc_acm_open(args->path, args->requested_serial, 115200, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->vid : 0x15ba, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->pid : 0x0100); if (!trans) return NULL; @@ -141,8 +144,9 @@ static device_t fet_open_olimex(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) trans = comport_open(args->path, 115200); else - trans = cdc_acm_open(args->path, args->requested_serial, - 115200, 0x15ba, 0x0031); + trans = cdc_acm_open(args->path, args->requested_serial, 115200, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->vid : 0x15ba, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->pid : 0x0031); if (!trans) return NULL; @@ -177,8 +181,9 @@ static device_t fet_open_olimex_v1(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) trans = comport_open(args->path, 500000); else - trans = cp210x_open(args->path, args->requested_serial, - 500000, 0x15ba, 0x0002); + trans = cp210x_open(args->path, args->requested_serial, 500000, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->vid : 0x15ba, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->pid : 0x0002); if (!trans) return NULL; @@ -213,7 +218,9 @@ static device_t fet_open_olimex_iso(const struct device_args *args) trans = comport_open(args->path, 200000); else trans = ftdi_open(args->path, args->requested_serial, - 0x15ba, 0x0008, 200000); + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->vid : 0x15ba, + (args->flags & DEVICE_FLAG_HAS_VID_PID) ? args->pid : 0x0008, + 200000); if (!trans) return NULL; @@ -248,7 +255,8 @@ static device_t fet_open_uif(const struct device_args *args) if (args->flags & DEVICE_FLAG_TTY) trans = comport_open(args->path, 460800); else - trans = ti3410_open(args->path, args->requested_serial); + trans = ti3410_open(args->path, args->requested_serial, + (args->flags & DEVICE_FLAG_HAS_VID_PID), args->vid, args->pid); if (!trans) return NULL; diff --git a/mspdebug.man b/mspdebug.man index 3e23d60..c75e2bd 100644 --- a/mspdebug.man +++ b/mspdebug.man @@ -52,6 +52,10 @@ section \fBDRIVERS\fR below for details. .IP "\-U \fIbus\fR:\fIdevice\fR" Specify a particular USB device to connect to. Without this option, the first device of the appropriate type is opened. +.IP "\-V \fIvid\fR:\fIpid\fR" +Specify a VID and PID of the USB device to connect to, or override the +default VID and PID. Some drives, such as \fBmehfet\fR, require this option, +while others have a default VID and PID which can be overridden. .IP "\-s \fIserial\fR" Specify a particular USB device serial number to connect to. Use this option to distinguish between multiple devices of the same type. diff --git a/transport/rf2500.c b/transport/rf2500.c index f0544ae..54301d6 100644 --- a/transport/rf2500.c +++ b/transport/rf2500.c @@ -228,7 +228,8 @@ static const struct transport_class rf2500_transport = { .set_modem = usbtr_set_modem }; -transport_t rf2500_open(const char *devpath, const char *requested_serial) +transport_t rf2500_open(const char *devpath, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid) { struct rf2500_transport *tr = malloc(sizeof(*tr)); struct usb_device *dev; @@ -248,8 +249,9 @@ transport_t rf2500_open(const char *devpath, const char *requested_serial) if (devpath) dev = usbutil_find_by_loc(devpath); else - dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT, - requested_serial); + dev = usbutil_find_by_id(has_vid_pid ? vid : USB_FET_VENDOR, + has_vid_pid ? pid : USB_FET_PRODUCT, + requested_serial); if (!dev) { free(tr); diff --git a/transport/rf2500.h b/transport/rf2500.h index f523071..e637336 100644 --- a/transport/rf2500.h +++ b/transport/rf2500.h @@ -27,7 +27,9 @@ * * A particular device may be specified in bus:dev form. */ -transport_t rf2500_open(const char *dev_path, const char *requested_serial); -transport_t rf2500hidapi_open(const char *dev_path, const char *requested_serial); +transport_t rf2500_open(const char *dev_path, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid); +transport_t rf2500hidapi_open(const char *dev_path, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid); #endif diff --git a/transport/rf2500hidapi.c b/transport/rf2500hidapi.c index d971f6c..0902ea7 100644 --- a/transport/rf2500hidapi.c +++ b/transport/rf2500hidapi.c @@ -161,7 +161,8 @@ static const wchar_t * get_wc(const char *c) return wc; } -transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial) +transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid) { struct rf2500_transport *tr = malloc(sizeof(*tr)); hid_device *handle; @@ -186,7 +187,9 @@ transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial) } else { wc_serial = NULL; } - handle = hid_open(USB_FET_VENDOR, USB_FET_PRODUCT, wc_serial); + handle = hid_open(has_vid_pid ? vid : USB_FET_VENDOR, + has_vid_pid ? pid : USB_FET_PRODUCT, wc_serial); + if ( wc_serial ) { free((wchar_t *)wc_serial); } diff --git a/transport/ti3410.c b/transport/ti3410.c index b96fed8..de51388 100644 --- a/transport/ti3410.c +++ b/transport/ti3410.c @@ -559,7 +559,8 @@ static const struct transport_class ti3410_transport = { .set_modem = ti3410_set_modem }; -transport_t ti3410_open(const char *devpath, const char *requested_serial) +transport_t ti3410_open(const char *devpath, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid) { struct ti3410_transport *tr = malloc(sizeof(*tr)); struct usb_device *dev; @@ -578,8 +579,9 @@ transport_t ti3410_open(const char *devpath, const char *requested_serial) if (devpath) dev = usbutil_find_by_loc(devpath); else - dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT, - requested_serial); + dev = usbutil_find_by_id(has_vid_pid ? vid : USB_FET_VENDOR, + has_vid_pid ? pid : USB_FET_PRODUCT, + requested_serial); if (!dev) { free(tr); diff --git a/transport/ti3410.h b/transport/ti3410.h index 8ef879e..f57ef21 100644 --- a/transport/ti3410.h +++ b/transport/ti3410.h @@ -24,6 +24,8 @@ /* This function is for opening an eZ430-F2013 or FET430UIF device via * libusb. */ -transport_t ti3410_open(const char *dev_path, const char *requested_serial); +transport_t ti3410_open(const char *dev_path, const char *requested_serial, + int has_vid_pid, uint16_t vid, uint16_t pid); + #endif diff --git a/ui/main.c b/ui/main.c index 7a914ac..01c1738 100644 --- a/ui/main.c +++ b/ui/main.c @@ -114,6 +114,9 @@ static void usage(const char *progname) " Connect via the given tty device, rather than USB.\n" " -U bus:dev\n" " Specify a particular USB device to connect to.\n" +" -V vid:pid\n" +" Specify a particular vid:pid par of a USB to connect to, instead of\n" +" a driver-specific default.\n" " -s serial\n" " Specify a particular device serial number to connect to.\n" " -j\n" @@ -328,7 +331,7 @@ static int parse_cmdline_args(int argc, char **argv, int opt; int want_usb = 0; - while ((opt = getopt_long(argc, argv, "d:jv:nU:s:qC:", + while ((opt = getopt_long(argc, argv, "d:jv:nUV:s:qC:", longopts, NULL)) >= 0) switch (opt) { case 'C': @@ -398,6 +401,18 @@ static int parse_cmdline_args(int argc, char **argv, want_usb = 1; break; + case 'V': + /* optarg is in "vid:pid" format, which we now need to parse */ + if (sscanf(optarg, "%04hx:%04hx", &args->devarg.vid, &args->devarg.pid) == 2) { + args->devarg.flags |= DEVICE_FLAG_HAS_VID_PID; + want_usb = 1; + } else { + printc("Invalid -V option specified: %s." + "Format should be ':'\n", optarg); + exit(1); + } + break; + case 's': args->devarg.requested_serial = optarg; break;