cmsisDAP: allows to select interface number

This commit is contained in:
Gwenhael Goavec-Merou 2022-08-29 20:58:51 +02:00
parent 61e959f93d
commit 27309d4931
6 changed files with 34 additions and 11 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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<bool>(args->invert_read_edge))
("vid", "probe Vendor ID", cxxopts::value<uint16_t>(args->vid))
("pid", "probe Product ID", cxxopts::value<uint16_t>(args->pid))
("cable-index", "probe index", cxxopts::value<uint16_t>(args->cable_index))
("cable-index", "probe index (FTDI and cmsisDAP)", cxxopts::value<int16_t>(args->cable_index))
("ftdi-serial", "FTDI chip serial number", cxxopts::value<string>(args->ftdi_serial))
("ftdi-channel", "FTDI chip channel number (channels 0-3 map to A-D)", cxxopts::value<int>(args->ftdi_channel))