Allow VID:PID override for JLink probe

This commit is contained in:
Viktor P 2023-04-17 19:15:04 +03:00
parent d60a1039a0
commit 4100675a6b
3 changed files with 7 additions and 7 deletions

View File

@ -39,7 +39,7 @@ using namespace std;
// buffer capacity // buffer capacity
#define BUF_SIZE 2048 #define BUF_SIZE 2048
Jlink::Jlink(uint32_t clkHz, int8_t verbose):_base_freq(0), _min_div(0), Jlink::Jlink(uint32_t clkHz, int8_t verbose, int vid = VID, int pid = PID):_base_freq(0), _min_div(0),
jlink_write_ep(-1), jlink_read_ep(-1), jlink_interface(-1), jlink_write_ep(-1), jlink_read_ep(-1), jlink_interface(-1),
_verbose(verbose > 0), _debug(verbose > 1), _quiet(verbose < 0), _verbose(verbose > 0), _debug(verbose > 1), _quiet(verbose < 0),
_num_bits(0), _last_tms(0), _last_tdi(0), _num_bits(0), _last_tms(0), _last_tdi(0),
@ -50,7 +50,7 @@ Jlink::Jlink(uint32_t clkHz, int8_t verbose):_base_freq(0), _min_div(0),
throw std::runtime_error("libusb init failed\n"); throw std::runtime_error("libusb init failed\n");
// search for all compatible devices // search for all compatible devices
if (!jlink_scan_usb()) if (!jlink_scan_usb(vid,pid))
throw std::runtime_error("can't find compatible device"); throw std::runtime_error("can't find compatible device");
// get device capacity // get device capacity
@ -659,7 +659,7 @@ bool Jlink::jlink_search_interface(libusb_device *dev,
return true; return true;
} }
bool Jlink::jlink_scan_usb() bool Jlink::jlink_scan_usb(int vid, int pid)
{ {
libusb_device **dev_list; libusb_device **dev_list;
libusb_device *usb_dev; libusb_device *usb_dev;
@ -677,7 +677,7 @@ bool Jlink::jlink_scan_usb()
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (desc.idProduct != PID || desc.idVendor != VID) if (desc.idProduct != pid || desc.idVendor != vid)
continue; continue;
if (_verbose) if (_verbose)

View File

@ -24,7 +24,7 @@ class Jlink: public JtagInterface {
* \param[in] verbose: verbose level -1 quiet, 0 normal, * \param[in] verbose: verbose level -1 quiet, 0 normal,
* 1 verbose, 2 debug * 1 verbose, 2 debug
*/ */
Jlink(uint32_t clkHz, int8_t verbose); Jlink(uint32_t clkHz, int8_t verbose, int vid, int pid);
~Jlink(); ~Jlink();
@ -270,7 +270,7 @@ class Jlink: public JtagInterface {
* \brief iterate on all USB peripheral to find one JLink * \brief iterate on all USB peripheral to find one JLink
* \return false when failure, unable to open or no device found * \return false when failure, unable to open or no device found
*/ */
bool jlink_scan_usb(); bool jlink_scan_usb(int vid, int pid);
typedef struct { typedef struct {
libusb_device *usb_dev; libusb_device *usb_dev;

View File

@ -115,7 +115,7 @@ void Jtag::init_internal(const cable_t &cable, const string &dev, const string &
_jtag = new DirtyJtag(clkHZ, _verbose); _jtag = new DirtyJtag(clkHZ, _verbose);
break; break;
case MODE_JLINK: case MODE_JLINK:
_jtag = new Jlink(clkHZ, _verbose); _jtag = new Jlink(clkHZ, _verbose, cable.vid, cable.pid);
break; break;
case MODE_USBBLASTER: case MODE_USBBLASTER:
_jtag = new UsbBlaster(cable, firmware_path, _verbose); _jtag = new UsbBlaster(cable, firmware_path, _verbose);