|
|
|
TOPDIR := $(shell pwd)
|
|
|
|
STDPERIPH_DIR := $(TOPDIR)/stdperiph
|
|
|
|
USBFS_DIR := $(TOPDIR)/usbd
|
|
|
|
CMSIS_DIR := $(TOPDIR)/CMSIS
|
|
|
|
TGT_DIR := $(TOPDIR)/target
|
|
|
|
LDSCRIPT_DIR := $(TOPDIR)/ldscripts
|
|
|
|
TINYUSB_DIR := $(TOPDIR)/tinyusb
|
|
|
|
DAP_DIR := $(TOPDIR)/dap
|
|
|
|
|
|
|
|
XTAL_HZ := 8000000
|
|
|
|
|
|
|
|
CROSS_COMPILE ?= arm-none-eabi-
|
|
|
|
CC := $(CROSS_COMPILE)gcc
|
|
|
|
AR := $(CROSS_COMPILE)ar
|
|
|
|
OBJCOPY:= $(CROSS_COMPILE)objcopy
|
|
|
|
GDB := $(CROSS_COMPILE)gdb
|
|
|
|
|
|
|
|
TARGET_APP_BASE ?= 0x08005000
|
|
|
|
|
|
|
|
DEBUG_CFLAGS += -g -ggdb
|
|
|
|
|
|
|
|
#DEBUG_CFLAGS += -Os
|
|
|
|
|
|
|
|
CFLAGS += -mlittle-endian -mthumb -fno-common -Wall
|
|
|
|
CFLAGS += -ffunction-sections -fdata-sections -ffreestanding -nostartfiles
|
|
|
|
CFLAGS += -Wno-unused-function -fno-builtin -fno-strict-aliasing -Wshadow -pipe
|
|
|
|
CFLAGS += -mcpu=cortex-m3 -march=armv7-m
|
|
|
|
CFLAGS += -std=gnu99
|
|
|
|
|
|
|
|
ifeq ($(XTAL_HZ), 8000000)
|
|
|
|
XTAL_FLAGS := -DHXTAL_VALUE_8M
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(XTAL_HZ), 25000000)
|
|
|
|
XTAL_FLAGS := -DHXTAL_VALUE_25M
|
|
|
|
endif
|
|
|
|
|
|
|
|
CFLAGS += -DHXTAL_VALUE=$(XTAL_HZ)
|
|
|
|
CFLAGS += $(XTAL_FLAGS)
|
|
|
|
CFLAGS += -DUSE_STDPERIPH_DRIVER
|
|
|
|
CFLAGS += -DGD32F10X_MD
|
|
|
|
CFLAGS += -DTARGET_APP_BASE=$(TARGET_APP_BASE)
|
|
|
|
|
|
|
|
CFLAGS += -I$(CMSIS_DIR)
|
|
|
|
CFLAGS += -I$(CMSIS_DIR)/GD/GD32F10x/inc
|
|
|
|
CFLAGS += -I$(STDPERIPH_DIR)/inc
|
|
|
|
CFLAGS += -I$(USBFS_DIR)/inc
|
|
|
|
CFLAGS += -I$(TINYUSB_DIR)/src
|
|
|
|
CFLAGS += -I$(TINYUSB_DIR)/src/device
|
|
|
|
CFLAGS += -I$(DAP_DIR)
|
|
|
|
CFLAGS += -I$(TGT_DIR)
|
|
|
|
CFLAGS += -I$(TGT_DIR)/boot
|
|
|
|
|
|
|
|
CFLAGS += $(DEBUG_CFLAGS)
|
|
|
|
|
|
|
|
LDFLAGS += -L$(LDSCRIPT_DIR)
|
|
|
|
LDFLAGS += -Xlinker --gc-sections
|
|
|
|
LDFLAGS += -Xlinker --print-memory-usage
|
|
|
|
LDFLAGS += -Xlinker -nostdlib
|
|
|
|
LDFLAGS += -Xlinker --sort-section=alignment -mcpu=cortex-m4
|
|
|
|
LDFLAGS += --specs=nosys.specs --specs=nano.specs
|
|
|
|
|
|
|
|
stdperiph_srcs := \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_adc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_bkp.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_can.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_crc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_dac.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_dbg.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_dma.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_enet.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_exmc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_exti.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_fmc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_fwdgt.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_gpio.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_i2c.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_misc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_pmu.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_rcu.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_rtc.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_sdio.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_spi.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_timer.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_usart.c \
|
|
|
|
$(STDPERIPH_DIR)/src/gd32f10x_wwdgt.c \
|
|
|
|
|
|
|
|
objects := $(stdperiph_srcs:.c=.o)
|
|
|
|
|
|
|
|
usbfs_srcs := \
|
|
|
|
$(USBFS_DIR)/src/usbd_core.c \
|
|
|
|
$(USBFS_DIR)/src/usbd_int.c \
|
|
|
|
$(USBFS_DIR)/src/usbd_pwr.c \
|
|
|
|
$(USBFS_DIR)/src/usbd_std.c \
|
|
|
|
|
|
|
|
objects += $(usbfs_srcs:.c=.o)
|
|
|
|
|
|
|
|
tinyusb_srcs := \
|
|
|
|
$(TINYUSB_DIR)/src/tusb.c \
|
|
|
|
$(TINYUSB_DIR)/src/common/tusb_fifo.c \
|
|
|
|
$(TINYUSB_DIR)/src/device/usbd.c \
|
|
|
|
$(TINYUSB_DIR)/src/device/usbd_control.c
|
|
|
|
|
|
|
|
objects += $(tinyusb_srcs:.c=.o)
|
|
|
|
|
|
|
|
dap_srcs := \
|
|
|
|
$(DAP_DIR)/DAP.c \
|
|
|
|
$(DAP_DIR)/DAP_vendor.c \
|
|
|
|
$(DAP_DIR)/JTAG_DP.c \
|
|
|
|
$(DAP_DIR)/SW_DP.c \
|
|
|
|
|
|
|
|
objects += $(dap_srcs:.c=.o)
|
|
|
|
|
|
|
|
objects += $(CMSIS_DIR)/GD/GD32F10x/src/system_gd32f10x.o
|
|
|
|
objects += $(CMSIS_DIR)/GD/GD32F10x/src/GCC/startup_gd32f10x_md.o
|
|
|
|
objects += $(CMSIS_DIR)/GD/GD32F10x/src/GCC/stub.o
|
|
|
|
|
|
|
|
tgt_frontpanel_srcs := \
|
|
|
|
$(TGT_DIR)/tick.c \
|
|
|
|
$(TGT_DIR)/cmd.c \
|
|
|
|
$(TGT_DIR)/fifo.c \
|
|
|
|
$(TGT_DIR)/terminal.c \
|
|
|
|
$(TGT_DIR)/target.c \
|
|
|
|
$(TGT_DIR)/usb/usb_driver.c \
|
|
|
|
$(TGT_DIR)/usb/frontpanel_core.c \
|
|
|
|
$(TGT_DIR)/fp/tgt_frontpanel.c \
|
|
|
|
$(TGT_DIR)/fp/main.c \
|
|
|
|
|
|
|
|
tgt_frontpanel_objs := $(tgt_frontpanel_srcs:.c=.o) $(objects)
|
|
|
|
|
|
|
|
tgt_dfu_srcs := \
|
|
|
|
$(TGT_DIR)/boot/main.c \
|
|
|
|
$(TGT_DIR)/usb_driver.c \
|
|
|
|
$(TGT_DIR)/usbd_cdc.c \
|
|
|
|
$(TGT_DIR)/target.c \
|
|
|
|
|
|
|
|
tgt_dfu_objs := $(tgt_dfu_srcs:.c=.o) $(objects)
|
|
|
|
|
|
|
|
all: dfu.bin dfu.hex
|
|
|
|
|
|
|
|
dfu.elf : $(tgt_dfu_objs)
|
|
|
|
@echo "linking $@"
|
|
|
|
@$(CC) $(LDFLAGS) -Wl,-Map="$@.map" $^ -o $@ -T dfu.ld
|
|
|
|
|
|
|
|
%.o : %.S
|
|
|
|
@echo "compiling $(notdir $<)"
|
|
|
|
@$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
%.o : %.c
|
|
|
|
@echo "compiling $(notdir $<)"
|
|
|
|
@$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
%.hex : %.elf
|
|
|
|
$(OBJCOPY) -O ihex $< $@
|
|
|
|
|
|
|
|
%.ld : %.ld.S
|
|
|
|
$(CC) -E -P -DROMBASE=$(TARGET_APP_BASE) -o $@ $<
|
|
|
|
|
|
|
|
%.bin : %.elf
|
|
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
|
|
|
|
flash_boot: dfu.hex
|
|
|
|
@echo "flasing $^ ..."
|
|
|
|
@pyocd flash $^
|
|
|
|
|
|
|
|
flash_fp: frontpanel.hex
|
|
|
|
@echo "flasing $^ ..."
|
|
|
|
@pyocd flash $^
|
|
|
|
|
|
|
|
dbg_dfu: dfu.elf
|
|
|
|
@echo "Please run pyocd gdbserver --persist"
|
|
|
|
@$(GDB) -ex "target remote localhost:3333" $^
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo "clean ..."
|
|
|
|
@rm -rf $(objects) $(tgt_frontpanel_objs) $(tgt_dfu_objs) $(TGT_DIR)/*.o ldscripts/frontpanel.ld
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
@rm -rf *.elf *.map *.bin *.hex
|