#include <sys/types.h>
#include <libusb.h>
#include <errno.h>
+#include <unistd.h>
#include "stlink-common.h"
#include "stlink-usb.h"
int i = fill_command(sl, SG_DXFER_FROM_DEV, rep_len);
cmd[i++] = STLINK_DEBUG_COMMAND;
- cmd[i++] = STLINK_DEBUG_HARDRESET;
- cmd[i++] = 0x2;
+ cmd[i++] = STLINK_DEBUG_RESETSYS;
size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len);
if (size == -1) {
};
-stlink_t* stlink_open_usb(const int verbose, int reset) {
+stlink_t* stlink_open_usb(const int verbose, int reset, char *p_usb_iserial) {
stlink_t* sl = NULL;
struct stlink_libusb* slu = NULL;
int error = -1;
sl->backend_data = slu;
sl->core_stat = STLINK_CORE_STAT_UNKNOWN;
-
if (libusb_init(&(slu->libusb_ctx))) {
WLOG("failed to init libusb context, wrong version of libraries?\n");
goto on_error;
if (desc.idVendor!=USB_ST_VID) continue;
if (devBus && devAddr)
if ((libusb_get_bus_number(list[cnt])!=devBus) || (libusb_get_device_address(list[cnt])!=devAddr)) continue;
- if ( (desc.idProduct == USB_STLINK_32L_PID) || (desc.idProduct == USB_STLINK_NUCLEO_PID) ) break;
+ if ( (desc.idProduct == USB_STLINK_32L_PID) || (desc.idProduct == USB_STLINK_NUCLEO_PID) ){
+ if ((p_usb_iserial != NULL)){
+ unsigned char buffer[13];
+ struct libusb_device_handle* handle;
+ libusb_open(list[cnt], &handle);
+ libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buffer, 13);
+ libusb_close(handle);
+ if (memcmp(p_usb_iserial,&buffer,12) == 0){
+ break;
+ }else{
+ continue;
+ }
+ }else{
+ break;
+ }
+ }
if (desc.idProduct == USB_STLINK_PID) {
slu->protocoll = 1;
break;
if (reset) {
stlink_reset(sl);
+ usleep(10000);
}
stlink_version(sl);
error = stlink_load_device_params(sl);