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.

156 lines
4.0KB

  1. ################################################################################
  2. #
  3. ################################################################################
  4. VERBOSE=@
  5. HELP=''
  6. STM_MCU_FAMILY=STM32F0
  7. STM_MCU_SUB_FAMILY=72
  8. STM_MCU_PIN_COUNT=C
  9. STM_MCU_CODE_SIZE=8
  10. STM_MCU_PACKAGE=T
  11. STM_MCU=$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)$(STM_MCU_PIN_COUNT)$(STM_MCU_CODE_SIZE)
  12. STM_MCU_FAMILY_LOWER=$(shell echo $(STM_MCU_FAMILY) | tr A-Z a-z)
  13. STM_MCU_CODE_SIZE_LOWER=$(shell echo $(STM_MCU_CODE_SIZE) | tr A-Z a-z)
  14. ifeq ($(VARIANT),)
  15. VARIANT = debug
  16. endif
  17. OS := $(shell uname)
  18. ifeq ($(OS),Linux)
  19. TOOLCHAIN := /usr/bin
  20. else
  21. TOOLCHAIN :=
  22. endif
  23. TOOLCHAIN_PREFIX := arm-none-eabi-
  24. CC := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gcc
  25. GDB := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gdb
  26. AS := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)as
  27. LD := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gcc
  28. OBJCOPY := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)objcopy
  29. SIZE := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)size
  30. ECHO := echo
  31. MKDIR := mkdir -p
  32. RM := rm -rf
  33. OUT = out/$(VARIANT)
  34. ELF = $(OUT)/stm.elf
  35. CFLAGS += -g
  36. CFLAGS += -mcpu=cortex-m0
  37. CFLAGS += -mthumb
  38. CFLAGS += -mfloat-abi=soft
  39. #CFLAGS += -mfpu=fpv5-sp-d16
  40. CFLAGS += '-D__weak=__attribute__((weak))'
  41. CFLAGS += '-D__packed="__attribute__((__packed__))"'
  42. CFLAGS += -DUSE_HAL_DRIVER
  43. ifeq ($(STM_MCU),STM32F072C8)
  44. CFLAGS += -D$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)xB
  45. else
  46. CFLAGS += -D$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)x$(STM_MCU_CODE_SIZE)
  47. endif
  48. CFLAGS += -Wall
  49. CFLAGS += -Werror
  50. CFLAGS += -fmessage-length=0
  51. CFLAGS += -ffunction-sections
  52. CFLAGS += -c
  53. CFLAGS += -fmessage-length=0
  54. #CFLAGS += -MMD
  55. #CFLAGS += -MP
  56. CFLAGS += -Icubemx/Inc
  57. CFLAGS += -Icubemx/Drivers/$(STM_MCU_FAMILY)xx_HAL_Driver/Inc
  58. CFLAGS += -Icubemx/Drivers/$(STM_MCU_FAMILY)xx_HAL_Driver/Inc/Legacy
  59. CFLAGS += -Icubemx/Drivers/CMSIS/Device/ST/$(STM_MCU_FAMILY)xx/Include
  60. CFLAGS += -Icubemx/Drivers/CMSIS/Include
  61. CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source
  62. CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/include
  63. CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
  64. CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0
  65. CFLAGS += -Icubemx/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
  66. CFLAGS += -Icubemx/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
  67. ifeq ($(VARIANT),debug)
  68. CFLAGS_PROJECT += -O0
  69. CFLAGS_PROJECT += -DDEBUG_LEVEL=5
  70. else ifeq ($(VARIANT),release)
  71. CFLAGS_PROJECT += -O3
  72. CFLAGS_PROJECT += -DDEBUG_LEVEL=0
  73. CFLAGS_PROJECT += -DNDEBUG
  74. endif
  75. CFLAGS_OPUS += -O3
  76. CFLAGS_OPUS += -DDEBUG_LEVEL=0
  77. CFLAGS_OPUS += -DNDEBUG
  78. LDFLAGS =
  79. LDFLAGS += -mcpu=cortex-m0
  80. LDFLAGS += -mthumb
  81. LDFLAGS += -mfloat-abi=soft
  82. #LDFLAGS += -mfpu=fpv5-sp-d16
  83. LDFLAGS += -specs=nosys.specs
  84. LDFLAGS += -specs=nano.specs
  85. LDFLAGS += -T"cubemx/$(STM_MCU)$(STM_MCU_PACKAGE)x_FLASH.ld"
  86. LDFLAGS += -Wl,-Map=$(OUT)/output.map
  87. LDFLAGS += -Wl,--gc-sections
  88. LDFLAGS += -lm
  89. # All Target
  90. HELP += 'all'
  91. all: $(ELF)
  92. # All of the sources participating in the build are defined here
  93. SOURCE =
  94. include gcc/freertos.mk
  95. include gcc/stm32.mk
  96. include gcc/middleware_usb.mk
  97. include gcc/middleware_usb_class.mk
  98. include gcc/drivers.mk
  99. include gcc/startup.mk
  100. include gcc/project.mk
  101. include openocd/openocd.mk
  102. include openocd/flash.mk
  103. ifneq ($(MAKECMDGOALS),clean)
  104. -include $(addprefix $(OUT)/,$(SOURCE:.c=.d))
  105. endif
  106. OBJC = $(SOURCE:.c=.o)
  107. OBJS = $(subst ../,,$(addprefix $(OUT)/,$(OBJC:.s=.o)))
  108. $(OUT):
  109. $(VERBOSE)$(MKDIR) $@
  110. # Tool invocations
  111. $(ELF): $(OBJS) $(OBJA) cubemx/$(STM_MCU)$(STM_MCU_PACKAGE)x_FLASH.ld | $(OUT)
  112. $(VERBOSE)$(ECHO) '[LD] $@'
  113. $(LD) $(LDFLAGS) -o $@ $(OBJS) $(OBJA) $(LIBS)
  114. $(MAKE) --no-print-directory post-build
  115. # Other Targets
  116. HELP += 'clean'
  117. clean:
  118. -$(VERBOSE)$(ECHO) '[RM] out'
  119. -$(VERBOSE)$(RM) $(OUT)
  120. post-build:
  121. -$(VERBOSE)$(ECHO) 'Generating binary and Printing size information:'
  122. $(VERBOSE)$(OBJCOPY) -O binary $(ELF) $(ELF:.elf=.bin)
  123. $(VERBOSE)$(OBJCOPY) -O binary $(ELF) $(ELF:.elf=.hex)
  124. $(VERBOSE)$(SIZE) $(ELF)
  125. -$(VERBOSE)$(ECHO) ' '
  126. .PHONY: all clean dependents help
  127. .SECONDARY: post-build
  128. help:
  129. -$(VERBOSE)$(ECHO) 'targets: $(HELP)'