diff --git a/examples/Makefile.rules b/examples/Makefile.rules new file mode 100644 index 0000000..7c4a31c --- /dev/null +++ b/examples/Makefile.rules @@ -0,0 +1,196 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## Copyright (C) 2010 Piotr Esden-Tempski +## Copyright (C) 2013 Frantisek Burian +## +## This library is free software: you can redistribute it and/or modify +## it under the terms of the GNU Lesser General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public License +## along with this library. If not, see . +## + +# Be silent per default, but 'make V=1' will show all compiler calls. +ifneq ($(V),1) +Q := @ +NULL := 2>/dev/null +endif + + +PREFIX ?= arm-none-eabi + +CC = $(PREFIX)-gcc +CPP = $(PREFIX)-g++ +LD = $(PREFIX)-gcc +OBJCOPY = $(PREFIX)-objcopy +OBJDUMP = $(PREFIX)-objdump +GDB = $(PREFIX)-gdb +STFLASH = $(shell which st-flash) + +LDSCRIPT ?= $(BINARY).ld + +OBJS += $(BINARY).o + +TOOLCHAIN_DIR ?= ../../../../../libopencm3 +ifeq ($(wildcard ../../../../../libopencm3/lib/lib$(LIBNAME).a),) +ifneq ($(strip $(shell which $(CC))),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +endif +else +ifeq ($(V),1) +$(info Building the example in the source directory. Using local library!) +endif +endif + + +INCLUDE_DIR = $(TOOLCHAIN_DIR)/include +LIB_DIR = $(TOOLCHAIN_DIR)/lib +SCRIPT_DIR = $(TOOLCHAIN_DIR)/share/libopencm3/scripts + +ifneq ($(OPENCM3_DIR),) +INCLUDE_DIR = $(OPENCM3_DIR)/include +LIB_DIR = $(OPENCM3_DIR)/lib +SCRIPT_DIR = $(OPENCM3_DIR)/scripts +endif + + + +# C flags + +CFLAGS += -Os -g $(ARCH_FLAGS) -MD $(DEFS) +CFLAGS += -Wall -Wextra -Wimplicit-function-declaration +CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes +CFLAGS += -Wundef -Wshadow -fno-common +CFLAGS += -I$(INCLUDE_DIR) + +# C++ flags + +CPPFLAGS += -Os -g $(ARCH_FLAGS) -MD $(DEFS) +CPPFLAGS += -Wall -Wextra -Wimplicit-function-declaration +CPPFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes +CPPFLAGS += -Wundef -Wshadow -fno-common +CPPFLAGS += -I$(INCLUDE_DIR) + +# Linker flags + +LDFLAGS += --static -nostartfiles $(ARCH_FLAGS) -l$(LIBNAME) +LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +LDFLAGS += -Wl,--gc-sections +LDFLAGS += -L$(LIB_DIR) +LDFLAGS += -T$(LDSCRIPT) +ifeq ($(V),1) +LDFLAGS += -Wl,--print-gc-sections +endif + + + + +.SUFFIXES: .elf .bin .hex .srec .list .images +.SECONDEXPANSION: +.SECONDARY: + +all: images + +images: $(BINARY).images +flash: $(BINARY).flash + +%.images: %.bin %.hex %.srec %.list + @#printf "*** $* images generated ***\n" + +%.bin: %.elf + @#printf " OBJCOPY $(*).bin\n" + $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin + +%.hex: %.elf + @#printf " OBJCOPY $(*).hex\n" + $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex + +%.srec: %.elf + @#printf " OBJCOPY $(*).srec\n" + $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec + +%.list: %.elf + @#printf " OBJDUMP $(*).list\n" + $(Q)$(OBJDUMP) -S $(*).elf > $(*).list + +%.elf: $(OBJS) $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a + @#printf " LD $(*).elf\n" + $(Q)$(LD) -o $(*).elf $(OBJS) $(LDFLAGS) + +%.o: %.c + @#printf " CC $(*).c\n" + $(Q)$(CC) $(CFLAGS) -o $(*).o -c $(*).c + +%.o: %.cpp + @#printf " CPP $(*).cpp\n" + $(Q)$(CPP) $(CPPFLAGS) -o $(*).o -c $(*).cpp + +clean: + @#printf " CLEAN\n" + $(Q)rm -f *.o + $(Q)rm -f *.d + $(Q)rm -f *.elf + $(Q)rm -f *.bin + $(Q)rm -f *.hex + $(Q)rm -f *.srec + $(Q)rm -f *.list + +%.stlink-flash: %.bin + @printf " FLASH $<\n" + $(Q)$(STFLASH) write $(*).bin 0x8000000 + +ifeq ($(STLINK_PORT),) +ifeq ($(BMP_PORT),) +ifeq ($(OOCD_SERIAL),) +%.flash: %.hex + @printf " FLASH $<\n" + @# IMPORTANT: Don't use "resume", only "reset" will work correctly! + $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ + -f board/$(OOCD_BOARD).cfg \ + -c "init" -c "reset init" \ + -c "stm32f1x mass_erase 0" \ + -c "flash write_image $(*).hex" \ + -c "reset" \ + -c "shutdown" $(NULL) +else +%.flash: %.hex + @printf " FLASH $<\n" + @# IMPORTANT: Don't use "resume", only "reset" will work correctly! + $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ + -f board/$(OOCD_BOARD).cfg \ + -c "ft2232_serial $(OOCD_SERIAL)" \ + -c "init" -c "reset init" \ + -c "stm32f1x mass_erase 0" \ + -c "flash write_image $(*).hex" \ + -c "reset" \ + -c "shutdown" $(NULL) +endif +else +%.flash: %.elf + @printf " GDB $(*).elf (flash)\n" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(BMP_PORT)' \ + -x $(SCRIPT_DIR)/black_magic_probe_flash.scr \ + $(*).elf +endif +else +%.flash: %.elf + @printf " GDB $(*).elf (flash)\n" + $(Q)$(GDB) --batch \ + -ex 'target extended-remote $(STLINK_PORT)' \ + -x $(SCRIPT_DIR)/stlink_flash.scr \ + $(*).elf +endif + +.PHONY: images clean + +-include $(OBJS:.o=.d) \ No newline at end of file diff --git a/examples/stm32/f0/Makefile.include b/examples/stm32/f0/Makefile.include index c5581ad..3e3fded 100644 --- a/examples/stm32/f0/Makefile.include +++ b/examples/stm32/f0/Makefile.include @@ -18,151 +18,26 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -#PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb +LIBNAME = opencm3_stm32f0 +DEFS = -DSTM32F0 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard ../../../../../libopencm3/lib/libopencm3_stm32f0.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m0 -msoft-float -ARCH_FLAGS = -mthumb -mcpu=cortex-m0 -msoft-float -CFLAGS += -Os -g \ - -Wall -Wextra -Wimplicit-function-declaration \ - -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \ - -Wundef -Wshadow \ - -I$(TOOLCHAIN_DIR)/include \ - -fno-common $(ARCH_FLAGS) -MD -DSTM32F0 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ - -L$(TOOLCHAIN_DIR)/lib \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - $(ARCH_FLAGS) -mfix-cortex-m3-ldrd - -CFLAGS += -I$(TOOLCHAIN_DIR)/include -LDFLAGS += -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib/stm32/f0 -SCRIPT_DIR = $(TOOLCHAIN_DIR)/share - -OBJS += $(BINARY).o +################################################################################ +# OpenOCD specific variables OOCD ?= openocd OOCD_INTERFACE ?= flossjtag OOCD_BOARD ?= olimex_stm32_h103 -# Black magic probe specific variables + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= -# texane/stlink can be used by uncommenting this... -# or defining it in your own makefiles -#STLINK_PORT ?= :4242 +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: - -all: images - -images: $(BINARY).images -flash: $(BINARY).flash - -%.images: %.bin %.hex %.srec %.list - @#echo "*** $* images generated ***" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f0.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f0 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -ifeq ($(STLINK_PORT),) -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "stm32l1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32l1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @echo " GDB $(*).elf (flash)" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif -else -%.flash: %.elf - @echo " GDB $(*).elf (flash)" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(STLINK_PORT)' \ - -x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) +include ../../../../Makefile.rules \ No newline at end of file diff --git a/examples/stm32/f1/Makefile.include b/examples/stm32/f1/Makefile.include index 919d918..942ae9b 100644 --- a/examples/stm32/f1/Makefile.include +++ b/examples/stm32/f1/Makefile.include @@ -18,155 +18,26 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -#PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb +LIBNAME = opencm3_stm32f1 +DEFS = -DSTM32F1 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f1.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd -ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -CFLAGS += -Os -g \ - -Wall -Wextra -Wimplicit-function-declaration \ - -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \ - -Wundef -Wshadow \ - -I$(TOOLCHAIN_DIR)/include \ - -fno-common $(ARCH_FLAGS) -MD -DSTM32F1 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ - -L$(TOOLCHAIN_DIR)/lib \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - $(ARCH_FLAGS) -mfix-cortex-m3-ldrd - -ifneq ($(OPENCM3_DIR),) -CFLAGS += -I$(OPENCM3_DIR)/include -LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/f1 -SCRIPT_DIR = $(OPENCM3_DIR)/share -else -SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share -endif - -OBJS += $(BINARY).o +################################################################################ +# OpenOCD specific variables OOCD ?= openocd OOCD_INTERFACE ?= flossjtag OOCD_BOARD ?= olimex_stm32_h103 -# Black magic probe specific variables + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= -# texane/stlink can be used by uncommenting this... -# or defining it in your own makefiles -#STLINK_PORT ?= :4242 +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: - -all: images - -images: $(BINARY).images -flash: $(BINARY).flash - -%.images: %.bin %.hex %.srec %.list - @#printf "*** $* images generated ***\n" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f1.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f1 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -ifeq ($(STLINK_PORT),) -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "stm32f1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32f1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(STLINK_PORT)' \ - -x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) +include ../../../../Makefile.rules diff --git a/examples/stm32/f2/Makefile.include b/examples/stm32/f2/Makefile.include index e8ec423..42e7c09 100644 --- a/examples/stm32/f2/Makefile.include +++ b/examples/stm32/f2/Makefile.include @@ -19,133 +19,27 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -# PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb +LIBNAME = opencm3_stm32f2 +DEFS = -DSTM32F2 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f2.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd -CFLAGS += -Os -g \ - -Wall -Wextra -Wimplicit-function-declaration \ - -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \ - -Wundef -Wshadow \ - -I$(TOOLCHAIN_DIR)/include \ - -fno-common -mcpu=cortex-m3 -mthumb -msoft-float -MD -DSTM32F2 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ - -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib/stm32/f2 \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - -mthumb -march=armv7 -mfix-cortex-m3-ldrd -msoft-float -OBJS += $(BINARY).o + +################################################################################ +# OpenOCD specific variables OOCD ?= openocd OOCD_INTERFACE ?= flossjtag OOCD_BOARD ?= olimex_stm32_h103 -# Black magic probe specific variables + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: - -all: images - -images: $(BINARY).images -flash: $(BINARY).flash - -%.images: %.bin %.hex %.srec %.list - @#printf "*** $* images generated ***\n" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f2.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f2 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "stm32f2x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32f2x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) +include ../../../../Makefile.rules diff --git a/examples/stm32/f3/Makefile.include b/examples/stm32/f3/Makefile.include index d52af29..4e062b8 100644 --- a/examples/stm32/f3/Makefile.include +++ b/examples/stm32/f3/Makefile.include @@ -19,136 +19,26 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -# PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb -FLASH = $(shell which st-flash) +LIBNAME = opencm3_stm32f3 +DEFS = -DSTM32F3 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f3.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include \ - -fno-common -mcpu=cortex-m4 -mthumb \ - -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -DSTM32F3 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -lc -lnosys -L$(TOOLCHAIN_DIR)/lib \ - -L$(TOOLCHAIN_DIR)/lib/stm32/f3 \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - -mthumb -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -OBJS += $(BINARY).o +################################################################################ +# OpenOCD specific variables OOCD ?= openocd OOCD_INTERFACE ?= stlink-v2 OOCD_BOARD ?= stm32f3discovery -# Black magic probe specific variables + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: - -all: images - -images: $(BINARY).images -flash: $(BINARY).flash - -%.images: %.bin %.hex %.srec %.list - @#echo "*** $* images generated ***" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f3.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f3 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -%.stlink-flash: %.bin - @printf " FLASH $<\n" - $(Q)$(FLASH) write $(*).bin 0x8000000 - - -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -s ${HOME}/local/share/openocd/scripts \ - -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "flash write_image erase $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @echo " GDB $(*).elf (flash)" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) +include ../../../../Makefile.rules diff --git a/examples/stm32/f4/Makefile.include b/examples/stm32/f4/Makefile.include index 4d8bc2d..8d27ea8 100644 --- a/examples/stm32/f4/Makefile.include +++ b/examples/stm32/f4/Makefile.include @@ -19,140 +19,29 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -# PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb -FLASH = $(shell which st-flash) +LIBNAME = opencm3_stm32f4 +DEFS = -DSTM32F4 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f4.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -CFLAGS += -Os -g \ - -Wall -Wextra -Wimplicit-function-declaration \ - -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \ - -Wundef -Wshadow \ - -I$(TOOLCHAIN_DIR)/include \ - -fno-common -mcpu=cortex-m4 -mthumb \ - -mfloat-abi=hard -mfpu=fpv4-sp-d16 -MD -DSTM32F4 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -lc -lnosys -L$(TOOLCHAIN_DIR)/lib \ - -L$(TOOLCHAIN_DIR)/lib/stm32/f4 \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - -mthumb -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -OBJS += $(BINARY).o +################################################################################ +# OpenOCD specific variables OOCD ?= openocd -OOCD_INTERFACE ?= flossjtag -OOCD_BOARD ?= olimex_stm32_h103 -# Black magic probe specific variables +OOCD_INTERFACE ?= stlink-v2 +OOCD_BOARD ?= stm32f4discovery + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: -all: images +include ../../../../Makefile.rules -images: $(BINARY).images -flash: $(BINARY).flash -%.images: %.bin %.hex %.srec %.list - @#printf "*** $* images generated ***\n" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f4.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32f4 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -%.stlink-flash: %.bin - @printf " FLASH $<\n" - $(Q)$(FLASH) write $(*).bin 0x8000000 - - -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "stm32x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) diff --git a/examples/stm32/l1/Makefile.include b/examples/stm32/l1/Makefile.include index 4e28ac6..7cf8d06 100644 --- a/examples/stm32/l1/Makefile.include +++ b/examples/stm32/l1/Makefile.include @@ -18,151 +18,26 @@ ## along with this library. If not, see . ## -PREFIX ?= arm-none-eabi -#PREFIX ?= arm-elf -CC = $(PREFIX)-gcc -LD = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -GDB = $(PREFIX)-gdb +LIBNAME = opencm3_stm32l1 +DEFS = -DSTM32L1 -TOOLCHAIN_DIR ?= ../../../../../libopencm3 -ifeq ($(wildcard ../../../../../libopencm3/lib/libopencm3_stm32l1.a),) -ifneq ($(strip $(shell which $(CC))),) -TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -endif -else -ifeq ($(V),1) -$(info We seem to be building the example in the source directory. Using local library!) -endif -endif +ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd -ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float -CFLAGS += -Os -g \ - -Wall -Wextra -Wimplicit-function-declaration \ - -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \ - -Wundef -Wshadow \ - -I$(TOOLCHAIN_DIR)/include \ - -fno-common $(ARCH_FLAGS) -MD -DSTM32L1 -LDSCRIPT ?= $(BINARY).ld -LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ - -L$(TOOLCHAIN_DIR)/lib \ - -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ - $(ARCH_FLAGS) -mfix-cortex-m3-ldrd - -CFLAGS += -I$(TOOLCHAIN_DIR)/include -LDFLAGS += -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib/stm32/l1 -SCRIPT_DIR = $(TOOLCHAIN_DIR)/share - -OBJS += $(BINARY).o +################################################################################ +# OpenOCD specific variables OOCD ?= openocd -OOCD_INTERFACE ?= flossjtag -OOCD_BOARD ?= olimex_stm32_h103 -# Black magic probe specific variables +OOCD_INTERFACE ?= stlink-v2 +OOCD_BOARD ?= stm32l1discovery + +################################################################################ +# Black Magic Probe specific variables # Set the BMP_PORT to a serial port and then BMP is used for flashing -BMP_PORT ?= -# texane/stlink can be used by uncommenting this... -# or defining it in your own makefiles -#STLINK_PORT ?= :4242 +BMP_PORT ?= -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -LDFLAGS += -Wl,--print-gc-sections -endif +################################################################################ +# texane/stlink specific variables +#STLINK_PORT ?= :4242 -.SUFFIXES: .elf .bin .hex .srec .list .images -.SECONDEXPANSION: -.SECONDARY: - -all: images - -images: $(BINARY).images -flash: $(BINARY).flash - -%.images: %.bin %.hex %.srec %.list - @#printf "*** $* images generated ***\n" - -%.bin: %.elf - @#printf " OBJCOPY $(*).bin\n" - $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin - -%.hex: %.elf - @#printf " OBJCOPY $(*).hex\n" - $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex - -%.srec: %.elf - @#printf " OBJCOPY $(*).srec\n" - $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec - -%.list: %.elf - @#printf " OBJDUMP $(*).list\n" - $(Q)$(OBJDUMP) -S $(*).elf > $(*).list - -%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32l1.a - @#printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(LD) -o $(*).elf $(OBJS) -lopencm3_stm32l1 $(LDFLAGS) - -%.o: %.c Makefile - @#printf " CC $(subst $(shell pwd)/,,$(@))\n" - $(Q)$(CC) $(CFLAGS) -o $@ -c $< - -clean: - $(Q)rm -f *.o - $(Q)rm -f *.d - $(Q)rm -f *.elf - $(Q)rm -f *.bin - $(Q)rm -f *.hex - $(Q)rm -f *.srec - $(Q)rm -f *.list - -ifeq ($(STLINK_PORT),) -ifeq ($(BMP_PORT),) -ifeq ($(OOCD_SERIAL),) -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "init" -c "reset init" \ - -c "stm32l1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -else -%.flash: %.hex - @printf " FLASH $<\n" - @# IMPORTANT: Don't use "resume", only "reset" will work correctly! - $(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ - -f board/$(OOCD_BOARD).cfg \ - -c "ft2232_serial $(OOCD_SERIAL)" \ - -c "init" -c "reset init" \ - -c "stm32l1x mass_erase 0" \ - -c "flash write_image $(*).hex" \ - -c "reset" \ - -c "shutdown" $(NULL) -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(BMP_PORT)' \ - -x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \ - $(*).elf -endif -else -%.flash: %.elf - @printf " GDB $(*).elf (flash)\n" - $(Q)$(GDB) --batch \ - -ex 'target extended-remote $(STLINK_PORT)' \ - -x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \ - $(*).elf -endif - -.PHONY: images clean - --include $(OBJS:.o=.d) +include ../../../../Makefile.rules