-# make ... for both libusb and libsg
-#
-# make CONFIG_USE_LIBSG=0 ...
-# for just libusb
-#
+# make ... for both stlink v1 and stlink v2 support
+##
VPATH=src
-SOURCES_LIB=stlink-common.c stlink-usb.c
+SOURCES_LIB=stlink-common.c stlink-usb.c #stlink-sg.c
OBJS_LIB=$(SOURCES_LIB:.c=.o)
-TEST_PROGRAMS=test_usb
+TEST_PROGRAMS=test_usb #test_sg
LDFLAGS=-lusb-1.0 -L. -lstlink
-ifeq ($(CONFIG_USE_LIBSG),)
-CONFIG_USE_LIBSG=1
-endif
-
-ifneq ($(CONFIG_USE_LIBSG),0)
-SOURCES_LIB+=stlink-sg.c
-CFLAGS+=-DCONFIG_USE_LIBSG=1
-LDFLAGS+=-lsgutils2
-TEST_PROGRAMS+=test_sg
-endif
-
CFLAGS+=-g
-CFLAGS+=-DCONFIG_USE_LIBUSB=1
CFLAGS+=-DDEBUG=1
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra
$(MAKE) -C gdbserver clean
flash:
- $(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)"
+ $(MAKE) -C flash
gdbserver:
$(MAKE) -C gdbserver
if (o.devname != NULL) /* stlinkv1 */
{
-#if CONFIG_USE_LIBSG
static const int scsi_verbose = 2;
sl = stlink_quirk_open(o.devname, scsi_verbose);
if (sl == NULL) goto on_error;
-#else
- printf("not compiled for use with STLink/V1");
- goto on_error;
-#endif
}
else /* stlinkv2 */
{
if(sl == NULL) return 1;
break;
case 1:
-#if (CONFIG_USE_LIBSG == 1)
if (strlen(state.devicename) == 0) {
const int DevNumMax = 99;
int ExistDevCount = 0;
sl = stlink_quirk_open(state.devicename, state.logging_level);
}
break;
-#else
- fprintf(stderr, "Support for stlink v1 disabled at build time...\n");
- fprintf(stderr, "Perhaps you're on OSX, and we haven't finished removing the libsg deps?\n");
- exit(EXIT_FAILURE);
-#endif
}
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
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;
#define STLINK_SG_SIZE 31
#define STLINK_CMD_SIZE 16
-#if defined(CONFIG_USE_LIBUSB)
struct stlink_libusb {
libusb_context* libusb_ctx;
libusb_device_handle* usb_handle;
unsigned int sg_transfer_idx;
unsigned int cmd_len;
};
-#else
-#error "it's all bad!"
- struct stlink_libusb {};
-#endif
-
stlink_t* stlink_open_usb(const int verbose);
#include <stdio.h>
#include <stdlib.h>
-#if CONFIG_USE_LIBSG
-#include <scsi/sg_lib.h>
-#include <scsi/sg_pt.h>
-#endif
#include "stlink-common.h"
int main(int argc, char *argv[]) {