diff --git a/README.md b/README.md index 34d0fb4..6ad5302 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ openFPGALoader -- a program to flash FPGA of positive --vid arg probe Vendor ID --pid arg probe Product ID - --cable-index arg probe index + --cable-index arg probe index (FTDI and cmsisDAP) --ftdi-serial arg FTDI chip serial number --ftdi-channel arg FTDI chip channel number (channels 0-3 map to A-D) diff --git a/src/cmsisDAP.cpp b/src/cmsisDAP.cpp index 4078e05..7900b2d 100644 --- a/src/cmsisDAP.cpp +++ b/src/cmsisDAP.cpp @@ -88,7 +88,7 @@ enum cmsisdap_status { DAP_ERROR = 0xff }; -CmsisDAP::CmsisDAP(int vid, int pid, uint8_t verbose):_verbose(verbose), +CmsisDAP::CmsisDAP(int vid, int pid, int index, uint8_t verbose):_verbose(verbose), _device_idx(0), _vid(vid), _pid(pid), _serial_number(L""), _dev(NULL), _num_tms(0), _is_connect(false) { @@ -121,18 +121,36 @@ CmsisDAP::CmsisDAP(int vid, int pid, uint8_t verbose):_verbose(verbose), throw std::runtime_error("No device found"); } /* more than one device: can't continue without more information */ - if (dev_found.size() > 1) { + if (dev_found.size() > 1 && index == -1) { hid_exit(); throw std::runtime_error( - "Error: more than one device. Please provides VID/PID"); + "Error: more than one device. Please provides VID/PID or cable-index"); + } + + /* if index check for if interface exist */ + if (index != -1) { + bool found = false; + for (size_t i = 0; i < dev_found.size(); i++) { + if (dev_found[i]->interface_number == index) { + found = true; + _device_idx = i; + break; + } + } + if (!found) { + hid_exit(); + throw std::runtime_error( + "Error: no compatible interface with index " + std::to_string(_device_idx)); + } } printInfo("Found " + std::to_string(dev_found.size()) + " compatible device:"); for (size_t i = 0; i < dev_found.size(); i++) { char val[256]; - snprintf(val, sizeof(val), "\t0x%04x 0x%04x %ls", + snprintf(val, sizeof(val), "\t0x%04x 0x%04x 0x%d %ls", dev_found[i]->vendor_id, dev_found[i]->product_id, + dev_found[i]->interface_number, dev_found[i]->product_string); printInfo(val); } diff --git a/src/cmsisDAP.hpp b/src/cmsisDAP.hpp index d034209..fc8e95b 100644 --- a/src/cmsisDAP.hpp +++ b/src/cmsisDAP.hpp @@ -21,9 +21,10 @@ class CmsisDAP: public JtagInterface { * else search for a compatible device * \param[in] vid: vendor id * \param[in] pid: product id + * \param[in] index: interface number * \param[in] verbose: verbose level 0 normal, 1 verbose */ - CmsisDAP(const int vid, const int pid, uint8_t verbose); + CmsisDAP(const int vid, const int pid, int index, uint8_t verbose); ~CmsisDAP(); diff --git a/src/ftdipp_mpsse.cpp b/src/ftdipp_mpsse.cpp index c65ec66..e7cd630 100644 --- a/src/ftdipp_mpsse.cpp +++ b/src/ftdipp_mpsse.cpp @@ -45,7 +45,10 @@ FTDIpp_MPSSE::FTDIpp_MPSSE(const mpsse_bit_config &cable, const string &dev, } else { _vid = cable.vid; _pid = cable.pid; - _index = cable.index; + if (cable.index == -1) + _index = 0; + else + _index = cable.index; } open_device(serial, 115200); diff --git a/src/jtag.cpp b/src/jtag.cpp index a31cf07..914b9c4 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -120,7 +120,8 @@ void Jtag::init_internal(cable_t &cable, const string &dev, const string &serial break; case MODE_CMSISDAP: #ifdef ENABLE_CMSISDAP - _jtag = new CmsisDAP(cable.config.vid, cable.config.pid, _verbose); + _jtag = new CmsisDAP(cable.config.vid, cable.config.pid, + cable.config.index, _verbose); break; #else std::cerr << "Jtag: support for cmsisdap was not enabled at compile time" << std::endl; diff --git a/src/main.cpp b/src/main.cpp index b153215..155396b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,7 +67,7 @@ struct arguments { int16_t altsetting; uint16_t vid; uint16_t pid; - uint16_t cable_index; + int16_t cable_index; string ip_adr; uint32_t protect_flash; bool unprotect_flash; @@ -98,7 +98,7 @@ int main(int argc, char **argv) /* command line args. */ struct arguments args = {0, false, false, false, 0, "", "", "-", "", -1, 0, false, "-", false, false, false, false, Device::PRG_NONE, false, - false, false, "", "", "", -1, 0, false, -1, 0, 0, 0, "127.0.0.1", + false, false, "", "", "", -1, 0, false, -1, 0, 0, -1, "127.0.0.1", 0, false, "", false, false, /* xvc server */ false, 3721, "-", @@ -652,7 +652,7 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p cxxopts::value(args->invert_read_edge)) ("vid", "probe Vendor ID", cxxopts::value(args->vid)) ("pid", "probe Product ID", cxxopts::value(args->pid)) - ("cable-index", "probe index", cxxopts::value(args->cable_index)) + ("cable-index", "probe index (FTDI and cmsisDAP)", cxxopts::value(args->cable_index)) ("ftdi-serial", "FTDI chip serial number", cxxopts::value(args->ftdi_serial)) ("ftdi-channel", "FTDI chip channel number (channels 0-3 map to A-D)", cxxopts::value(args->ftdi_channel))