2020-04-03 12:08:06 +07:00
|
|
|
# ---------------------------------------
|
|
|
|
# Common make rules for all examples
|
|
|
|
# ---------------------------------------
|
|
|
|
|
2021-01-26 21:19:14 +07:00
|
|
|
# Set all as default goal
|
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
|
2021-01-22 14:58:32 +07:00
|
|
|
ifeq ($(FAMILY),esp32s2)
|
2021-03-01 20:25:55 +07:00
|
|
|
# ---------------------------------------
|
2020-04-03 12:08:06 +07:00
|
|
|
# Espressif IDF use CMake build system, this add wrapper target to call idf.py
|
2021-03-01 20:25:55 +07:00
|
|
|
# ---------------------------------------
|
2020-04-03 12:08:06 +07:00
|
|
|
|
|
|
|
.PHONY: all clean flash
|
|
|
|
|
|
|
|
all:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) build
|
2020-04-03 12:08:06 +07:00
|
|
|
|
2020-11-27 22:31:47 +07:00
|
|
|
build: all
|
|
|
|
|
2020-04-03 12:08:06 +07:00
|
|
|
clean:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) clean
|
2021-01-22 14:58:32 +07:00
|
|
|
|
|
|
|
fullclean:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) fullclean
|
2020-04-03 12:08:06 +07:00
|
|
|
|
|
|
|
flash:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) flash
|
2020-04-03 12:08:06 +07:00
|
|
|
|
2020-11-27 22:31:47 +07:00
|
|
|
bootloader-flash:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) bootloader-flash
|
2020-11-27 22:31:47 +07:00
|
|
|
|
|
|
|
app-flash:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) app-flash
|
2020-11-27 22:31:47 +07:00
|
|
|
|
|
|
|
erase:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) erase_flash
|
2020-11-27 22:31:47 +07:00
|
|
|
|
|
|
|
monitor:
|
2021-01-29 11:24:05 +07:00
|
|
|
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) monitor
|
2021-01-22 14:58:32 +07:00
|
|
|
|
2021-02-01 14:47:39 +07:00
|
|
|
uf2: $(BUILD)/$(PROJECT).uf2
|
|
|
|
|
2021-01-26 21:19:14 +07:00
|
|
|
UF2_FAMILY_ID = 0xbfdd4eee
|
2021-02-01 14:47:39 +07:00
|
|
|
$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).bin
|
2021-01-26 21:19:14 +07:00
|
|
|
@echo CREATE $@
|
2021-02-01 14:47:39 +07:00
|
|
|
$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -b 0x0 -c -o $@ $^
|
2021-01-26 21:19:14 +07:00
|
|
|
|
2021-01-22 14:58:32 +07:00
|
|
|
else ifeq ($(FAMILY),rp2040)
|
2021-03-01 20:25:55 +07:00
|
|
|
# ---------------------------------------
|
|
|
|
# RP2040 CMake
|
|
|
|
# ---------------------------------------
|
2021-01-22 14:58:32 +07:00
|
|
|
|
2021-02-10 00:48:58 -05:00
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CMAKE_DEFSYM += -DCMAKE_BUILD_TYPE=Debug
|
|
|
|
endif
|
|
|
|
|
2021-01-29 11:24:05 +07:00
|
|
|
$(BUILD):
|
|
|
|
cmake -S . -B $(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) -DPICO_BUILD_DOCS=0 $(CMAKE_DEFSYM)
|
|
|
|
|
|
|
|
all: $(BUILD)
|
2021-01-22 14:58:32 +07:00
|
|
|
$(MAKE) -C $(BUILD)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(RM) -rf $(BUILD)
|
2020-11-27 22:31:47 +07:00
|
|
|
|
2021-01-29 11:24:05 +07:00
|
|
|
flash:
|
|
|
|
@$(CP) $(BUILD)/$(PROJECT).uf2 /media/$(USER)/RPI-RP2
|
|
|
|
|
2020-04-03 12:08:06 +07:00
|
|
|
else
|
2021-03-01 20:25:55 +07:00
|
|
|
# ---------------------------------------
|
2020-04-03 12:08:06 +07:00
|
|
|
# GNU Make build system
|
2021-03-01 20:25:55 +07:00
|
|
|
# ---------------------------------------
|
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 \
|
2020-10-07 13:36:03 +07:00
|
|
|
src/class/audio/audio_device.c \
|
2019-05-01 14:27:17 +07:00
|
|
|
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
|
|
|
|
2021-03-02 11:50:57 +07:00
|
|
|
LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections
|
|
|
|
ifneq ($(SKIP_NANOLIB), 1)
|
|
|
|
LDFLAGS += -specs=nosys.specs -specs=nano.specs
|
2019-09-14 18:01:52 -04:00
|
|
|
endif
|
2021-03-02 11:50:57 +07:00
|
|
|
|
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
|
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size
|
2019-05-01 14:27:17 +07:00
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
uf2: $(BUILD)/$(PROJECT).uf2
|
2019-05-20 12:35:33 +07:00
|
|
|
|
2019-05-01 14:27:17 +07:00
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
|
|
|
$(OBJ_DIRS):
|
2021-01-14 01:19:43 +09:00
|
|
|
ifeq ($(CMDEXE),1)
|
2021-01-10 20:46:29 +09:00
|
|
|
@$(MKDIR) $(subst /,\,$@)
|
|
|
|
else
|
2019-05-01 14:27:17 +07:00
|
|
|
@$(MKDIR) -p $@
|
2021-01-10 20:46:29 +09:00
|
|
|
endif
|
2019-05-01 14:27:17 +07:00
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
$(BUILD)/$(PROJECT).elf: $(OBJ)
|
2019-05-01 14:27:17 +07:00
|
|
|
@echo LINK $@
|
|
|
|
@$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
|
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
|
2019-05-01 14:27:17 +07:00
|
|
|
@echo CREATE $@
|
2019-05-18 17:03:44 +02:00
|
|
|
@$(OBJCOPY) -O binary $^ $@
|
2019-09-14 18:01:52 -04:00
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
|
2019-05-01 14:27:17 +07:00
|
|
|
@echo CREATE $@
|
|
|
|
@$(OBJCOPY) -O ihex $^ $@
|
|
|
|
|
2021-01-26 21:19:14 +07:00
|
|
|
# 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
|
2021-01-26 12:46:24 +07:00
|
|
|
$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex
|
2019-05-20 12:35:33 +07:00
|
|
|
@echo CREATE $@
|
2021-01-26 21:19:14 +07:00
|
|
|
$(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
|
2019-05-20 12:35:33 +07:00
|
|
|
|
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 $@ $<
|
|
|
|
|
|
|
|
# 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 $@ $<
|
|
|
|
|
2021-01-26 12:46:24 +07:00
|
|
|
size: $(BUILD)/$(PROJECT).elf
|
2019-05-01 14:27:17 +07:00
|
|
|
-@echo ''
|
|
|
|
@$(SIZE) $<
|
|
|
|
-@echo ''
|
|
|
|
|
2020-07-16 00:44:09 +07:00
|
|
|
.PHONY: clean
|
2019-05-01 14:27:17 +07:00
|
|
|
clean:
|
2021-01-14 01:19:43 +09:00
|
|
|
ifeq ($(CMDEXE),1)
|
2021-01-10 20:46:29 +09:00
|
|
|
rd /S /Q $(subst /,\,$(BUILD))
|
|
|
|
else
|
2020-07-16 00:44:09 +07:00
|
|
|
$(RM) -rf $(BUILD)
|
2021-01-10 20:46:29 +09:00
|
|
|
endif
|
2020-07-16 00:44:09 +07:00
|
|
|
|
|
|
|
# Print out the value of a make variable.
|
|
|
|
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
|
|
|
|
print-%:
|
|
|
|
@echo $* = $($*)
|
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
|
|
|
|
|
2020-10-08 17:17:37 +07:00
|
|
|
JLINK_IF ?= swd
|
|
|
|
|
2019-05-01 14:27:17 +07:00
|
|
|
# Flash using jlink
|
2021-01-26 12:46:24 +07:00
|
|
|
flash-jlink: $(BUILD)/$(PROJECT).hex
|
2019-05-01 14:27:17 +07:00
|
|
|
@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
|
2021-01-26 12:46:24 +07:00
|
|
|
flash-stlink: $(BUILD)/$(PROJECT).elf
|
2020-01-10 15:00:46 +07:00
|
|
|
STM32_Programmer_CLI --connect port=swd --write $< --go
|
2020-04-03 12:08:06 +07:00
|
|
|
|
2020-10-08 17:19:48 +07:00
|
|
|
# flash with pyocd
|
2021-01-26 12:46:24 +07:00
|
|
|
flash-pyocd: $(BUILD)/$(PROJECT).hex
|
2020-10-08 17:19:48 +07:00
|
|
|
pyocd flash -t $(PYOCD_TARGET) $<
|
2020-10-09 13:48:08 +07:00
|
|
|
pyocd reset -t $(PYOCD_TARGET)
|
2020-10-08 17:19:48 +07:00
|
|
|
|
2021-01-26 21:19:14 +07:00
|
|
|
endif # GNU Make
|
|
|
|
|
|
|
|
#-------------- Artifacts --------------
|
|
|
|
|
|
|
|
# Create binary directory
|
|
|
|
$(BIN):
|
|
|
|
@$(MKDIR) -p $@
|
|
|
|
|
|
|
|
# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
|
2021-01-26 22:04:20 +07:00
|
|
|
# due to large size of combined artifacts, only uf2 is uploaded for now
|
2021-01-26 21:19:14 +07:00
|
|
|
copy-artifact: $(BIN)
|
|
|
|
@$(CP) $(BUILD)/$(PROJECT).uf2 $(BIN)
|
2021-01-26 22:04:20 +07:00
|
|
|
#@$(CP) $(BUILD)/$(PROJECT).bin $(BIN)
|
|
|
|
#@$(CP) $(BUILD)/$(PROJECT).hex $(BIN)
|
|
|
|
#@$(CP) $(BUILD)/$(PROJECT).elf $(BIN)
|
2021-01-26 21:19:14 +07:00
|
|
|
|