diff --git a/Makefile b/Makefile index 4c3b44b..a6545e8 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ LDFLAGS=-lstlink -lusb-1.0 -lsgutils2 -L. LIBRARY=libstlink.a -all: $(LIBRARY) test_usb test_sg +all: $(LIBRARY) flash gdbserver test_usb test_sg $(LIBRARY): $(OBJS_LIB) @echo "objs are $(OBJS_LIB)" @@ -42,5 +42,15 @@ clean: rm -rf $(LIBRARY) rm -rf test_usb* rm -rf test_sg* + +distclean: clean + $(MAKE) -C flash clean + $(MAKE) -C gdbserver clean -.PHONY: clean all +flash: + $(MAKE) -C flash + +gdbserver: + $(MAKE) -C gdbserver + +.PHONY: clean all flash gdbserver diff --git a/example/blink_flash/Makefile b/example/blink_flash/Makefile index d058390..7776471 100644 --- a/example/blink_flash/Makefile +++ b/example/blink_flash/Makefile @@ -5,7 +5,18 @@ CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy CFLAGS=-O2 -mlittle-endian -mthumb -CFLAGS+=-mcpu=cortex-m3 -ffreestanding -nostdlib -nostdinc + +CFLAGS=-g -O2 -mlittle-endian -mthumb +ifeq ($(CONFIG_STM32L_DISCOVERY), 1) + CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY +else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1) + CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32VL_DISCOVERY=1 +else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1) + CFLAGS+=-mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1 +else +$(error "must specify CONFIG_ for board!") +endif + CFLAGS+=-ffreestanding -nostdlib -nostdinc # to run from FLASH CFLAGS+=-Wl,-T,stm32_flash.ld diff --git a/flash/main.c b/flash/main.c index 3b9416d..a443f95 100644 --- a/flash/main.c +++ b/flash/main.c @@ -17,6 +17,11 @@ struct opts size_t size; }; +static void usage(void) +{ + puts("stlinkv1 command line: ./flash {read|write} /dev/sgX path addr "); + puts("stlinkv2 command line: ./flash {read|write} path addr "); +} static int get_opts(struct opts* o, int ac, char** av) { @@ -75,6 +80,7 @@ int main(int ac, char** av) if (get_opts(&o, ac - 1, av + 1) == -1) { printf("invalid command line\n"); + usage(); goto on_error; } @@ -86,7 +92,7 @@ int main(int ac, char** av) } else /* stlinkv2 */ { - sl = stlink_open_usb(NULL, 10); + sl = stlink_open_usb(10); if (sl == NULL) goto on_error; }