diff options
-rw-r--r-- | Makefile | 303 | ||||
-rw-r--r-- | libmaple/rules.mk | 50 | ||||
-rw-r--r-- | support/make/build-rules.mk | 40 | ||||
-rw-r--r-- | support/make/build-targets.mk | 31 | ||||
-rw-r--r-- | support/make/build-templates.mk | 5 | ||||
-rw-r--r-- | support/openocd/flash.cfg | 4 | ||||
-rw-r--r-- | wirish/rules.mk | 43 |
7 files changed, 266 insertions, 210 deletions
@@ -1,139 +1,105 @@ -# dumb dumb dumb makefile -# Project name -PROJECT=maple - -# ARM/GNU toolchain parameters -CC := arm-none-eabi-gcc -CPP := arm-none-eabi-g++ -LD := arm-none-eabi-ld -v -AR := arm-none-eabi-ar -AS := arm-none-eabi-as -CP := arm-none-eabi-objcopy -OD := arm-none-eabi-objdump - -# Platform detection -ARCH = $(shell uname -m) -OS = $(shell uname) +.DEFAULT_GOAL := sketch + +BOARD ?= maple +MAPLE_TARGET ?= flash + +# Useful paths +SRCROOT := $(dir) +BUILD_PATH = build +LIBMAPLE_PATH := libmaple + +# Useful variables +GLOBAL_CFLAGS = -Os -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \ + -ffunction-sections -fdata-sections -Wl,--gc-sections + +GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall + + +LDDIR := support/ld +LDFLAGS = -T$(LDDIR)/$(LDSCRIPT) -L$(LDDIR) \ + -mcpu=cortex-m3 -mthumb -Xlinker \ + --gc-sections --print-gc-sections --march=armv7-m -Wall + +# Set up build rules and some useful templates +include support/make/build-rules.mk +include support/make/build-templates.mk VENDOR_ID = 1EAF PRODUCT_ID = 0003 -# Modify this if necessary -DFU = dfu-util +# Force a rebuild if the maple target changed +PREV_BUILD_TYPE := $(shell cat $(BUILD_PATH)/build-type 2>/dev/null) +ifneq ($(PREV_BUILD_TYPE), $(MAPLE_TARGET)) + $(shell rm -rf $(BUILD_PATH)) +endif + +# Some target specific things +ifeq ($(MAPLE_TARGET), ram) + VECT_BASE_ADDR := VECT_TAB_RAM + LDSCRIPT := ram.ld + UPLOAD := support/scripts/reset.py && \ + sleep 1 && \ + $(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R + +endif +ifeq ($(MAPLE_TARGET), flash) + LDSCRIPT := flash.ld + VECT_BASE_ADDR := VECT_TAB_FLASH + UPLOAD := support/scripts/reset.py && \ + sleep 1 && \ + $(DFU) -a1 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R +endif +ifeq ($(MAPLE_TARGET), jtag) + LDSCRIPT := jtag.ld + VECT_BASE_ADDR := VECT_TAB_BASE + UPLOAD := \ + openocd -f support/openocd/flash.cfg +endif + +# Set all submodules here +LIBMAPLE_MODULES := libmaple +LIBMAPLE_MODULES += wirish + +# call each module rules.mk +$(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m)))) + +# Main target +include support/make/build-targets.mk + +# Fake targets +POSSIBLE_TARGETS := install sketch clean help debug cscope tags ctags +.PHONY: $(POSSIBLE_TARGETS) + +install: sketch + $(UPLOAD) + +sketch: MSG_INFO $(BUILD_PATH)/$(BOARD).bin -BUILD_PATH = build -LIB_PATH = libmaple - -OUTDIRS = $(BUILD_PATH)/$(LIB_PATH) \ - $(BUILD_PATH)/wirish \ - $(BUILD_PATH)/wirish/comm \ - $(BUILD_PATH)/$(LIB_PATH)/usb \ - $(BUILD_PATH)/$(LIB_PATH)/usb/usb_lib - - - -INCLUDES = -I$(LIB_PATH) \ - -I./ \ - -Iwirish \ - -Iwirish/comm \ - -I$(LIB_PATH)/usb \ - -I$(LIB_PATH)/usb/usb_lib - -CFLAGS = $(INCLUDES) -c \ - -Os \ - -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \ - -ffunction-sections -fdata-sections -Wl,--gc-sections \ - -D$(DEFFLAGS) - -CXXFLAGS = -fno-rtti -fno-exceptions -Wall - -LDDIR=support/ld -LFLAGS = -T$(LDDIR)/$(LDSCRIPT) -L$(LDDIR) \ - -mcpu=cortex-m3 -mthumb -Xlinker \ - --gc-sections --print-gc-sections --march=armv7-m -Wall - -CPFLAGS = -v -Obinary -ODFLAGS = -S - -CSRC = libmaple/systick.c \ - libmaple/timers.c \ - libmaple/adc.c \ - libmaple/syscalls.c \ - libmaple/exc.c \ - libmaple/exti.c \ - libmaple/gpio.c \ - libmaple/nvic.c \ - libmaple/usart.c \ - libmaple/util.c \ - libmaple/rcc.c \ - libmaple/flash.c \ - libmaple/spi.c \ - wirish/wirish.c \ - wirish/wirish_shift.c \ - wirish/wirish_analog.c \ - wirish/time.c \ - wirish/pwm.c \ - wirish/ext_interrupts.c \ - wirish/wirish_digital.c \ - libmaple/usb/usb.c \ - libmaple/usb/usb_callbacks.c \ - libmaple/usb/usb_hardware.c \ - libmaple/usb/descriptors.c \ - libmaple/usb/usb_lib/usb_core.c \ - libmaple/usb/usb_lib/usb_init.c \ - libmaple/usb/usb_lib/usb_int.c \ - libmaple/usb/usb_lib/usb_mem.c \ - libmaple/usb/usb_lib/usb_regs.c \ - -CPPSRC = wirish/wirish_math.cpp \ - wirish/Print.cpp \ - wirish/comm/HardwareSerial.cpp \ - wirish/comm/HardwareSPI.cpp \ - wirish/usb_serial.cpp \ - wirish/cxxabi-compat.cpp \ - main.cpp - -# i really have no idea what i'm doing -meep += $(CSRC) -moop = $(patsubst %, %, $(meep)) -beep = $(CPPSRC) -boop = $(patsubst %, %, $(beep)) - -# English -MSG_ERRORS_NONE = Errors: none -MSG_BEGIN = -------- begin -------- -MSG_ETAGS = Created TAGS File -MSG_END = -------- end -------- -MSG_SIZE = Program Image Size: -MSG_LINKING = Linking: -MSG_COMPILING = Compiling C: -MSG_ASSEMBLING = Assembling: -MSG_CLEANING = Cleaning project: -MSG_FLASH = Creating load file for Flash: - - -_COBJ = $(moop:.c=.o) -_CPPOBJ = $(boop:.cpp=.o) -COBJ = $(patsubst %, $(BUILD_PATH)/%,$(_COBJ)) -CPPOBJ = $(patsubst %, $(BUILD_PATH)/%,$(_CPPOBJ)) - -.PHONY: run cscope clean info program_ram program_flash program_jtag - -info: - @echo "" - @echo "libmaple Makefile help" - @echo "----------------------" - @echo "Compile targets:" - @echo " ram: Compile sketch code for RAM to be loaded over the bootloader" - @echo " flash: Compile sketch code for flash to be loaded over the bootloader" - @echo " jtag: Compile sketch code for flash to be loaded over JTAG" +clean: + rm -rf build + +help: @echo "" - @echo "Programming targets:" - @echo " program_ram: Upload code to RAM via bootloader" - @echo " program_flash: Upload code to flash via bootloader" - @echo " program_jtag: Upload code to flash via jtag" + @echo " libmaple Makefile help" + @echo " ----------------------" + @echo " Compile targets:" + @echo " sketch: Compile sketch code" + @echo " " + @echo " Programming targets:" + @echo " install: Upload code to target" + @echo " " + @echo " Other targets:" + @echo " debug: Start an openocd gdb server, port 3333" + @echo " clean: Remove all build and object files" + @echo " help: Show this message" + @echo " " + +debug: + $(OPENOCD) -f support/openocd/run.cfg -all: info +cscope: + rm -rf *.cscope + find . -name '*.[hcs]' -o -name '*.cpp' | xargs cscope -b tags: etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"` @@ -142,82 +108,3 @@ tags: ctags: ctags-exuberant -R . @echo "Made tags file for VIM code browsing" - -$(BUILD_PATH): - mkdir -p build - -$(OUTDIRS): - @echo Making directory $@ - mkdir -p $@ - @echo - -# actual build rules -$(COBJ) : $(BUILD_PATH)/%.o : %.c - @echo $(MSG_COMPILING) $< - $(CC) $(CFLAGS) -c $< -o $@ - @echo - -$(CPPOBJ) : $(BUILD_PATH)/%.o : %.cpp - @echo $(MSG_COMPILING) $< - $(CPP) $(CFLAGS) $(CXXFLAGS) -c $< -o $@ - @echo - -# targets -$(BUILD_PATH)/$(PROJECT).out: $(OUTDIRS) $(COBJ) $(CPPOBJ) - @echo Linking - @echo CPP OBJ: $(CPPOBJ) - @echo - @echo C OBJ: $(COBJ) - @echo - $(CC) $(LFLAGS) -o $(BUILD_PATH)/$(PROJECT).out $(COBJ) $(CPPOBJ) - @echo - -$(BUILD_PATH)/main.bin: $(BUILD_PATH)/$(PROJECT).out - $(CP) $(CPFLAGS) $(BUILD_PATH)/$(PROJECT).out $(BUILD_PATH)/main.bin - $(OD) $(ODFLAGS) $(BUILD_PATH)/$(PROJECT).out > $(BUILD_PATH)/$(PROJECT).d - @echo - find $(BUILD_PATH) -iname *.o | xargs arm-none-eabi-size -t - @echo - @echo "Final Size:" - arm-none-eabi-size $< - -ram: DEFFLAGS := VECT_TAB_RAM -ram: LDSCRIPT := ram.ld -ram: $(BUILD_PATH)/main.bin - @echo "RAM build" - -flash: DEFFLAGS := VECT_TAB_FLASH -flash: LDSCRIPT := flash.ld -flash: $(BUILD_PATH)/main.bin - @echo "Flash build" - -jtag: DEFFLAGS := VECT_TAB_BASE -jtag: LDSCRIPT := jtag.ld -jtag: $(BUILD_PATH)/main.bin - @echo "JTAG build" - -program_ram: ram - support/scripts/reset.py - sleep 1 - $(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D build/main.bin -R - -program_flash: flash - support/scripts/reset.py - sleep 1 - $(DFU) -a1 -d $(VENDOR_ID):$(PRODUCT_ID) -D build/main.bin -R - -program_jtag: jtag - openocd -f support/openocd/flash.cfg - - -run: $(BUILD_PATH)/main.bin - openocd -f support/openocd/run.cfg - -cscope: - rm -rf *.cscope - find . -name '*.[hcs]' -o -name '*.cpp' | xargs cscope -b - -clean: - rm -f *.hex *.o - rm -rf build - diff --git a/libmaple/rules.mk b/libmaple/rules.mk new file mode 100644 index 0000000..60673fe --- /dev/null +++ b/libmaple/rules.mk @@ -0,0 +1,50 @@ +# Standard things +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) +BUILDDIRS += $(BUILD_PATH)/$(d) +BUILDDIRS += $(BUILD_PATH)/$(d)/usb +BUILDDIRS += $(BUILD_PATH)/$(d)/usb/usb_lib + +LIBMAPLE_INCLUDES := -I$(LIBMAPLE_PATH) -I$(LIBMAPLE_PATH)/usb -I$(LIBMAPLE_PATH)/usb/usb_lib + +# Local flags +CFLAGS_$(d) = -I$(d) $(LIBMAPLE_INCLUDES) -D$(VECT_BASE_ADDR) + +# Local rules and targets +cSRCS_$(d) := systick.c \ + timers.c \ + adc.c \ + syscalls.c \ + exc.c \ + exti.c \ + gpio.c \ + nvic.c \ + usart.c \ + util.c \ + rcc.c \ + flash.c \ + spi.c \ + usb/usb.c \ + usb/usb_callbacks.c \ + usb/usb_hardware.c \ + usb/descriptors.c \ + usb/usb_lib/usb_core.c \ + usb/usb_lib/usb_init.c \ + usb/usb_lib/usb_int.c \ + usb/usb_lib/usb_mem.c \ + usb/usb_lib/usb_regs.c + +cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) + +OBJS_$(d) := $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) +DEPS_$(d) := $(OBJS_$(d):%.o=%.d) + +$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) + +TGT_BIN += $(OBJS_$(d)) + +# Standard things +-include $(DEPS_$(d)) +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/support/make/build-rules.mk b/support/make/build-rules.mk new file mode 100644 index 0000000..52ede32 --- /dev/null +++ b/support/make/build-rules.mk @@ -0,0 +1,40 @@ +# Useful tools +CC := arm-none-eabi-gcc +CXX := arm-none-eabi-g++ +LD := arm-none-eabi-ld -v +AR := arm-none-eabi-ar +AS := arm-none-eabi-as +OBJCOPY := arm-none-eabi-objcopy +DISAS := arm-none-eabi-objdump +OBJDUMP := arm-none-eabi-objdump +SIZE := arm-none-eabi-size +DFU := dfu-util +OPENOCD := openocd + +# Suppress annoying output unless V is set +ifndef V + SILENT_CC = @echo ' [CC] ' $(@:$(BUILD_PATH)/%.o=%.c); + SILENT_CXX = @echo ' [CXX] ' $(@:$(BUILD_PATH)/%.o=%.cpp); + SILENT_LD = @echo ' [LD] ' $(@F); + SILENT_AR = @echo ' [AR] ' + SILENT_AS = @echo ' [AS] ' + SILENT_OBJCOPY = @echo ' [OBJCOPY] ' $(@F); + SILENT_DISAS = @echo ' [DISAS] ' $(@:$(BUILD_PATH)/%.bin=%).disas; + SILENT_OBJDUMP = @echo ' [OBJDUMP] ' $(OBJDUMP); + DFU := dfu-util + OPENOCD := openocd +endif + +BUILDDIRS := +TGT_BIN := + +CFLAGS = $(GLOBAL_CFLAGS) $(TGT_CFLAGS) +CXXFLAGS = $(GLOBAL_CXXFLAGS) $(TGT_CXXFLAGS) + +# General directory independent build rules, generate dependency information +$(BUILD_PATH)/%.o: %.c + $(SILENT_CC) $(CC) $(CFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $< + +$(BUILD_PATH)/%.o: %.cpp + $(SILENT_CXX) $(CXX) $(CFLAGS) $(CXXFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $< + diff --git a/support/make/build-targets.mk b/support/make/build-targets.mk new file mode 100644 index 0000000..a7f2446 --- /dev/null +++ b/support/make/build-targets.mk @@ -0,0 +1,31 @@ +# main project target +$(BUILD_PATH)/main.o: main.cpp + $(SILENT_CXX) $(CXX) $(CFLAGS) $(CXXFLAGS) $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -o $@ -c $< + +$(BUILD_PATH)/$(BOARD).elf: $(BUILDDIRS) $(TGT_BIN) $(BUILD_PATH)/main.o + $(SILENT_LD) $(CXX) $(LDFLAGS) -o $@ $(TGT_BIN) $(BUILD_PATH)/main.o + +$(BUILD_PATH)/$(BOARD).bin: $(BUILD_PATH)/$(BOARD).elf + $(SILENT_OBJCOPY) $(OBJCOPY) -v -Obinary $(BUILD_PATH)/$(BOARD).elf $@ 1>/dev/null + $(SILENT_DISAS) $(DISAS) -d $(BUILD_PATH)/$(BOARD).elf > $(BUILD_PATH)/$(BOARD).disas + @echo + @find $(BUILD_PATH) -iname *.o | xargs $(SIZE) -t > $(BUILD_PATH)/$(BOARD).sizes + @echo "Final Size:" + $(SIZE) $< + @echo $(MAPLE_TARGET) > $(BUILD_PATH)/build-type + +$(BUILDDIRS): + @mkdir -p $@ + +MSG_INFO: + @echo "================================================================================" + @echo "" + @echo " Build info:" + @echo " BOARD:" $(BOARD) + @echo " MAPLE_TARGET:" $(MAPLE_TARGET) + @echo "" + @echo " See 'make help' for all possible targets" + @echo "" + @echo "================================================================================" + @echo + diff --git a/support/make/build-templates.mk b/support/make/build-templates.mk new file mode 100644 index 0000000..4371f13 --- /dev/null +++ b/support/make/build-templates.mk @@ -0,0 +1,5 @@ +define LIBMAPLE_MODULE_template +dir := $(1) +include $$(dir)/rules.mk +endef + diff --git a/support/openocd/flash.cfg b/support/openocd/flash.cfg index 6cffa80..eceac32 100644 --- a/support/openocd/flash.cfg +++ b/support/openocd/flash.cfg @@ -72,9 +72,9 @@ proc flash_chip {} { echo "Erasing 128KB..." flash erase_address 0x08000000 0x20000 echo "Flashing image..." - flash write_bank 0 build/main.bin 0 + flash write_bank 0 build/maple.bin 0 echo "Verifying image..." - verify_image build/main.bin 0x08000000 bin + verify_image build/maple.bin 0x08000000 bin echo "Checksum verified, resetting chip" reset run echo "Daemon shutdown" diff --git a/wirish/rules.mk b/wirish/rules.mk new file mode 100644 index 0000000..e74d15d --- /dev/null +++ b/wirish/rules.mk @@ -0,0 +1,43 @@ +# Standard things +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) +BUILDDIRS += $(BUILD_PATH)/$(d) +BUILDDIRS += $(BUILD_PATH)/$(d)/comm + +WIRISH_INCLUDES := -I$(d) -I$(d)/comm + +# Local flags +CFLAGS_$(d) := $(WIRISH_INCLUDES) $(LIBMAPLE_INCLUDES) + +# Local rules and targets +cSRCS_$(d) := wirish.c \ + wirish_shift.c \ + wirish_analog.c \ + time.c \ + pwm.c \ + ext_interrupts.c \ + wirish_digital.c + +cppSRCS_$(d) := wirish_math.cpp \ + Print.cpp \ + comm/HardwareSerial.cpp \ + comm/HardwareSPI.cpp \ + usb_serial.cpp \ + cxxabi-compat.cpp + +cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) +cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%) + +OBJS_$(d) := $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) \ + $(cppFILES_$(d):%.cpp=$(BUILD_PATH)/%.o) +DEPS_$(d) := $(OBJS_$(d):%.o=%.d) + +$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) + +TGT_BIN += $(OBJS_$(d)) + +# Standard things +-include $(DEPS_$(d)) +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) |