94 lines
2.2 KiB
Makefile
94 lines
2.2 KiB
Makefile
TARGET = stm32_project
|
|
|
|
BUILD_DIR = ./build
|
|
|
|
SRC_DIRS = \
|
|
./src \
|
|
./STM32F1xx_HAL_Driver/Src
|
|
|
|
SRCS := \
|
|
$(shell find $(SRC_DIRS) -name *.c -or -name *.s) \
|
|
./CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f102xb.s \
|
|
|
|
|
|
INC_DIRS := \
|
|
$(shell find $(SRC_DIRS) -type d) \
|
|
./CMSIS/Include \
|
|
./CMSIS/Device/ST/STM32F1xx/Include \
|
|
./inc \
|
|
./STM32F1xx_HAL_Driver/Inc
|
|
|
|
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
|
DEPS := $(OBJS:.o=.d)
|
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
|
|
|
CC = arm-none-eabi-gcc
|
|
AS = arm-none-eabi-as
|
|
CFLAGS := -MMD -MP -g
|
|
CFLAGS += -DSTM32F103xB
|
|
CFLAGS += -Os
|
|
CFLAGS += -mcpu=cortex-m3 -mfloat-abi=soft -mthumb --specs=nosys.specs -fdata-sections -ffunction-sections
|
|
CFLAGS += -Wall -Wextra
|
|
CFLAGS += -T ./CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/linker/STM32F103XB_FLASH.ld
|
|
CFLAGS += $(INC_FLAGS)
|
|
LDFLAGS = -Wl,--gc-sections
|
|
|
|
SIZECMD = arm-none-eabi-size --format=berkly $(BUILD_DIR)/$(TARGET).elf
|
|
OPENOCDCFG = -f "./ssi_converter_board.cfg"
|
|
|
|
all: $(BUILD_DIR)/$(TARGET).elf
|
|
$(SIZECMD)
|
|
|
|
#executable
|
|
$(BUILD_DIR)/$(TARGET).elf: $(OBJS)
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
|
|
# assembly
|
|
$(BUILD_DIR)/%.s.o: %.s
|
|
$(MKDIR_P) $(dir $@)
|
|
$(AS) $(ASFLAGS) -c $< -o $@
|
|
|
|
# c source
|
|
$(BUILD_DIR)/%.c.o: %.c
|
|
$(MKDIR_P) $(dir $@)
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
|
|
|
-include $(DEPS)
|
|
MKDIR_P ?= mkdir -p
|
|
|
|
.PHONY: clean flash debug _debug ocdserver gdbgui
|
|
|
|
flash: $(BUILD_DIR)/$(TARGET).elf
|
|
$(SIZECMD)
|
|
openocd $(OPENOCDCFG) -c "program $(BUILD_DIR)/${TARGET}.elf verify reset exit"
|
|
|
|
debug: $(BUILD_DIR)/$(TARGET).elf
|
|
make _debug -j2
|
|
|
|
debug_attach:
|
|
make _debug_attach -j2
|
|
|
|
_debug: ocdserver gdbgui
|
|
_debug_attach: ocdserver gdbgui_attach
|
|
|
|
ocdserver:
|
|
openocd $(OPENOCDCFG) -c "gdb_port 3333"
|
|
|
|
gdbgui: $(BUILD_DIR)/$(TARGET).elf
|
|
sleep 1s
|
|
gdbgui -g arm-none-eabi-gdb \
|
|
--gdb-args "-ex \"target remote localhost:3333\" \
|
|
-ex \"load $(BUILD_DIR)/$(TARGET).elf \" \
|
|
-ex \"file $(BUILD_DIR)/$(TARGET).elf \" \
|
|
-ex \"monitor reset halt\""
|
|
|
|
gdbgui_attach: $(BUILD_DIR)/$(TARGET).elf
|
|
sleep 1s
|
|
gdbgui -g arm-none-eabi-gdb \
|
|
--gdb-args "-ex \"target remote localhost:3333\" \
|
|
-ex \"file $(BUILD_DIR)/$(TARGET).elf \" \
|
|
-ex \"monitor halt\""
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|