flag out the only scsi specific code
[fw/stlink] / src / stlink-usb.c
index ff9ef71de7a4e6afc0b632342b473cc97826ff0b..52699614420b464eb095f0f3c264db2d39219e82 100644 (file)
@@ -116,7 +116,10 @@ ssize_t send_recv(struct stlink_libusb* handle, int terminate,
         if (submit_wait(handle, handle->rep_trans)) return -1;
         res = handle->rep_trans->actual_length;
     }
+    
     if ((handle->protocoll == 1) && terminate) {
+        fprintf(stderr, "This is never used....\n");
+        exit(EXIT_FAILURE);
         /* Read the SG reply */
         unsigned char sg_buf[13];
         libusb_fill_bulk_transfer
@@ -172,6 +175,7 @@ static int fill_command
     int i = 0;
     memset(cmd, 0, sizeof (sl->c_buf));
     if(slu->protocoll == 1) {
+        fprintf(stderr, "This is never used....\n");
         cmd[i++] = 'U';
         cmd[i++] = 'S';
         cmd[i++] = 'B';
@@ -604,47 +608,14 @@ stlink_t* stlink_open_usb(const int verbose) {
        goto on_error;
     }
     
-    count = libusb_get_device_list(slu->libusb_ctx, &devs);
-    if (count < 0) {
-        printf("libusb_get_device_list\n");
-        goto on_libusb_error;
-    }
-
-    for (i = 0; i < count; ++i) {
-        dev = devs[i];
-        slu->protocoll = is_stlink_device(dev, 0);
-        if (slu->protocoll > 0) break;
-    }
-    if (i == count) goto on_libusb_error;
-
-    if (libusb_open(dev, &(slu->usb_handle))) {
-        printf("libusb_open()\n");
-        goto on_libusb_error;
+    slu->usb_handle = libusb_open_device_with_vid_pid(slu->libusb_ctx, USB_ST_VID, USB_STLINK_32L_PID);
+    if (slu->usb_handle == NULL) {
+               // TODO - free usb context too...
+        free(slu);
+               fprintf(stderr, "Couldn't find any ST-Link/V2 devices");
+        return NULL;
     }
     
-    if (iSerial) {
-        unsigned char serial[256];
-        struct libusb_device_descriptor desc;
-        int r;
-
-        r = libusb_get_device_descriptor(dev, &desc);
-        if (r<0) {
-            printf("Can't get descriptor to match Iserial\n");
-            goto on_libusb_error;
-        }
-        r = libusb_get_string_descriptor_ascii
-            (slu->usb_handle, desc.iSerialNumber, serial, 256);
-        if (r<0) {
-            printf("Can't get Serialnumber to match Iserial\n");
-            goto on_libusb_error;
-        }
-        if (strcmp((char*)serial, iSerial)) {
-            printf("Mismatch in serial numbers, dev %s vs given %s\n",
-                   serial, iSerial);
-            goto on_libusb_error;
-        }
-    }
-
     if (libusb_kernel_driver_active(slu->usb_handle, 0) == 1) {
         int r;
         
@@ -685,11 +656,12 @@ stlink_t* stlink_open_usb(const int verbose) {
         printf("libusb_alloc_transfer\n");
         goto on_libusb_error;
     }
-
+    // TODO - could use the scanning techniq from stm8 code here...
     slu->ep_rep = 1 /* ep rep */ | LIBUSB_ENDPOINT_IN;
     slu->ep_req = 2 /* ep req */ | LIBUSB_ENDPOINT_OUT;
 
     slu->sg_transfer_idx = 0;
+    // TODO - never used at the moment, always CMD_SIZE
     slu->cmd_len = (slu->protocoll == 1)? STLINK_SG_SIZE: STLINK_CMD_SIZE;
 
     /* success */