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.
234 lines
6.1 KiB
234 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
|
|
dsp_dir := $(cmsis_dir)/dsp/Source
|
|
stdph_dir := $(top_dir)/stdperiph
|
|
lib_dir := $(top_dir)/lib
|
|
usb_dir := $(top_dir)/usb
|
|
codec2_dir := $(top_dir)/codec2
|
|
scripts_dir := $(top_dir)/scripts
|
|
|
|
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 :=
|
|
objs :=
|
|
TARGET_CFLAGS :=
|
|
TARGET_LDFLAGS:=
|
|
|
|
CFLAGS += -I$(cmsis_dir)/inc \
|
|
-I$(stdph_dir)/inc \
|
|
|
|
COMM_CFLAGS += -mlittle-endian -mthumb -fno-common -Wall -ffunction-sections -fdata-sections \
|
|
-ffreestanding -nostartfiles -Wno-unused-function -fno-builtin -mcpu=cortex-m4 -march=armv7e-m \
|
|
-fno-strict-aliasing -Wshadow -pipe \
|
|
|
|
include $(lib_dir)/lib.mk
|
|
|
|
target ?= vocoder
|
|
|
|
target_dir := $(top_dir)/targets/$(target)
|
|
|
|
-include $(target_dir)/target.mk
|
|
|
|
link_script ?= $(scripts_dir)/stm32f4x.lds
|
|
iap_script ?= iap.ld
|
|
|
|
CFLAGS += -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)
|
|
|
|
LDFLAGS += -L$(scripts_dir)
|
|
LDFLAGS += -Xlinker --gc-sections
|
|
LDFLAGS += -Xlinker --print-memory-usage
|
|
LDFLAGS += -Xlinker -nostdlib
|
|
LDFLAGS += -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
|
|
objs += $(usb_objs)
|
|
endif
|
|
|
|
ifeq ($(use_codec2),1)
|
|
include $(codec2_dir)/codec2.mk
|
|
CFLAGS += -DENABLE_CODEC2
|
|
objs += $(codec2_objs)
|
|
endif
|
|
|
|
CFLAGS += $(TARGET_CFLAGS)
|
|
ASFLAGS += $(TARGET_CFLAGS)
|
|
LDFLAGS += $(TARGET_LDFLAGS)
|
|
|
|
cmsis_srcs += \
|
|
$(cmsis_dir)/src/system_stm32f4xx.c
|
|
|
|
objs += $(lib_objs)
|
|
|
|
objs += $(cmsis_startup:.S=.o) $(cmsis_srcs:.c=.o)
|
|
objs += $(stdph_srcs:.c=.o)
|
|
|
|
firmware_objs := $(objs) $(${target}_objs)
|
|
iap_objs := $(objs) $(iap_srcs:.c=.o)
|
|
|
|
all: firmware
|
|
|
|
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.elf : $(scripts_dir)/boot.S iap.bin firmware.bin
|
|
$(CC) -nostdlib $< -o $@ -T $(scripts_dir)/boot.ld
|
|
|
|
boot.bin : boot.elf
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
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 $^ 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) $(scripts_dir)/*.lds *.o
|
|
|
|
distclean: clean
|
|
@rm -rf firmware.* tags *.map *.elf *.bin *.hex
|
|
|
|
|