Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ######################################
  2. # Makefile by CubeMX2Makefile.py
  3. ######################################
  4. ######################################
  5. # target
  6. ######################################
  7. TARGET = firmware
  8. ######################################
  9. # building variables
  10. ######################################
  11. # debug build?
  12. DEBUG = 1
  13. # optimization
  14. OPT = -O0
  15. #######################################
  16. # pathes
  17. #######################################
  18. # Build path
  19. BUILD_DIR = build
  20. ######################################
  21. # source
  22. ######################################
  23. C_SOURCES = \
  24. Src/main.c \
  25. Src/stm32f0xx_it.c \
  26. Src/system_stm32f0xx.c \
  27. Src/stm32f0xx_hal_msp.c \
  28. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c \
  29. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c \
  30. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c \
  31. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c \
  32. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c \
  33. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c \
  34. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart.c \
  35. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c \
  36. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c \
  37. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c \
  38. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c \
  39. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c \
  40. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart_ex.c \
  41. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c \
  42. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c \
  43. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c
  44. ASM_SOURCES = \
  45. Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f030x6.s
  46. #######################################
  47. # binaries
  48. #######################################
  49. CC = arm-none-eabi-gcc
  50. AS = arm-none-eabi-gcc -x assembler-with-cpp
  51. CP = arm-none-eabi-objcopy
  52. AR = arm-none-eabi-ar
  53. SZ = arm-none-eabi-size
  54. HEX = $(CP) -O ihex
  55. BIN = $(CP) -O binary -S
  56. #######################################
  57. # CFLAGS
  58. #######################################
  59. # macros for gcc
  60. AS_DEFS =
  61. C_DEFS = -D'__weak=__attribute__((weak))' -D'__packed=__attribute__((__packed__))' -DUSE_HAL_DRIVER -DSTM32F030x6
  62. # includes for gcc
  63. AS_INCLUDES =
  64. C_INCLUDES = -IDrivers/CMSIS/Device/ST/STM32F0xx/Include
  65. C_INCLUDES += -IDrivers/CMSIS/Include
  66. C_INCLUDES += -IDrivers/STM32F0xx_HAL_Driver/Inc
  67. C_INCLUDES += -IDrivers/STM32F0xx_HAL_Driver/Inc/Legacy
  68. C_INCLUDES += -IInc
  69. # compile gcc flags
  70. ASFLAGS = -mthumb -mcpu=cortex-m0 $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  71. CFLAGS = -mthumb -mcpu=cortex-m0 $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  72. ifeq ($(DEBUG), 1)
  73. CFLAGS += -g -gdwarf-2
  74. endif
  75. # Generate dependency information
  76. CFLAGS += -std=c99 -MD -MP -MF .dep/$(@F).d
  77. #######################################
  78. # LDFLAGS
  79. #######################################
  80. # link script
  81. LDSCRIPT = STM32F030F4Px_FLASH.ld
  82. # libraries
  83. LIBS = -lc -lm -lnosys
  84. LIBDIR =
  85. LDFLAGS = -mthumb -mcpu=cortex-m0 -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  86. # default action: build all
  87. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  88. #######################################
  89. # build the application
  90. #######################################
  91. # list of objects
  92. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  93. vpath %.c $(sort $(dir $(C_SOURCES)))
  94. # list of ASM program objects
  95. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  96. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  97. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  98. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  99. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  100. $(AS) -c $(CFLAGS) $< -o $@
  101. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  102. $(CC) $(OBJECTS) $(LDFLAGS) -o $@
  103. $(SZ) $@
  104. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  105. $(HEX) $< $@
  106. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  107. $(BIN) $< $@
  108. $(BUILD_DIR):
  109. mkdir -p $@
  110. #######################################
  111. # clean up
  112. #######################################
  113. clean:
  114. -rm -fR .dep $(BUILD_DIR)
  115. #######################################
  116. # dependencies
  117. #######################################
  118. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  119. .PHONY: clean all
  120. # *** EOF ***