#include <stdlib.h>
#include <string.h>
#include <stdint.h>
-#include <time.h>
+#include <sys/time.h>
#include <sys/types.h>
-#include <libusb-1.0/libusb.h>
+#include <libusb.h>
#include "stlink-common.h"
#include "stlink-usb.h"
#define WLOG(format, args...) ugly_log(UWARN, LOG_TAG, format, ## args)
#define fatal(format, args...) ugly_log(UFATAL, LOG_TAG, format, ## args)
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
+ } while (0)
+#endif
enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80};
volatile unsigned long flags;
};
-static void on_trans_done(struct libusb_transfer * trans) {
+static void LIBUSB_CALL on_trans_done(struct libusb_transfer * trans) {
struct trans_ctx * const ctx = trans->user_data;
if (trans->status != LIBUSB_TRANSFER_COMPLETED)
}
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
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';
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...
- WLOG("Couldn't find any ST-Link/V2 devices");
- goto on_error;
+ slu->usb_handle = libusb_open_device_with_vid_pid(slu->libusb_ctx, USB_ST_VID, USB_STLINK_PID);
+ if (slu->usb_handle == NULL) {
+ WLOG("Couldn't find any ST-Link/V2 devices");
+ goto on_error;
+ }
+ slu->protocoll = 1;
}
-
+
if (libusb_kernel_driver_active(slu->usb_handle, 0) == 1) {
int r;