summaryrefslogtreecommitdiff
path: root/examples/rules.mk
diff options
context:
space:
mode:
authornxf58843 <[email protected]>2021-08-23 09:55:04 -0700
committerGitHub <[email protected]>2021-08-23 09:55:04 -0700
commitfb16e80e575a44828f5367f4fb7380162b0354f0 (patch)
treebb965cc935083d99e083667d4f0f1533d50a29f5 /examples/rules.mk
parent616562a48aa1d8ce2f4ca71f6e780a8bec9fb5eb (diff)
parentea902493db49843dcdeca6bfa2b2efe540f44b2f (diff)
Merge pull request #2 from hathach/master
Pulling latest from source
Diffstat (limited to 'examples/rules.mk')
-rw-r--r--examples/rules.mk142
1 files changed, 107 insertions, 35 deletions
diff --git a/examples/rules.mk b/examples/rules.mk
index 87c7e9649..4fce468fd 100644
--- a/examples/rules.mk
+++ b/examples/rules.mk
@@ -1,6 +1,17 @@
-#
-# Common make definition for all examples
-#
+# ---------------------------------------
+# Common make rules for all examples
+# ---------------------------------------
+
+# Set all as default goal
+.DEFAULT_GOAL := all
+
+# ESP32-SX and RP2040 has its own CMake build system
+ifneq ($(FAMILY),esp32s2)
+ifneq ($(FAMILY),esp32s3)
+ifneq ($(FAMILY),rp2040)
+# ---------------------------------------
+# GNU Make build system
+# ---------------------------------------
# libc
LIBS += -lgcc -lm -lnosys
@@ -15,29 +26,36 @@ SRC_C += \
src/common/tusb_fifo.c \
src/device/usbd.c \
src/device/usbd_control.c \
- src/class/msc/msc_device.c \
+ src/class/audio/audio_device.c \
src/class/cdc/cdc_device.c \
+ src/class/dfu/dfu_device.c \
src/class/dfu/dfu_rt_device.c \
src/class/hid/hid_device.c \
src/class/midi/midi_device.c \
+ src/class/msc/msc_device.c \
+ src/class/net/net_device.c \
src/class/usbtmc/usbtmc_device.c \
- src/class/vendor/vendor_device.c \
- src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c
+ src/class/vendor/vendor_device.c
# TinyUSB stack include
INC += $(TOP)/src
-#
CFLAGS += $(addprefix -I,$(INC))
-LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,[email protected] -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs
+
+LDFLAGS += $(CFLAGS) -Wl,-T,$(TOP)/$(LD_FILE) -Wl,[email protected] -Wl,-cref -Wl,-gc-sections
+ifneq ($(SKIP_NANOLIB), 1)
+LDFLAGS += -specs=nosys.specs -specs=nano.specs
+endif
+
ASFLAGS += $(CFLAGS)
-# Assembly files can be name with upper case .S, convert it to .s
+# Assembly files can be name with upper case .S, convert it to .s
SRC_S := $(SRC_S:.S=.s)
# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
# assembly file should be placed first in linking order
-OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=.o))
+# '_asm' suffix is added to object of assembly file
+OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o))
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
# Verbose mode
@@ -47,33 +65,44 @@ $(info LDFLAGS $(LDFLAGS)) $(info )
$(info ASFLAGS $(ASFLAGS)) $(info )
endif
-# Set all as default goal
-.DEFAULT_GOAL := all
-all: $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/$(BOARD)-firmware.hex size
+all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size
-uf2: $(BUILD)/$(BOARD)-firmware.uf2
+uf2: $(BUILD)/$(PROJECT).uf2
OBJ_DIRS = $(sort $(dir $(OBJ)))
$(OBJ): | $(OBJ_DIRS)
$(OBJ_DIRS):
+ifeq ($(CMDEXE),1)
+ @$(MKDIR) $(subst /,\,$@)
+else
@$(MKDIR) -p $@
+endif
-$(BUILD)/$(BOARD)-firmware.elf: $(OBJ)
+$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
-$(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf
+$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O binary $^ $@
-
-$(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf
+
+$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O ihex $^ $@
-UF2_FAMILY ?= 0x00
-$(BUILD)/$(BOARD)-firmware.uf2: $(BUILD)/$(BOARD)-firmware.hex
+# UF2 generation, iMXRT need to strip to text only before conversion
+ifeq ($(FAMILY),imxrt)
+$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).elf
+ @echo CREATE $@
+ @$(OBJCOPY) -O ihex -R .flash_config -R .ivt $^ $(BUILD)/$(PROJECT)-textonly.hex
+ $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $(BUILD)/$(PROJECT)-textonly.hex
+else
+$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex
@echo CREATE $@
- $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^
+ $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^
+endif
+
+copy-artifact: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex $(BUILD)/$(PROJECT).uf2
# We set vpath to point to the top of the tree so that the source files
# can be located. By following this scheme, it allows a single build rule
@@ -82,43 +111,51 @@ vpath %.c . $(TOP)
$(BUILD)/obj/%.o: %.c
@echo CC $(notdir $@)
@$(CC) $(CFLAGS) -c -MD -o $@ $<
- @# The following fixes the dependency file.
- @# See http://make.paulandlesley.org/autodep.html for details.
- @# Regex adjusted from the above to play better with Windows paths, etc.
- @$(CP) $(@:.o=.d) $(@:.o=.P); \
- $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
- -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
- $(RM) $(@:.o=.d)
# ASM sources lower case .s
vpath %.s . $(TOP)
-$(BUILD)/obj/%.o: %.s
+$(BUILD)/obj/%_asm.o: %.s
@echo AS $(notdir $@)
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
# ASM sources upper case .S
vpath %.S . $(TOP)
-$(BUILD)/obj/%.o: %.S
+$(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
-size: $(BUILD)/$(BOARD)-firmware.elf
+size: $(BUILD)/$(PROJECT).elf
-@echo ''
@$(SIZE) $<
-@echo ''
+.PHONY: clean
clean:
- rm -rf $(BUILD)
+ifeq ($(CMDEXE),1)
+ rd /S /Q $(subst /,\,$(BUILD))
+else
+ $(RM) -rf $(BUILD)
+endif
+
+endif
+endif
+endif # GNU Make
+
+# ---------------------------------------
+# Flash Targets
+# ---------------------------------------
# Flash binary using Jlink
ifeq ($(OS),Windows_NT)
JLINKEXE = JLink.exe
-else
+else
JLINKEXE = JLinkExe
endif
+JLINK_IF ?= swd
+
# Flash using jlink
-flash-jlink: $(BUILD)/$(BOARD)-firmware.hex
+flash-jlink: $(BUILD)/$(PROJECT).hex
@echo halt > $(BUILD)/$(BOARD).jlink
@echo r > $(BUILD)/$(BOARD).jlink
@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
@@ -128,5 +165,40 @@ flash-jlink: $(BUILD)/$(BOARD)-firmware.hex
$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink
# flash STM32 MCU using stlink with STM32 Cube Programmer CLI
-flash-stlink: $(BUILD)/$(BOARD)-firmware.elf
+flash-stlink: $(BUILD)/$(PROJECT).elf
STM32_Programmer_CLI --connect port=swd --write $< --go
+
+# flash with pyocd
+flash-pyocd: $(BUILD)/$(PROJECT).hex
+ pyocd flash -t $(PYOCD_TARGET) $<
+ pyocd reset -t $(PYOCD_TARGET)
+
+# flash with Black Magic Probe
+
+# This symlink is created by https://github.com/blacksphere/blackmagic/blob/master/driver/99-blackmagic.rules
+BMP ?= /dev/ttyBmpGdb
+
+flash-bmp: $(BUILD)/$(PROJECT).elf
+ $(GDB) --batch -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' -ex load $<
+
+debug-bmp: $(BUILD)/$(PROJECT).elf
+ $(GDB) -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' $<
+
+#-------------- Artifacts --------------
+
+# Create binary directory
+$(BIN):
+ @$(MKDIR) -p $@
+
+# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
+# due to large size of combined artifacts, only uf2 is uploaded for now
+copy-artifact: $(BIN)
+ @$(CP) $(BUILD)/$(PROJECT).uf2 $(BIN)
+ #@$(CP) $(BUILD)/$(PROJECT).bin $(BIN)
+ #@$(CP) $(BUILD)/$(PROJECT).hex $(BIN)
+ #@$(CP) $(BUILD)/$(PROJECT).elf $(BIN)
+
+# Print out the value of a make variable.
+# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
+print-%:
+ @echo $* = $($*)