Makefile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. ##########################################################################################################################
  2. # File automatically-generated by tool: [projectgenerator] version: [3.5.2] date: [Tue May 26 23:27:59 OMST 2020]
  3. ##########################################################################################################################
  4. # ------------------------------------------------
  5. # Generic Makefile (based on gcc)
  6. #
  7. # ChangeLog :
  8. # 2017-02-10 - Several enhancements + project update mode
  9. # 2015-07-22 - first version
  10. # ------------------------------------------------
  11. ######################################
  12. # target
  13. ######################################
  14. TARGET = target_prod
  15. ######################################
  16. # building variables
  17. ######################################
  18. # debug build?
  19. DEBUG = 1
  20. # optimization
  21. OPT = -Og
  22. #######################################
  23. # paths
  24. #######################################
  25. PROJECT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
  26. # Build path
  27. BUILD_DIR = build
  28. ######################################
  29. # source
  30. ######################################
  31. C_SOURCES =
  32. CPP_SOURCES =
  33. ASM_SOURCES =
  34. C_DEFS =
  35. # Target
  36. C_SOURCES += \
  37. Src/main.c \
  38. Src/freertos.c \
  39. Src/stm32l4xx_it.c \
  40. Src/stm32l4xx_hal_msp.c \
  41. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c \
  42. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c \
  43. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c \
  44. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c \
  45. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c \
  46. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c \
  47. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c \
  48. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c \
  49. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c \
  50. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c \
  51. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c \
  52. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c \
  53. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c \
  54. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c \
  55. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c \
  56. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c \
  57. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c \
  58. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c \
  59. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c \
  60. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c \
  61. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_spi.c \
  62. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_spi_ex.c \
  63. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c \
  64. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c \
  65. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pcd.c \
  66. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pcd_ex.c \
  67. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usb.c \
  68. Src/system_stm32l4xx.c \
  69. Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
  70. Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
  71. Middlewares/Third_Party/FreeRTOS/Source/list.c \
  72. Middlewares/Third_Party/FreeRTOS/Source/queue.c \
  73. Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \
  74. Middlewares/Third_Party/FreeRTOS/Source/tasks.c \
  75. Middlewares/Third_Party/FreeRTOS/Source/timers.c \
  76. Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c \
  77. Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_1.c \
  78. Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \
  79. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c \
  80. Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c \
  81. Src/usb_device.c \
  82. Src/usbd_conf.c \
  83. Src/usbd_desc.c \
  84. Src/usbd_cdc_if.c \
  85. Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \
  86. Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
  87. Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
  88. Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
  89. C_SOURCES += Src/flipper_hal.c
  90. C_DEFS += \
  91. -DUSE_HAL_DRIVER \
  92. -DSTM32L476xx \
  93. -DBUTON_INVERT=false \
  94. -DDEBUG_UART=huart1
  95. ASM_SOURCES += \
  96. startup_stm32l476xx.s
  97. # Core
  98. CPP_SOURCES += ../core/app.cpp
  99. C_SOURCES += ../core/log.c
  100. C_SOURCES += ../core/tty_uart.c
  101. C_SOURCES += ../core/furi.c
  102. C_SOURCES += ../core/furi_ac.c
  103. # System applications
  104. ifeq ($(TEST), 1)
  105. C_SOURCES += ../applications/tests/furiac_test.c
  106. C_SOURCES += ../applications/tests/furi_record_test.c
  107. C_SOURCES += ../applications/tests/test_index.c
  108. C_DEFS += -DTEST
  109. endif
  110. # Examples
  111. ifeq ($(EXAMPLE_BLINK), 1)
  112. C_SOURCES += ../applications/examples/blink.c
  113. C_DEFS += -DEXAMPLE_BLINK
  114. endif
  115. ifeq ($(EXAMPLE_UART_WRITE), 1)
  116. C_SOURCES += ../applications/examples/uart_write.c
  117. C_DEFS += -DEXAMPLE_UART_WRITE
  118. endif
  119. # User application
  120. # Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
  121. #######################################
  122. # binaries
  123. #######################################
  124. PREFIX = arm-none-eabi-
  125. # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
  126. # either it can be added to the PATH environment variable.
  127. ifdef GCC_PATH
  128. CC = $(GCC_PATH)/$(PREFIX)gcc
  129. CPP = $(GCC_PATH)/$(PREFIX)g++
  130. AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
  131. CP = $(GCC_PATH)/$(PREFIX)objcopy
  132. SZ = $(GCC_PATH)/$(PREFIX)size
  133. else
  134. CC = $(PREFIX)gcc
  135. CPP = $(PREFIX)g++
  136. AS = $(PREFIX)gcc -x assembler-with-cpp
  137. CP = $(PREFIX)objcopy
  138. SZ = $(PREFIX)size
  139. endif
  140. HEX = $(CP) -O ihex
  141. BIN = $(CP) -O binary -S
  142. #######################################
  143. # Rust library
  144. #######################################
  145. RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
  146. RUST_LIB_NAME = flipper_core
  147. RUST_LIB_TARGET = thumbv7em-none-eabihf
  148. RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
  149. ifeq ($(DEBUG), 1)
  150. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
  151. else
  152. RUST_LIB_FLAGS += --release
  153. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
  154. endif
  155. RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build -p flipper-core $(RUST_LIB_FLAGS)
  156. #######################################
  157. # CFLAGS
  158. #######################################
  159. # cpu
  160. CPU = -mcpu=cortex-m4
  161. # fpu
  162. FPU = -mfpu=fpv4-sp-d16
  163. # float-abi
  164. FLOAT-ABI = -mfloat-abi=hard
  165. # mcu
  166. MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
  167. # macros for gcc
  168. # AS defines
  169. AS_DEFS =
  170. # AS includes
  171. AS_INCLUDES = \
  172. -IInc
  173. # C includes
  174. C_INCLUDES = \
  175. -IInc \
  176. -I../applications \
  177. -I../core \
  178. -IDrivers/STM32L4xx_HAL_Driver/Inc \
  179. -IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy \
  180. -IMiddlewares/Third_Party/FreeRTOS/Source/include \
  181. -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS \
  182. -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \
  183. -IDrivers/CMSIS/Device/ST/STM32L4xx/Include \
  184. -IDrivers/CMSIS/Include \
  185. -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \
  186. -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \
  187. -I../core-rs/flipper-core/bindings
  188. # compile gcc flags
  189. ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  190. CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  191. ifeq ($(DEBUG), 1)
  192. CFLAGS += -g -gdwarf-2
  193. endif
  194. # Generate dependency information
  195. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  196. CPPFLAGS = -fno-threadsafe-statics
  197. #######################################
  198. # LDFLAGS
  199. #######################################
  200. # link script
  201. LDSCRIPT = STM32L476RGTx_FLASH.ld
  202. # libraries
  203. LIBS = -lc -lm -lnosys -l$(RUST_LIB_NAME)
  204. LIBDIR = -L$(RUST_LIB_PATH)
  205. LDFLAGS = $(MCU) -specs=nano.specs -specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  206. # default action: build all
  207. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  208. rust_lib:
  209. $(RUST_LIB_CMD)
  210. example_blink:
  211. EXAMPLE_BLINK=1 make
  212. rm $(BUILD_DIR)/app.o
  213. example_uart_write:
  214. EXAMPLE_UART_WRITE=1 make
  215. rm $(BUILD_DIR)/app.o
  216. test:
  217. TEST=1 make
  218. rm $(BUILD_DIR)/app.o
  219. .PHONY: all rust_lib example_blink example_uart_write test
  220. #######################################
  221. # build the application
  222. #######################################
  223. # list of objects
  224. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  225. vpath %.c $(sort $(dir $(C_SOURCES)))
  226. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
  227. vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
  228. # list of ASM program objects
  229. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  230. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  231. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  232. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  233. $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
  234. $(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  235. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  236. $(AS) -c $(CFLAGS) $< -o $@
  237. $(BUILD_DIR)/%.pb.c $(BUILD_DIR)/%.pb.h: ../flipper_proto/%.proto
  238. $(PROTOC) $(PROTOC_OPTS) --nanopb_out=$(BUILD_DIR) $<
  239. $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a: rust_lib
  240. $(BUILD_DIR)/$(TARGET).elf: $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
  241. $(CPP) $(OBJECTS) $(LDFLAGS) -o $@
  242. $(SZ) $@
  243. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  244. $(HEX) $< $@
  245. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  246. $(BIN) $< $@
  247. $(BUILD_DIR):
  248. mkdir $@
  249. #######################################
  250. # clean up
  251. #######################################
  252. clean:
  253. -rm -fR $(BUILD_DIR)
  254. cd $(RUST_LIB_SRC) && cargo clean
  255. #######################################
  256. # dependencies
  257. #######################################
  258. -include $(wildcard $(BUILD_DIR)/*.d)
  259. # *** EOF ***