From af164a25a3cffdb9a84d52fa7218667182c5de27 Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Thu, 20 Nov 2014 14:22:12 -0800 Subject: [PATCH] Build system --- .gitignore | 1 + .gitmodules | 5 +- Makefile | 119 ++++++-------------------------- build.mk | 0 common.mk | 26 +++++++ sam0 => deps/sam0 | 0 deps/usb | 1 + firmware.mk | 26 +++++++ {src => firmware}/conf_clocks.h | 0 {src => firmware}/main.c | 0 {src => firmware}/usb.c | 0 usb.mk | 5 ++ 12 files changed, 86 insertions(+), 97 deletions(-) create mode 100644 .gitignore create mode 100644 build.mk create mode 100644 common.mk rename sam0 => deps/sam0 (100%) create mode 160000 deps/usb create mode 100644 firmware.mk rename {src => firmware}/conf_clocks.h (100%) rename {src => firmware}/main.c (100%) rename {src => firmware}/usb.c (100%) create mode 100644 usb.mk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/.gitmodules b/.gitmodules index 2638b89..c1861ac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "sam0"] - path = sam0 + path = deps/sam0 url = https://github.com/avrxml/sam0.git +[submodule "deps/usb"] + path = deps/usb + url = https://github.com/nonolith/USB-XMEGA/ diff --git a/Makefile b/Makefile index b33c3ab..6d29f66 100644 --- a/Makefile +++ b/Makefile @@ -1,111 +1,38 @@ -############################################################################## -CONFIG = Debug -#CONFIG = Release +TARGETS = firmware +BUILD = build -############################################################################## -.PHONY: all directory clean size +all: $(TARGETS) +.PHONY: all clean -AT_PATH = sam0/ -CMSIS_PATH = sam0/cmsis/samr21 -DRIVERS_PATH = sam0/drivers -SRC_PATH = src - -USB_PATH=usb -include usb/samd/makefile +ATMEL_PATH = deps/sam0 +CMSIS_PATH = $(ATMEL_PATH)/cmsis/samr21 +DRIVERS_PATH = $(ATMEL_PATH)/drivers CC = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy SIZE = arm-none-eabi-size -LD = arm-none-eabi-gcc - -CFLAGS += -W -Wall --std=gnu99 -Os -CFLAGS += -fdata-sections -ffunction-sections -CFLAGS += -funsigned-char -funsigned-bitfields -CFLAGS += -mcpu=cortex-m0plus -mthumb -CFLAGS += -MD -MP -MT $(CONFIG)/$(*F).o -MF $(CONFIG)/$(@F).d - -ifeq ($(CONFIG), Debug) - CFLAGS += -g -endif - -LDFLAGS += -mcpu=cortex-m0plus -mthumb -LDFLAGS += -Wl,--gc-sections --specs=nano.specs -LDFLAGS += -Wl,--script=sam0/linker_scripts/samr21/gcc/samr21g18a_flash.ld - -INCLUDES += \ - -I$(SRC_PATH) \ - -I$(CMSIS_PATH)/.. \ - -I$(CMSIS_PATH)/include \ - -I$(CMSIS_PATH)/source \ - -I$(DRIVERS_PATH)/interrupt \ - -I$(DRIVERS_PATH)/port \ - -I$(DRIVERS_PATH)/sercom \ - -I$(DRIVERS_PATH)/sercom/usart \ - -I$(DRIVERS_PATH)/sercom/i2c \ - -I$(DRIVERS_PATH)/sercom/spi \ - -I$(DRIVERS_PATH)/sercom/spi/module_config \ - -I$(DRIVERS_PATH)/system \ - -I$(DRIVERS_PATH)/system/clock \ - -I$(DRIVERS_PATH)/system/clock/clock_samd21_r21 \ - -I$(DRIVERS_PATH)/system/clock/clock_samd21_r21/module_config \ - -I$(DRIVERS_PATH)/system/interrupt \ - -I$(DRIVERS_PATH)/system/interrupt/system_interrupt_samr21 \ - -I$(DRIVERS_PATH)/system/pinmux \ - -I$(AT_PATH)/include \ - -I$(SRC_PATH)/radio \ - $(USB_OPTS) - -SRCS += \ - $(CMSIS_PATH)/source/gcc/startup_samr21.c \ - $(CMSIS_PATH)/source/system_samr21.c \ - $(DRIVERS_PATH)/system/interrupt/interrupt_sam_nvic.c \ - $(DRIVERS_PATH)/system/clock/clock_samd21_r21/clock.c \ - $(DRIVERS_PATH)/system/clock/clock_samd21_r21/gclk.c \ - $(DRIVERS_PATH)/system/pinmux/pinmux.c \ - $(DRIVERS_PATH)/system/interrupt/system_interrupt.c \ - $(DRIVERS_PATH)/system/system.c \ - $(SRC_USB) \ - $(SRC_PATH)/main.c \ - $(SRC_PATH)/usb.c - -DEFINES += \ - -DPHY_AT86RF233 \ - -DHAL_ATSAMD21J18 \ - -DPLATFORM_XPLAINED_PRO_SAMR21 \ - -DF_CPU=8000000 \ - -BOARD=SAMR21_XPLAINED_PRO \ - -D __SAMR21G18A__ - -CFLAGS += $(INCLUDES) $(DEFINES) - -OBJS = $(addprefix $(CONFIG)/, $(notdir %/$(subst .c,.o, $(SRCS)))) - -all: directory $(CONFIG)/firmware.elf $(CONFIG)/firmware.hex $(CONFIG)/firmware.bin size -$(CONFIG)/firmware.elf: - $(Q)$(LD) $(LDFLAGS) $(CFLAGS) $(obj-y) $(libflags-gnu-y) $(SRCS) -o $@ - @echo $(MSG_SIZE) - $(Q)$(SIZE) -Ax $@ - $(Q)$(SIZE) -Bx $@ +include $(addsuffix .mk,$(TARGETS)) +define each_target +$(1): $(BUILD)/$(1).elf $(BUILD)/$(1).bin +.PHONY: $(1) -$(CONFIG)/firmware.hex: $(CONFIG)/firmware.elf - @echo OBJCOPY $@ - @$(OBJCOPY) -O ihex -R .eeprom $^ $@ +$(1)_OBJS := $$(addprefix $(BUILD)/$(1)/, $$(subst .c,.o, $$($(1)_SRC))) +-include $$($(1)_OBJS:.o=.d) -$(CONFIG)/firmware.bin: $(CONFIG)/firmware.elf - @echo OBJCOPY $@ - @$(OBJCOPY) -O binary -R .eeprom $^ $@ +$$($(1)_OBJS): $(BUILD)/$(1)/%.o: %.c + @mkdir -p $$(shell dirname $$@) + $(Q)$(CC) $$($(1)_CFLAGS) $$($(1)_INCLUDE) $$($(1)_DEFINE) -c $$< -o $$@ -MMD -MP -MF $$(patsubst %.o,%.d,$$@) -directory: - @mkdir -p $(CONFIG) +$(BUILD)/$(1).bin $(BUILD)/$(1).elf: $$($(1)_OBJS) + $(Q)$(CC) $$($(1)_CFLAGS) $$($(1)_LDFLAGS) $$($(1)_OBJS) -o $(BUILD)/$(1).elf + $(Q)$(OBJCOPY) -O binary -R .eeprom $(BUILD)/$(1).elf $(BUILD)/$(1).bin +endef -size: $(CONFIG)/firmware.elf - @echo size: - @$(SIZE) -t $^ +$(foreach t,$(TARGETS),$(eval $(call each_target,$(t)))) clean: - @echo clean - @-rm -rf $(CONFIG) + @-rm -rf $(BUILD) --include $(wildcard $(CONFIG)/*.d) +print-% : ; @echo $* = $($*) diff --git a/build.mk b/build.mk new file mode 100644 index 0000000..e69de29 diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..ab70fea --- /dev/null +++ b/common.mk @@ -0,0 +1,26 @@ +$(TARGET)_INCLUDE += \ + -I$(CMSIS_PATH)/.. \ + -I$(CMSIS_PATH)/include \ + -I$(CMSIS_PATH)/source \ + -I$(ATMEL_PATH)/include \ + +$(TARGET)_SRC += \ + $(CMSIS_PATH)/source/gcc/startup_samr21.c \ + $(CMSIS_PATH)/source/system_samr21.c \ + +$(TARGET)_CFLAGS += -Wall --std=gnu99 -Os -g +$(TARGET)_CFLAGS += -fdata-sections -ffunction-sections +$(TARGET)_CFLAGS += -funsigned-char -funsigned-bitfields +$(TARGET)_CFLAGS += -mcpu=cortex-m0plus -mthumb + +$(TARGET)_LDFLAGS += -mcpu=cortex-m0plus -mthumb +$(TARGET)_LDFLAGS += -Wl,--gc-sections --specs=nano.specs +$(TARGET)_LDFLAGS += -Wl,--script=deps/sam0/linker_scripts/samr21/gcc/samr21g18a_flash.ld + +$(TARGET)_DEFINE += \ + -DPHY_AT86RF233 \ + -DHAL_ATSAMD21J18 \ + -DPLATFORM_XPLAINED_PRO_SAMR21 \ + -DF_CPU=8000000 \ + -BOARD=SAMR21_XPLAINED_PRO \ + -D __SAMR21G18A__ diff --git a/sam0 b/deps/sam0 similarity index 100% rename from sam0 rename to deps/sam0 diff --git a/deps/usb b/deps/usb new file mode 160000 index 0000000..93e5c39 --- /dev/null +++ b/deps/usb @@ -0,0 +1 @@ +Subproject commit 93e5c39c80f62a203b18fe04aefcc9cb154d5249 diff --git a/firmware.mk b/firmware.mk new file mode 100644 index 0000000..4af50ce --- /dev/null +++ b/firmware.mk @@ -0,0 +1,26 @@ +TARGET := firmware + +include common.mk +include usb.mk + +$(TARGET)_INCLUDE += \ + -I$(DRIVERS_PATH)/interrupt \ + -I$(DRIVERS_PATH)/port \ + -I$(DRIVERS_PATH)/system \ + -I$(DRIVERS_PATH)/system/clock \ + -I$(DRIVERS_PATH)/system/clock/clock_samd21_r21 \ + -I$(DRIVERS_PATH)/system/clock/clock_samd21_r21/module_config \ + -I$(DRIVERS_PATH)/system/interrupt \ + -I$(DRIVERS_PATH)/system/interrupt/system_interrupt_samr21 \ + -I$(DRIVERS_PATH)/system/pinmux \ + +$(TARGET)_SRC += \ + firmware/main.c \ + firmware/usb.c \ + $(DRIVERS_PATH)/system/interrupt/interrupt_sam_nvic.c \ + $(DRIVERS_PATH)/system/clock/clock_samd21_r21/clock.c \ + $(DRIVERS_PATH)/system/clock/clock_samd21_r21/gclk.c \ + $(DRIVERS_PATH)/system/pinmux/pinmux.c \ + $(DRIVERS_PATH)/system/interrupt/system_interrupt.c \ + $(DRIVERS_PATH)/system/system.c \ + $(USB_PATH)/class/dfu/dfu.c diff --git a/src/conf_clocks.h b/firmware/conf_clocks.h similarity index 100% rename from src/conf_clocks.h rename to firmware/conf_clocks.h diff --git a/src/main.c b/firmware/main.c similarity index 100% rename from src/main.c rename to firmware/main.c diff --git a/src/usb.c b/firmware/usb.c similarity index 100% rename from src/usb.c rename to firmware/usb.c diff --git a/usb.mk b/usb.mk new file mode 100644 index 0000000..7648fed --- /dev/null +++ b/usb.mk @@ -0,0 +1,5 @@ +USB_PATH := deps/usb + +$(TARGET)_SRC += $(USB_PATH)/samd/usb_samd.c +$(TARGET)_SRC += $(USB_PATH)/usb_requests.c +$(TARGET)_INCLUDE += -I $(USB_PATH)