This will let people with Macintosh OS/X computers compile and use stlink with STLink/V2 devices, as libsg3 is not available for that platform.
-
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
VPATH=src
-SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c
+SOURCES_LIB=stlink-common.c stlink-usb.c
OBJS_LIB=$(SOURCES_LIB:.c=.o)
+TEST_PROGRAMS=test_usb
+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
-CFLAGS+=-DCONFIG_USE_LIBSG
-CFLAGS+=-DDEBUG
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
+CFLAGS+=-DDEBUG=1
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra
-LDFLAGS=-lstlink -lusb-1.0 -lsgutils2 -L.
LIBRARY=libstlink.a
-all: $(LIBRARY) flash gdbserver test_usb test_sg
+all: $(LIBRARY) flash gdbserver $(TEST_PROGRAMS)
$(LIBRARY): $(OBJS_LIB)
@echo "objs are $(OBJS_LIB)"
$(MAKE) -C gdbserver clean
flash:
- $(MAKE) -C flash
+ $(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)"
gdbserver:
$(MAKE) -C gdbserver
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
CC=gcc
CFLAGS+=-g
-CFLAGS+=-DCONFIG_USE_LIBUSB
-CFLAGS+=-DCONFIG_USE_LIBSG
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
CFLAGS+=-DDEBUG
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra
CFLAGS+=-I../src
-LDFLAGS=-L.. -lstlink -lusb-1.0 -lsgutils2
+LDFLAGS=-lusb-1.0 -L.. -lstlink
+
+ifeq ($(CONFIG_USE_LIBSG),)
+CONFIG_USE_LIBSG=1
+endif
+
+ifneq ($(CONFIG_USE_LIBSG),0)
+CFLAGS+=-DCONFIG_USE_LIBSG=1
+LDFLAGS+=-lsgutils2
+endif
SRCS=main.c
OBJS=$(SRCS:.c=.o)
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 */
{
+# make ... for both libusb and libsg
+#
+# make CONFIG_USE_LIBSG=0 ...
+# for just libusb
+#
PRG := st-util
OBJS = gdb-remote.o gdb-server.o
CFLAGS+=-g -Wall -Werror -std=gnu99 -I../src
-CFLAGS+=-DCONFIG_USE_LIBUSB
-CFLAGS+=-DCONFIG_USE_LIBSG
-LIBS := -lstlink -lusb-1.0 -lsgutils2
-LDFLAGS+=$(LIBS) -L..
+CFLAGS+=-DCONFIG_USE_LIBUSB=1
+LDFLAGS=-lusb-1.0 -L.. -lstlink
+ifeq ($(CONFIG_USE_LIBSG),)
+CONFIG_USE_LIBSG=1
+endif
+
+ifneq ($(CONFIG_USE_LIBSG),0)
+CFLAGS+=-DCONFIG_USE_LIBSG=1
+LDFLAGS+=-lsgutils2
+endif
all: $(PRG)
switch(argc) {
- default: {
- fprintf(stderr, HelpStr, NULL);
- return 1;
- }
-
case 3 : {
//sl = stlink_quirk_open(argv[2], 0);
- // FIXME - hardcoded to usb....
- sl = stlink_open_usb(10);
+ // FIXME - hardcoded to usb....
+ sl = stlink_open_usb(10);
if(sl == NULL) return 1;
break;
}
}
}
+#if CONFIG_USE_LIBSG
case 1 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
const int DevNumMax = 99;
int ExistDevCount = 0;
}
break;
}
+#endif
+
+ default: {
+ fprintf(stderr, HelpStr, NULL);
+ return 1;
+ }
}
- if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
- stlink_exit_dfu_mode(sl);
- }
+ if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
+ stlink_exit_dfu_mode(sl);
+ }
if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
stlink_enter_swd_mode(sl);
#include <sys/stat.h>
#include <sys/mman.h>
+#include "stlink-common.h"
+
+#if CONFIG_USE_LIBSG
// sgutils2 (apt-get install libsgutils2-dev)
#include <scsi/sg_lib.h>
#include <scsi/sg_pt.h>
-
-#include "stlink-common.h"
#include "stlink-sg.h"
+#endif
// Suspends execution of the calling process for
#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[]) {
//fflush(stderr); fflush(stdout);
return EXIT_SUCCESS;
-}
\ No newline at end of file
+}