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.
206 lines
5.2 KiB
206 lines
5.2 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_INTERFACE ?= jlink
|
|
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
|
|
|
|
link_script := $(top_dir)/stm32f4x.lds
|
|
specs := --specs=nosys.specs --specs=nano.specs
|
|
|
|
debug ?= 1
|
|
ifeq ($(debug),1)
|
|
debug_flags := -O0 -g -ggdb
|
|
else
|
|
debug_flags := -Os -DNDEBUG
|
|
endif
|
|
|
|
cmsis_startup :=
|
|
cmsis_srcs :=
|
|
|
|
inc_flags += -I$(cmsis_dir)/inc \
|
|
-I$(stdph_dir)/inc \
|
|
-I$(lib_dir)/ \
|
|
-I$(top_dir)/src
|
|
|
|
COMM_CFLAGS += -mthumb -fno-common -Wall -ffunction-sections -fdata-sections \
|
|
-ffreestanding -fno-builtin -mcpu=cortex-m4
|
|
|
|
TARGET ?= f429
|
|
|
|
-include targets.mk
|
|
|
|
FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16 -D__FPU_USED=1 -D__FPU_PRESENT=1
|
|
|
|
TARGET_CFLAGS += $(FP_FLAGS)
|
|
TARGET_CFLAGS += $(COMM_CFLAGS)
|
|
TARGET_CFLAGS += -DUSE_STDPERIPH_DRIVER
|
|
|
|
CFLAGS += -std=gnu99
|
|
CFLAGS += $(debug_flags)
|
|
CFLAGS += $(inc_flags)
|
|
CFLAGS += $(TARGET_CFLAGS)
|
|
ASFLAGS += $(TARGET_CFLAGS)
|
|
|
|
LDFLAGS += -Xlinker --gc-sections -Xlinker --print-memory-usage \
|
|
-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)
|
|
usb_srcs := \
|
|
$(usb_dir)/otg/src/usb_core.c \
|
|
$(usb_dir)/otg/src/usb_dcd_int.c \
|
|
$(usb_dir)/otg/src/usb_dcd.c \
|
|
$(usb_dir)/core/src/usbd_core.c \
|
|
$(usb_dir)/core/src/usbd_ioreq.c \
|
|
$(usb_dir)/core/src/usbd_req.c \
|
|
$(usb_dir)/cdc/src/usbd_cdc_core.c \
|
|
|
|
CFLAGS += -I$(usb_dir)/core/inc -I$(usb_dir)/otg/inc\
|
|
-I$(usb_dir)/cdc/inc -DUSE_USB_OTG_FS \
|
|
-DUSE_ULPI_PHY
|
|
|
|
lib_srcs += $(lib_dir)/usb/usbd_cdc.c
|
|
lib_srcs += $(lib_dir)/usb/usbd_desc.c
|
|
lib_srcs += $(lib_dir)/usb/usb_bsp.c
|
|
CFLAGS += -I$(lib_dir)/usb
|
|
endif
|
|
|
|
|
|
cmsis_srcs += \
|
|
$(cmsis_dir)/src/system_stm32f4xx.c
|
|
|
|
lib_srcs += \
|
|
$(lib_dir)/gcc_stubs.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)/fmc_sdram.c \
|
|
|
|
project_srcs += \
|
|
$(top_dir)/src/i2c.c \
|
|
$(top_dir)/src/main.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)
|
|
objs += $(project_srcs:.c=.o)
|
|
|
|
firmware.elf: | $(link_script)
|
|
|
|
all: firmware.bin firmware.hex
|
|
|
|
firmware.hex : firmware.elf
|
|
$(OBJCOPY) -O ihex $< $@
|
|
|
|
firmware.bin : firmware.elf
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
firmware.elf : $(objs)
|
|
$(CC) $(LDFLAGS) -Wl,-Map="$@.map" -T $(link_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 swd" \
|
|
-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
|
|
|
|
dbg: $(BINARY).elf
|
|
$(GDB) $^ -x $(top_dir)/gdb/init.gdb
|
|
|
|
clean:
|
|
@rm -rf $(objs) *.lds
|
|
|
|
distclean: clean
|
|
@rm -rf firmware.* tags
|
|
|
|
|