|
| 1 | +# Configuration ################################################################ |
| 2 | +# Target name |
| 3 | +TARGET = stm32-bootloader |
| 4 | +# Debug configuration selector |
| 5 | +DEBUG = 1 |
| 6 | +# Optimization level |
| 7 | +OPT = -Og |
| 8 | +# Build path |
| 9 | +BUILD_DIR = build |
| 10 | + |
| 11 | +# Defines ###################################################################### |
| 12 | +# Assembly defines |
| 13 | +ASM_DEFS = |
| 14 | + |
| 15 | +# C defines |
| 16 | +C_DEFS = \ |
| 17 | +-DUSE_HAL_DRIVER \ |
| 18 | +-DSTM32L496xx |
| 19 | + |
| 20 | +# Includes ##################################################################### |
| 21 | +# Assembly includes |
| 22 | +ASM_INCLUDES = |
| 23 | + |
| 24 | +# C includes |
| 25 | +C_INCLUDES = \ |
| 26 | +-I../include \ |
| 27 | +-I../../../lib/stm32-bootloader \ |
| 28 | +-I../../../lib/fatfs \ |
| 29 | +-I../../../drivers/CMSIS/Include \ |
| 30 | +-I../../../drivers/CMSIS/Device/ST/STM32L4xx/Include \ |
| 31 | +-I../../../drivers/STM32L4xx_HAL_Driver/Inc |
| 32 | + |
| 33 | +# Source files ################################################################# |
| 34 | +# Assembly source files |
| 35 | +ASM_SOURCES = \ |
| 36 | +startup_stm32l496xx.s |
| 37 | + |
| 38 | +# C source files |
| 39 | +C_SOURCES = \ |
| 40 | +$(wildcard ../source/*.c) \ |
| 41 | +$(wildcard ../../../lib/stm32-bootloader/*.c) \ |
| 42 | +$(wildcard ../../../lib/fatfs/*.c) \ |
| 43 | +../../../lib/fatfs/option/unicode.c \ |
| 44 | +$(wildcard ../../../drivers/STM32L4xx_HAL_Driver/Src/*.c) |
| 45 | + |
| 46 | +# Toolchain #################################################################### |
| 47 | +CUSTOMPATH = "C:/Program Files (x86)/GNU Tools ARM Embedded/8 2019-q3-update/bin" |
| 48 | +PREFIX = arm-none-eabi- |
| 49 | +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) |
| 50 | +# either it can be added to the PATH environment variable. |
| 51 | +ifdef GCC_PATH |
| 52 | +CC = $(GCC_PATH)/$(PREFIX)gcc |
| 53 | +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp |
| 54 | +CP = $(GCC_PATH)/$(PREFIX)objcopy |
| 55 | +SZ = $(GCC_PATH)/$(PREFIX)size |
| 56 | +else |
| 57 | +CC = $(CUSTOMPATH)/$(PREFIX)gcc |
| 58 | +AS = $(CUSTOMPATH)/$(PREFIX)gcc -x assembler-with-cpp |
| 59 | +CP = $(CUSTOMPATH)/$(PREFIX)objcopy |
| 60 | +SZ = $(CUSTOMPATH)/$(PREFIX)size |
| 61 | +endif |
| 62 | +HEX = $(CP) -O ihex |
| 63 | +BIN = $(CP) -O binary -S |
| 64 | + |
| 65 | +# Compiler flags ############################################################### |
| 66 | +# CPU |
| 67 | +CPU = -mcpu=cortex-m4 |
| 68 | +# FPU |
| 69 | +FPU = -mfpu=fpv4-sp-d16 |
| 70 | +# Float-abi |
| 71 | +FLOAT-ABI = -mfloat-abi=hard |
| 72 | +# MCU |
| 73 | +MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) |
| 74 | + |
| 75 | +# Create compiler flags |
| 76 | +ASFLAGS = $(MCU) $(ASM_DEFS) $(ASM_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections |
| 77 | +CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections |
| 78 | + |
| 79 | +# Generate debug information |
| 80 | +ifeq ($(DEBUG), 1) |
| 81 | +CFLAGS += -g -gdwarf-2 |
| 82 | +endif |
| 83 | + |
| 84 | +# Generate dependency information |
| 85 | +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" |
| 86 | + |
| 87 | +# Linker flags ################################################################# |
| 88 | +# Linker script |
| 89 | +LDSCRIPT = stm32l496xx_flash.ld |
| 90 | + |
| 91 | +# Libraries |
| 92 | +LIBS = -lc -lm -lnosys |
| 93 | +LIBDIR = |
| 94 | + |
| 95 | +# Create linker flags |
| 96 | +LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections |
| 97 | + |
| 98 | +# Build target ################################################################# |
| 99 | +# Default: build all |
| 100 | +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin |
| 101 | + |
| 102 | +# List of C objects |
| 103 | +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) |
| 104 | +vpath %.c $(sort $(dir $(C_SOURCES))) |
| 105 | + |
| 106 | +# List of ASM objects |
| 107 | +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) |
| 108 | +vpath %.s $(sort $(dir $(ASM_SOURCES))) |
| 109 | + |
| 110 | +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) |
| 111 | + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ |
| 112 | + |
| 113 | +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) |
| 114 | + $(AS) -c $(ASFLAGS) $< -o $@ |
| 115 | + |
| 116 | +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile |
| 117 | + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ |
| 118 | + $(SZ) $@ |
| 119 | + |
| 120 | +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) |
| 121 | + $(HEX) $< $@ |
| 122 | + |
| 123 | +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) |
| 124 | + $(BIN) $< $@ |
| 125 | + |
| 126 | +$(BUILD_DIR): |
| 127 | + mkdir $@ |
| 128 | + |
| 129 | +# Clean |
| 130 | +clean: |
| 131 | + -rm -rf $(BUILD_DIR) |
| 132 | + |
| 133 | +# Dependencies |
| 134 | +-include $(wildcard $(BUILD_DIR)/*.d) |
0 commit comments