Merge pull request #11627 from phobos-/crazybee-bmi270
[betaflight.git] / make / mcu / STM32F4.mk
blobff47ee2365c2e9c130e9ad3067fc27bd2501798e
2 # F4 Make file include
5 ifeq ($(OPBL),yes)
6 ifeq ($(TARGET), $(filter $(TARGET),$(F405_TARGETS)))
7 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405_opbl.ld
8 else ifeq ($(TARGET), $(filter $(TARGET),$(F411_TARGETS)))
9 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411_opbl.ld
10 else
11 $(error No OPBL linker script specified for $(TARGET`))
12 endif
13 endif
15 #CMSIS
16 ifeq ($(PERIPH_DRIVER), HAL)
17 CMSIS_DIR := $(ROOT)/lib/main/STM32F4/Drivers/CMSIS
18 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4/Drivers/STM32F4xx_HAL_Driver
19 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
20 EXCLUDES =
21 else
22 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
23 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4/Drivers/STM32F4xx_StdPeriph_Driver
24 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
25 EXCLUDES = stm32f4xx_crc.c \
26 stm32f4xx_can.c \
27 stm32f4xx_fmc.c \
28 stm32f4xx_sai.c \
29 stm32f4xx_cec.c \
30 stm32f4xx_dsi.c \
31 stm32f4xx_flash_ramfunc.c \
32 stm32f4xx_fmpi2c.c \
33 stm32f4xx_lptim.c \
34 stm32f4xx_qspi.c \
35 stm32f4xx_spdifrx.c \
36 stm32f4xx_cryp.c \
37 stm32f4xx_cryp_aes.c \
38 stm32f4xx_hash_md5.c \
39 stm32f4xx_cryp_des.c \
40 stm32f4xx_hash.c \
41 stm32f4xx_dbgmcu.c \
42 stm32f4xx_cryp_tdes.c \
43 stm32f4xx_hash_sha1.c
44 endif
46 ifeq ($(TARGET),$(filter $(TARGET), $(F411_TARGETS)))
47 EXCLUDES += stm32f4xx_fsmc.c
48 MCU_FLASH_SIZE := 512
49 else ifeq ($(TARGET),$(filter $(TARGET), $(F446_TARGETS)))
50 EXCLUDES += stm32f4xx_fsmc.c
51 MCU_FLASH_SIZE := 512
52 else
53 MCU_FLASH_SIZE := 1024
54 endif
56 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
58 ifeq ($(PERIPH_DRIVER), HAL)
59 #USB
60 USBCORE_DIR = $(ROOT)/lib/main/STM32F4/Middlewares/ST/STM32_USB_Device_Library/Core
61 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
62 EXCLUDES = usbd_conf_template.c
63 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
65 USBCDC_DIR = $(ROOT)/lib/main/STM32F4/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
66 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
67 EXCLUDES = usbd_cdc_if_template.c
68 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
70 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src
72 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
73 $(USBCORE_SRC) \
74 $(USBCDC_SRC)
75 else
76 USBCORE_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Core
77 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/src/*.c))
78 USBOTG_DIR = $(ROOT)/lib/main/STM32_USB_OTG_Driver
79 USBOTG_SRC = $(notdir $(wildcard $(USBOTG_DIR)/src/*.c))
80 EXCLUDES = usb_bsp_template.c \
81 usb_conf_template.c \
82 usb_hcd_int.c \
83 usb_hcd.c \
84 usb_otg.c
86 USBOTG_SRC := $(filter-out ${EXCLUDES}, $(USBOTG_SRC))
87 USBCDC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/cdc
88 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/src/*.c))
89 EXCLUDES = usbd_cdc_if_template.c
90 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
91 USBMSC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/msc
92 USBMSC_SRC = $(notdir $(wildcard $(USBMSC_DIR)/src/*.c))
93 EXCLUDES = usbd_storage_template.c
94 USBMSC_SRC := $(filter-out ${EXCLUDES}, $(USBMSC_SRC))
95 USBHID_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/hid
96 USBHID_SRC = $(notdir $(wildcard $(USBHID_DIR)/src/*.c))
97 USBWRAPPER_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/hid_cdc_wrapper
98 USBWRAPPER_SRC = $(notdir $(wildcard $(USBWRAPPER_DIR)/src/*.c))
99 VPATH := $(VPATH):$(USBOTG_DIR)/src:$(USBCORE_DIR)/src:$(USBCDC_DIR)/src:$(USBMSC_DIR)/src:$(USBHID_DIR)/src:$(USBWRAPPER_DIR)/src
101 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
102 $(USBOTG_SRC) \
103 $(USBCORE_SRC) \
104 $(USBCDC_SRC) \
105 $(USBHID_SRC) \
106 $(USBWRAPPER_SRC) \
107 $(USBMSC_SRC)
108 endif
110 #CMSIS
111 VPATH := $(VPATH):$(CMSIS_DIR)/Core/Include:$(ROOT)/lib/main/STM32F4/Drivers/CMSIS/Device/ST/STM32F4xx
113 ifeq ($(PERIPH_DRIVER), HAL)
114 CMSIS_SRC :=
115 INCLUDE_DIRS := $(INCLUDE_DIRS) \
116 $(STDPERIPH_DIR)/Inc \
117 $(USBCORE_DIR)/Inc \
118 $(USBCDC_DIR)/Inc \
119 $(CMSIS_DIR)/Include \
120 $(CMSIS_DIR)/Device/ST/STM32F4xx/Include \
121 $(ROOT)/src/main/vcp_hal
122 else
123 CMSIS_SRC := $(notdir $(wildcard $(CMSIS_DIR)/CoreSupport/*.c \
124 $(ROOT)/lib/main/STM32F4/Drivers/CMSIS/Device/ST/STM32F4xx/*.c))
125 INCLUDE_DIRS := $(INCLUDE_DIRS) \
126 $(STDPERIPH_DIR)/inc \
127 $(USBOTG_DIR)/inc \
128 $(USBCORE_DIR)/inc \
129 $(USBCDC_DIR)/inc \
130 $(USBHID_DIR)/inc \
131 $(USBWRAPPER_DIR)/inc \
132 $(USBMSC_DIR)/inc \
133 $(USBFS_DIR)/inc \
134 $(CMSIS_DIR)/Core/Include \
135 $(ROOT)/lib/main/STM32F4/Drivers/CMSIS/Device/ST/STM32F4xx \
136 $(ROOT)/src/main/vcpf4
137 endif
139 ifneq ($(filter SDCARD_SPI,$(FEATURES)),)
140 INCLUDE_DIRS := $(INCLUDE_DIRS) \
141 $(FATFS_DIR)
142 VPATH := $(VPATH):$(FATFS_DIR)
143 endif
145 ifneq ($(filter SDCARD_SDIO,$(FEATURES)),)
146 INCLUDE_DIRS := $(INCLUDE_DIRS) \
147 $(FATFS_DIR)
148 VPATH := $(VPATH):$(FATFS_DIR)
149 endif
151 #Flags
152 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
154 ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
155 DEVICE_FLAGS = -DSTM32F411xE
156 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411.ld
157 STARTUP_SRC = startup_stm32f411xe.s
158 else ifeq ($(TARGET),$(filter $(TARGET),$(F405_TARGETS)))
159 DEVICE_FLAGS = -DSTM32F40_41xxx -DSTM32F405xx
160 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405.ld
161 STARTUP_SRC = startup_stm32f40xx.s
162 else ifeq ($(TARGET),$(filter $(TARGET),$(F446_TARGETS)))
163 DEVICE_FLAGS = -DSTM32F446xx
164 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f446.ld
165 STARTUP_SRC = startup_stm32f446xx.s
166 else
167 $(error Unknown MCU for F4 target)
168 endif
169 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
171 MCU_COMMON_SRC = \
172 startup/system_stm32f4xx.c \
173 drivers/accgyro/accgyro_mpu.c \
174 drivers/adc_stm32f4xx.c \
175 drivers/bus_i2c_stm32f10x.c \
176 drivers/bus_spi_stdperiph.c \
177 drivers/dma_stm32f4xx.c \
178 drivers/dshot_bitbang.c \
179 drivers/dshot_bitbang_decode.c \
180 drivers/dshot_bitbang_stdperiph.c \
181 drivers/inverter.c \
182 drivers/light_ws2811strip_stdperiph.c \
183 drivers/transponder_ir_io_stdperiph.c \
184 drivers/pwm_output_dshot.c \
185 drivers/pwm_output_dshot_shared.c \
186 drivers/serial_uart_stdperiph.c \
187 drivers/serial_uart_stm32f4xx.c \
188 drivers/system_stm32f4xx.c \
189 drivers/timer_stm32f4xx.c \
190 drivers/persistent.c
192 ifeq ($(PERIPH_DRIVER), HAL)
193 VCP_SRC = \
194 vcp_hal/usbd_desc.c \
195 vcp_hal/usbd_conf.c \
196 vcp_hal/usbd_cdc_interface.c \
197 drivers/serial_usb_vcp.c \
198 drivers/usb_io.c
199 else
200 VCP_SRC = \
201 vcpf4/stm32f4xx_it.c \
202 vcpf4/usb_bsp.c \
203 vcpf4/usbd_desc.c \
204 vcpf4/usbd_usr.c \
205 vcpf4/usbd_cdc_vcp.c \
206 drivers/serial_usb_vcp.c \
207 drivers/usb_io.c
208 endif
210 MSC_SRC = \
211 drivers/usb_msc_common.c \
212 drivers/usb_msc_f4xx.c \
213 msc/usbd_msc_desc.c \
214 msc/usbd_storage.c
216 ifneq ($(filter SDCARD_SPI,$(FEATURES)),)
217 MSC_SRC += \
218 msc/usbd_storage_sd_spi.c
219 endif
221 ifneq ($(filter SDCARD_SDIO,$(FEATURES)),)
222 MSC_SRC += \
223 msc/usbd_storage_sdio.c
224 MCU_COMMON_SRC += \
225 drivers/sdio_f4xx.c
226 endif
228 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
229 MSC_SRC += \
230 msc/usbd_storage_emfat.c \
231 msc/emfat.c \
232 msc/emfat_file.c
233 endif
235 DSP_LIB := $(ROOT)/lib/main/CMSIS/DSP
236 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE -DARM_MATH_CM4