You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
236 lines
6.1 KiB
236 lines
6.1 KiB
CROSS ?= arm-none-eabi-
|
|
|
|
CC := $(CROSS)gcc
|
|
CXX := $(CROSS)c++
|
|
AS := $(CROSS)as
|
|
OBJCOPY := $(CROSS)objcopy
|
|
LD := $(CROSS)ld
|
|
SIZE := $(CROSS)size
|
|
GDB := $(CROSS)gdb
|
|
|
|
OOCD ?= openocd
|
|
#OOCD_INTERFACE ?= stlink-v2-1
|
|
#OOCD_TRANSPORT ?= hla_swd
|
|
#OOCD_INTERFACE ?= cmsis-dap
|
|
OOCD_INTERFACE ?= jlink
|
|
OOCD_TRANSPORT ?= swd
|
|
OOCD_TARGET ?= stm32f4x
|
|
|
|
top_dir := $(shell pwd)
|
|
cmsis_dir := $(top_dir)/cmsis
|
|
stdph_dir := $(top_dir)/stdperiph
|
|
lib_dir := $(top_dir)/lib
|
|
usb_dir := $(top_dir)/usb
|
|
|
|
specs := --specs=nosys.specs --specs=nano.specs
|
|
|
|
#debug ?= 1
|
|
ifeq ($(debug),1)
|
|
debug_flags := -O0 -g -ggdb
|
|
else
|
|
debug_flags := -Os -DNDEBUG -fno-strength-reduce -fomit-frame-pointer
|
|
|
|
endif
|
|
|
|
cmsis_startup :=
|
|
cmsis_srcs :=
|
|
|
|
inc_flags += -I$(cmsis_dir)/inc \
|
|
-I$(stdph_dir)/inc \
|
|
-I$(lib_dir)/ \
|
|
|
|
COMM_CFLAGS += -mthumb -fno-common -Wall -ffunction-sections -fdata-sections \
|
|
-ffreestanding -fno-builtin -mcpu=cortex-m4 -march=armv7e-m \
|
|
-fno-strict-aliasing -Wshadow -pipe
|
|
|
|
target ?= vocoder
|
|
|
|
target_dir := $(top_dir)/targets/$(target)
|
|
|
|
-include $(target_dir)/target.mk
|
|
|
|
link_script ?= $(top_dir)/stm32f4x.lds
|
|
iap_script ?= $(top_dir)/iap.ld
|
|
|
|
inc_flags += -I$(target_dir)
|
|
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16 -D__FPU_USED=1 -D__FPU_PRESENT=1
|
|
|
|
ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
|
|
ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
|
|
|
|
TARGET_CFLAGS += $(FP_FLAGS)
|
|
TARGET_CFLAGS += $(COMM_CFLAGS)
|
|
TARGET_CFLAGS += -DUSE_STDPERIPH_DRIVER
|
|
|
|
CFLAGS += -std=gnu99
|
|
CFLAGS += $(debug_flags)
|
|
CFLAGS += $(inc_flags)
|
|
|
|
LDFLAGS += -Xlinker --gc-sections -Xlinker --print-memory-usage -Xlinker -nostdlib \
|
|
-Xlinker --sort-section=alignment -mcpu=cortex-m4 $(FP_FLAGS) \
|
|
|
|
ROMBASE ?= 0x08000000
|
|
ROMSZ ?= 2048k
|
|
RAMBASE ?= 0x20000000
|
|
RAMSZ ?= 192k
|
|
|
|
stdph_srcs := \
|
|
$(stdph_dir)/src/misc.c \
|
|
$(stdph_dir)/src/stm32f4xx_adc.c \
|
|
$(stdph_dir)/src/stm32f4xx_can.c \
|
|
$(stdph_dir)/src/stm32f4xx_cec.c \
|
|
$(stdph_dir)/src/stm32f4xx_crc.c \
|
|
$(stdph_dir)/src/stm32f4xx_cryp_aes.c \
|
|
$(stdph_dir)/src/stm32f4xx_cryp.c \
|
|
$(stdph_dir)/src/stm32f4xx_cryp_des.c \
|
|
$(stdph_dir)/src/stm32f4xx_cryp_tdes.c \
|
|
$(stdph_dir)/src/stm32f4xx_dac.c \
|
|
$(stdph_dir)/src/stm32f4xx_dbgmcu.c \
|
|
$(stdph_dir)/src/stm32f4xx_dcmi.c \
|
|
$(stdph_dir)/src/stm32f4xx_dfsdm.c \
|
|
$(stdph_dir)/src/stm32f4xx_dma2d.c \
|
|
$(stdph_dir)/src/stm32f4xx_dma.c \
|
|
$(stdph_dir)/src/stm32f4xx_dsi.c \
|
|
$(stdph_dir)/src/stm32f4xx_exti.c \
|
|
$(stdph_dir)/src/stm32f4xx_flash.c \
|
|
$(stdph_dir)/src/stm32f4xx_flash_ramfunc.c \
|
|
$(stdph_dir)/src/stm32f4xx_fmpi2c.c \
|
|
$(stdph_dir)/src/stm32f4xx_gpio.c \
|
|
$(stdph_dir)/src/stm32f4xx_hash.c \
|
|
$(stdph_dir)/src/stm32f4xx_hash_md5.c \
|
|
$(stdph_dir)/src/stm32f4xx_hash_sha1.c \
|
|
$(stdph_dir)/src/stm32f4xx_i2c.c \
|
|
$(stdph_dir)/src/stm32f4xx_iwdg.c \
|
|
$(stdph_dir)/src/stm32f4xx_lptim.c \
|
|
$(stdph_dir)/src/stm32f4xx_ltdc.c \
|
|
$(stdph_dir)/src/stm32f4xx_pwr.c \
|
|
$(stdph_dir)/src/stm32f4xx_qspi.c \
|
|
$(stdph_dir)/src/stm32f4xx_rcc.c \
|
|
$(stdph_dir)/src/stm32f4xx_rng.c \
|
|
$(stdph_dir)/src/stm32f4xx_rtc.c \
|
|
$(stdph_dir)/src/stm32f4xx_sai.c \
|
|
$(stdph_dir)/src/stm32f4xx_sdio.c \
|
|
$(stdph_dir)/src/stm32f4xx_spdifrx.c \
|
|
$(stdph_dir)/src/stm32f4xx_spi.c \
|
|
$(stdph_dir)/src/stm32f4xx_syscfg.c \
|
|
$(stdph_dir)/src/stm32f4xx_tim.c \
|
|
$(stdph_dir)/src/stm32f4xx_usart.c \
|
|
$(stdph_dir)/src/stm32f4xx_wwdg.c \
|
|
|
|
ifeq ($(use_usb),1)
|
|
include $(usb_dir)/usb.mk
|
|
endif
|
|
|
|
CFLAGS += $(TARGET_CFLAGS)
|
|
ASFLAGS += $(TARGET_CFLAGS)
|
|
|
|
cmsis_srcs += \
|
|
$(cmsis_dir)/src/system_stm32f4xx.c
|
|
|
|
lib_srcs += \
|
|
$(lib_dir)/gcc_stubs.c \
|
|
$(lib_dir)/tick.c \
|
|
$(lib_dir)/printf.c \
|
|
$(lib_dir)/fifo.c \
|
|
$(lib_dir)/cmd.c \
|
|
$(lib_dir)/gpio.c \
|
|
$(lib_dir)/a3k.c \
|
|
$(lib_dir)/serial.c \
|
|
$(lib_dir)/vrom.c \
|
|
$(lib_dir)/utils.c \
|
|
$(lib_dir)/sdram.c \
|
|
$(lib_dir)/is42s32800g.c \
|
|
$(lib_dir)/timer.c \
|
|
$(lib_dir)/ymodem.c \
|
|
$(lib_dir)/eeprom.c \
|
|
$(lib_dir)/bkp_sram.c \
|
|
$(lib_dir)/flash_if.c \
|
|
$(lib_dir)/iwdg.c \
|
|
$(lib_dir)/sdio_sd.c \
|
|
|
|
objs += $(cmsis_startup:.S=.o) $(cmsis_srcs:.c=.o)
|
|
objs += $(stdph_srcs:.c=.o)
|
|
objs += $(lib_srcs:.c=.o)
|
|
objs += $(usb_srcs:.c=.o)
|
|
|
|
firmware_objs := $(objs) $(${target}_objs)
|
|
iap_objs := $(objs) $(iap_srcs:.c=.o)
|
|
|
|
all: firmware iap
|
|
|
|
iap : iap.bin iap.hex
|
|
|
|
firmware : firmware.bin firmware.hex
|
|
|
|
firmware.elf: | $(link_script)
|
|
|
|
%.hex : %.elf
|
|
$(OBJCOPY) -O ihex $< $@
|
|
|
|
%.bin : %.elf
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
firmware.elf : $(firmware_objs)
|
|
|
|
$(CC) $(LDFLAGS) -Wl,-Map="$@.map" -T $(link_script) $(specs) $^ -o $@
|
|
@$(SIZE) -Bd $@
|
|
|
|
iap.elf : $(iap_objs)
|
|
$(CC) $(LDFLAGS) -Wl,-Map="$@.map" -T $(iap_script) $(specs) $^ -o $@
|
|
@$(SIZE) -Bd $@
|
|
|
|
%.o : %.s
|
|
@echo "compiling $(notdir $<)"
|
|
@$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
%.o : %.S
|
|
@echo "compiling $(notdir $<)"
|
|
@$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
%.lds : %.lds.S
|
|
$(CC) -E -P -DROMBASE=$(ROMBASE) -DROMSZ=$(ROMSZ) -DRAMBASE=$(RAMBASE) -DRAMSZ=$(RAMSZ) -o $@ $<
|
|
|
|
BINARY ?= firmware
|
|
ifeq ($(OOCD_FILE),)
|
|
flash: $(BINARY).elf
|
|
@printf " FLASH $<\n"
|
|
(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
|
|
$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
|
|
-c "transport select $(OOCD_TRANSPORT)" \
|
|
-f target/$(OOCD_TARGET).cfg \
|
|
-c "program $(BINARY).elf verify reset exit" \
|
|
$(NULL)
|
|
else
|
|
flash: $(BINARY).elf
|
|
@printf " FLASH $<\n"
|
|
(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
|
|
$(OOCD) -f $(OOCD_FILE) \
|
|
-c "program $(BINARY).elf verify reset exit" \
|
|
$(NULL)
|
|
endif
|
|
|
|
boot.bin : iap.bin firmware.bin merge.py
|
|
@rm -f boot.bin
|
|
@echo "make boot.bin"
|
|
@python3 merge.py
|
|
|
|
download: boot.bin
|
|
$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
|
|
-c "transport select $(OOCD_TRANSPORT)" \
|
|
-f target/$(OOCD_TARGET).cfg \
|
|
-c "init" -c "reset init" -c "halt" \
|
|
-c "flash write_image erase boot.bin 0x08000000" \
|
|
-c "reset run" -c "shutdown"
|
|
|
|
st-flash: $(BINARY).hex
|
|
st-flash --format ihex write $<
|
|
|
|
debug: $(BINARY).elf
|
|
$(GDB) $^ -x $(top_dir)/gdb/init.gdb
|
|
|
|
clean:
|
|
@rm -rf $(objs) $(firmware_objs) $(iap_objs) *.lds *.o
|
|
|
|
distclean: clean
|
|
@rm -rf firmware.* tags *.map *.elf *.bin *.hex
|
|
|
|
|