| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | # ---------------------------------------
 | 
					
						
							|  |  |  | # Common make rules for all examples
 | 
					
						
							|  |  |  | # ---------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 21:36:53 +07:00
										 |  |  | ifeq ($(CROSS_COMPILE),xtensa-esp32s2-elf-) | 
					
						
							| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | # Espressif IDF use CMake build system, this add wrapper target to call idf.py
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PHONY: all clean flash | 
					
						
							|  |  |  | .DEFAULT_GOAL := all | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | all: | 
					
						
							|  |  |  | 	idf.py -B$(BUILD) -DBOARD=$(BOARD) build | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | clean: | 
					
						
							| 
									
										
										
										
											2020-06-29 16:52:08 +07:00
										 |  |  | 	idf.py -B$(BUILD) -DBOARD=$(BOARD) clean | 
					
						
							| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | flash: | 
					
						
							| 
									
										
										
										
											2020-06-29 16:52:08 +07:00
										 |  |  | 	idf.py -B$(BUILD) -DBOARD=$(BOARD) flash | 
					
						
							| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | # GNU Make build system
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # libc
 | 
					
						
							| 
									
										
										
										
											2019-10-03 14:22:43 +02:00
										 |  |  | LIBS += -lgcc -lm -lnosys | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifneq ($(BOARD), spresense) | 
					
						
							|  |  |  | LIBS += -lc | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # TinyUSB Stack source
 | 
					
						
							|  |  |  | SRC_C += \
 | 
					
						
							| 
									
										
										
										
											2019-07-24 23:07:30 +07:00
										 |  |  | 	src/tusb.c \
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 	src/common/tusb_fifo.c \
 | 
					
						
							|  |  |  | 	src/device/usbd.c \
 | 
					
						
							|  |  |  | 	src/device/usbd_control.c \
 | 
					
						
							|  |  |  | 	src/class/cdc/cdc_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-10-28 14:38:50 +01:00
										 |  |  | 	src/class/dfu/dfu_rt_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 	src/class/hid/hid_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-06-10 18:46:00 +07:00
										 |  |  | 	src/class/midi/midi_device.c \
 | 
					
						
							| 
									
										
										
										
											2020-04-01 17:07:28 +07:00
										 |  |  | 	src/class/msc/msc_device.c \
 | 
					
						
							|  |  |  | 	src/class/net/net_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-09-14 12:13:11 -04:00
										 |  |  | 	src/class/usbtmc/usbtmc_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-07-24 23:07:30 +07:00
										 |  |  | 	src/class/vendor/vendor_device.c \
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 	src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # TinyUSB stack include
 | 
					
						
							|  |  |  | INC += $(TOP)/src | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CFLAGS += $(addprefix -I,$(INC)) | 
					
						
							| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # TODO Skip nanolib for MSP430
 | 
					
						
							| 
									
										
										
										
											2019-09-14 18:01:52 -04:00
										 |  |  | ifeq ($(BOARD), msp_exp430f5529lp) | 
					
						
							|  |  |  |   LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-05-14 14:07:06 +07:00
										 |  |  | ASFLAGS += $(CFLAGS) | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 18:01:52 -04:00
										 |  |  | # Assembly files can be name with upper case .S, convert it to .s
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 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)) | 
					
						
							|  |  |  | OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Verbose mode
 | 
					
						
							|  |  |  | ifeq ("$(V)","1") | 
					
						
							|  |  |  | $(info CFLAGS  $(CFLAGS) ) $(info ) | 
					
						
							|  |  |  | $(info LDFLAGS $(LDFLAGS)) $(info ) | 
					
						
							|  |  |  | $(info ASFLAGS $(ASFLAGS)) $(info ) | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Set all as default goal
 | 
					
						
							|  |  |  | .DEFAULT_GOAL := all | 
					
						
							| 
									
										
										
										
											2019-09-08 21:54:56 +07:00
										 |  |  | all: $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/$(BOARD)-firmware.hex size | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 12:35:33 +07:00
										 |  |  | uf2: $(BUILD)/$(BOARD)-firmware.uf2 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | OBJ_DIRS = $(sort $(dir $(OBJ))) | 
					
						
							|  |  |  | $(OBJ): | $(OBJ_DIRS) | 
					
						
							|  |  |  | $(OBJ_DIRS): | 
					
						
							|  |  |  | 	@$(MKDIR) -p $@ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(BUILD)/$(BOARD)-firmware.elf: $(OBJ) | 
					
						
							|  |  |  | 	@echo LINK $@ | 
					
						
							|  |  |  | 	@$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf | 
					
						
							|  |  |  | 	@echo CREATE $@ | 
					
						
							| 
									
										
										
										
											2019-05-18 17:03:44 +02:00
										 |  |  | 	@$(OBJCOPY) -O binary $^ $@ | 
					
						
							| 
									
										
										
										
											2019-09-14 18:01:52 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | $(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 	@echo CREATE $@ | 
					
						
							|  |  |  | 	@$(OBJCOPY) -O ihex $^ $@ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 12:35:33 +07:00
										 |  |  | UF2_FAMILY ?= 0x00 | 
					
						
							|  |  |  | $(BUILD)/$(BOARD)-firmware.uf2: $(BUILD)/$(BOARD)-firmware.hex | 
					
						
							|  |  |  | 	@echo CREATE $@ | 
					
						
							|  |  |  | 	$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | # 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
 | 
					
						
							|  |  |  | # to be used to compile all .c files.
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | 	@echo AS $(notdir $@) | 
					
						
							|  |  |  | 	@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # ASM sources upper case .S
 | 
					
						
							|  |  |  | vpath %.S . $(TOP) | 
					
						
							|  |  |  | $(BUILD)/obj/%.o: %.S | 
					
						
							|  |  |  | 	@echo AS $(notdir $@) | 
					
						
							|  |  |  | 	@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | size: $(BUILD)/$(BOARD)-firmware.elf | 
					
						
							|  |  |  | 	-@echo '' | 
					
						
							|  |  |  | 	@$(SIZE) $< | 
					
						
							|  |  |  | 	-@echo '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | clean: | 
					
						
							| 
									
										
										
										
											2019-05-24 12:04:47 +07:00
										 |  |  | 	rm -rf $(BUILD) | 
					
						
							| 
									
										
										
										
											2019-09-14 18:01:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | # Flash binary using Jlink
 | 
					
						
							|  |  |  | ifeq ($(OS),Windows_NT) | 
					
						
							|  |  |  |   JLINKEXE = JLink.exe | 
					
						
							| 
									
										
										
										
											2019-09-14 18:01:52 -04:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  |   JLINKEXE = JLinkExe | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Flash using jlink
 | 
					
						
							|  |  |  | flash-jlink: $(BUILD)/$(BOARD)-firmware.hex | 
					
						
							|  |  |  | 	@echo halt > $(BUILD)/$(BOARD).jlink | 
					
						
							| 
									
										
										
										
											2020-01-17 12:06:59 +07:00
										 |  |  | 	@echo r > $(BUILD)/$(BOARD).jlink | 
					
						
							| 
									
										
										
										
											2019-05-01 14:27:17 +07:00
										 |  |  | 	@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink | 
					
						
							|  |  |  | 	@echo r >> $(BUILD)/$(BOARD).jlink | 
					
						
							|  |  |  | 	@echo go >> $(BUILD)/$(BOARD).jlink | 
					
						
							|  |  |  | 	@echo exit >> $(BUILD)/$(BOARD).jlink | 
					
						
							| 
									
										
										
										
											2019-05-15 18:01:58 +07:00
										 |  |  | 	$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink | 
					
						
							| 
									
										
										
										
											2020-01-10 15:00:46 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # flash STM32 MCU using stlink with STM32 Cube Programmer CLI
 | 
					
						
							|  |  |  | flash-stlink: $(BUILD)/$(BOARD)-firmware.elf | 
					
						
							|  |  |  | 	STM32_Programmer_CLI --connect port=swd --write $< --go | 
					
						
							| 
									
										
										
										
											2020-04-03 12:08:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | endif # Make target
 |