Cleanup of USB drivers for AT32F4 (#12441)
[betaflight.git] / make / mcu / STM32H7.mk
blobac3f32d7861932c9959a90483741f89652ca5238
2 # H7 Make file include
5 ifeq ($(DEBUG_HARDFAULTS),H7)
6 CFLAGS += -DDEBUG_HARDFAULTS
7 endif
9 #CMSIS
10 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
12 #STDPERIPH
13 STDPERIPH_DIR = $(ROOT)/lib/main/STM32H7/Drivers/STM32H7xx_HAL_Driver
14 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
16 EXCLUDES = \
17 stm32h7xx_hal_cec.c \
18 stm32h7xx_hal_comp.c \
19 stm32h7xx_hal_crc.c \
20 stm32h7xx_hal_crc_ex.c \
21 stm32h7xx_hal_cryp.c \
22 stm32h7xx_hal_cryp_ex.c \
23 stm32h7xx_hal_dcmi.c \
24 stm32h7xx_hal_dfsdm.c \
25 stm32h7xx_hal_dma2d.c \
26 stm32h7xx_hal_dsi.c \
27 stm32h7xx_hal_eth.c \
28 stm32h7xx_hal_eth_ex.c \
29 stm32h7xx_hal_fdcan.c \
30 stm32h7xx_hal_hash.c \
31 stm32h7xx_hal_hash_ex.c \
32 stm32h7xx_hal_hcd.c \
33 stm32h7xx_hal_hrtim.c \
34 stm32h7xx_hal_hsem.c \
35 stm32h7xx_hal_i2s.c \
36 stm32h7xx_hal_i2s_ex.c \
37 stm32h7xx_hal_irda.c \
38 stm32h7xx_hal_iwdg.c \
39 stm32h7xx_hal_jpeg.c \
40 stm32h7xx_hal_lptim.c \
41 stm32h7xx_hal_ltdc.c \
42 stm32h7xx_hal_ltdc_ex.c \
43 stm32h7xx_hal_mdios.c \
44 stm32h7xx_hal_mdma.c \
45 stm32h7xx_hal_mmc.c \
46 stm32h7xx_hal_mmc_ex.c \
47 stm32h7xx_hal_msp_template.c \
48 stm32h7xx_hal_nand.c \
49 stm32h7xx_hal_nor.c \
50 stm32h7xx_hal_opamp.c \
51 stm32h7xx_hal_opamp_ex.c \
52 stm32h7xx_hal_ramecc.c \
53 stm32h7xx_hal_rng.c \
54 stm32h7xx_hal_rtc.c \
55 stm32h7xx_hal_sai.c \
56 stm32h7xx_hal_sai_ex.c \
57 stm32h7xx_hal_sd_ex.c \
58 stm32h7xx_hal_sdram.c \
59 stm32h7xx_hal_smartcard.c \
60 stm32h7xx_hal_smartcard_ex.c \
61 stm32h7xx_hal_smbus.c \
62 stm32h7xx_hal_spdifrx.c \
63 stm32h7xx_hal_spi.c \
64 stm32h7xx_hal_sram.c \
65 stm32h7xx_hal_swpmi.c \
66 stm32h7xx_hal_usart.c \
67 stm32h7xx_hal_usart_ex.c \
68 stm32h7xx_hal_wwdg.c \
69 stm32h7xx_ll_adc.c \
70 stm32h7xx_ll_bdma.c \
71 stm32h7xx_ll_comp.c \
72 stm32h7xx_ll_crc.c \
73 stm32h7xx_ll_dac.c \
74 stm32h7xx_ll_delayblock.c \
75 stm32h7xx_ll_dma2d.c \
76 stm32h7xx_ll_exti.c \
77 stm32h7xx_ll_fmc.c \
78 stm32h7xx_ll_gpio.c \
79 stm32h7xx_ll_hrtim.c \
80 stm32h7xx_ll_i2c.c \
81 stm32h7xx_ll_lptim.c \
82 stm32h7xx_ll_lpuart.c \
83 stm32h7xx_ll_mdma.c \
84 stm32h7xx_ll_opamp.c \
85 stm32h7xx_ll_pwr.c \
86 stm32h7xx_ll_rcc.c \
87 stm32h7xx_ll_rng.c \
88 stm32h7xx_ll_rtc.c \
89 stm32h7xx_ll_swpmi.c \
90 stm32h7xx_ll_usart.c \
91 stm32h7xx_ll_utils.c
93 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
95 #USB
96 USBCORE_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Core
97 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
98 EXCLUDES = usbd_conf_template.c
99 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
101 USBCDC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
102 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
103 EXCLUDES = usbd_cdc_if_template.c
104 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
106 USBHID_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/HID
107 USBHID_SRC = $(notdir $(wildcard $(USBHID_DIR)/Src/*.c))
109 USBMSC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC
110 USBMSC_SRC = $(notdir $(wildcard $(USBMSC_DIR)/Src/*.c))
111 EXCLUDES = usbd_msc_storage_template.c
112 USBMSC_SRC := $(filter-out ${EXCLUDES}, $(USBMSC_SRC))
114 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src:$(USBHID_DIR)/Src:$(USBMSC_DIR)/Src:$(STDPERIPH_DIR)/src
116 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
117 $(USBCORE_SRC) \
118 $(USBCDC_SRC) \
119 $(USBHID_SRC) \
120 $(USBMSC_SRC)
122 #CMSIS
123 VPATH := $(VPATH):$(CMSIS_DIR)/Include:$(CMSIS_DIR)/Device/ST/STM32H7xx
124 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
125 CMSIS_SRC :=
126 INCLUDE_DIRS := $(INCLUDE_DIRS) \
127 $(STDPERIPH_DIR)/Inc \
128 $(USBCORE_DIR)/Inc \
129 $(USBCDC_DIR)/Inc \
130 $(USBHID_DIR)/Inc \
131 $(USBMSC_DIR)/Inc \
132 $(CMSIS_DIR)/Core/Include \
133 $(ROOT)/lib/main/STM32H7/Drivers/CMSIS/Device/ST/STM32H7xx/Include \
134 $(ROOT)/src/main/drivers/stm32 \
135 $(ROOT)/src/main/drivers/stm32/vcp_hal
137 #Flags
138 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant
140 # Flags that are used in the STM32 libraries
141 DEVICE_FLAGS = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER
144 # H743xI : 2M FLASH, 512KB AXI SRAM + 512KB D2 & D3 SRAM (H753xI also)
145 # H743xG : 1M FLASH, 512KB AXI SRAM + 512KB D2 & D3 SRAM (H753xG also)
146 # H7A3xI : 2M FLASH, 1MB AXI SRAM + 160KB AHB & SRD SRAM
147 # H750xB : 128K FLASH, 1M RAM
149 ifeq ($(TARGET_MCU),STM32H743xx)
150 DEVICE_FLAGS += -DSTM32H743xx
151 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h743_2m.ld
152 STARTUP_SRC = startup_stm32h743xx.s
153 MCU_FLASH_SIZE := 2048
154 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
156 ifeq ($(RAM_BASED),yes)
157 FIRMWARE_SIZE := 448
158 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
159 # and the maximum size of the data stored on the external storage device.
160 MCU_FLASH_SIZE := FIRMWARE_SIZE
161 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h743.ld
162 endif
164 else ifeq ($(TARGET_MCU),STM32H7A3xxQ)
165 DEVICE_FLAGS += -DSTM32H7A3xxQ
166 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_2m.ld
167 STARTUP_SRC = startup_stm32h7a3xx.s
168 MCU_FLASH_SIZE := 2048
169 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
171 ifeq ($(RAM_BASED),yes)
172 FIRMWARE_SIZE := 448
173 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
174 # and the maximum size of the data stored on the external storage device.
175 MCU_FLASH_SIZE := FIRMWARE_SIZE
176 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_ram_based.ld
177 endif
179 else ifeq ($(TARGET_MCU),STM32H7A3xx)
180 DEVICE_FLAGS += -DSTM32H7A3xx
181 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_2m.ld
182 STARTUP_SRC = startup_stm32h7a3xx.s
183 MCU_FLASH_SIZE := 2048
184 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
186 ifeq ($(RAM_BASED),yes)
187 FIRMWARE_SIZE := 448
188 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
189 # and the maximum size of the data stored on the external storage device.
190 MCU_FLASH_SIZE := FIRMWARE_SIZE
191 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_ram_based.ld
192 endif
194 else ifeq ($(TARGET_MCU),STM32H723xx)
195 DEVICE_FLAGS += -DSTM32H723xx
196 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h723_1m.ld
197 STARTUP_SRC = startup_stm32h723xx.s
198 DEFAULT_TARGET_FLASH := 1024
199 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
201 ifeq ($(TARGET_FLASH),)
202 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
203 endif
205 ifeq ($(EXST),yes)
206 FIRMWARE_SIZE := 1024
207 # TARGET_FLASH now becomes the amount of MEMORY-MAPPED address space that is occupied by the firmware
208 # and the maximum size of the data stored on the external flash device.
209 MCU_FLASH_SIZE := FIRMWARE_SIZE
210 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h723_exst.ld
211 LD_SCRIPTS = $(LINKER_DIR)/stm32_h723_common.ld $(LINKER_DIR)/stm32_h723_common_post.ld
212 endif
214 else ifeq ($(TARGET_MCU),STM32H725xx)
215 DEVICE_FLAGS += -DSTM32H725xx
216 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h723_1m.ld
217 STARTUP_SRC = startup_stm32h723xx.s
218 MCU_FLASH_SIZE := 1024
219 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
221 else ifeq ($(TARGET_MCU),STM32H730xx)
222 DEVICE_FLAGS += -DSTM32H730xx
223 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h730_128m.ld
224 STARTUP_SRC = startup_stm32h730xx.s
225 DEFAULT_TARGET_FLASH := 128
226 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
229 ifeq ($(TARGET_FLASH),)
230 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
231 endif
233 ifeq ($(EXST),yes)
234 FIRMWARE_SIZE := 1024
235 # TARGET_FLASH now becomes the amount of MEMORY-MAPPED address space that is occupied by the firmware
236 # and the maximum size of the data stored on the external flash device.
237 MCU_FLASH_SIZE := FIRMWARE_SIZE
238 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h730_exst.ld
239 LD_SCRIPTS = $(LINKER_DIR)/stm32_h730_common.ld $(LINKER_DIR)/stm32_h730_common_post.ld
240 endif
243 else ifeq ($(TARGET_MCU),STM32H750xx)
244 DEVICE_FLAGS += -DSTM32H750xx
245 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h750_128k.ld
246 STARTUP_SRC = startup_stm32h743xx.s
247 DEFAULT_TARGET_FLASH := 128
249 ifeq ($(TARGET_FLASH),)
250 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
251 endif
253 ifeq ($(EXST),yes)
254 FIRMWARE_SIZE := 448
255 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
256 # and the maximum size of the data stored on the external storage device.
257 MCU_FLASH_SIZE := FIRMWARE_SIZE
258 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h750_exst.ld
259 endif
261 ifeq ($(EXST),yes)
262 # Upper 8 regions are reserved for a boot loader in EXST environment
263 DEVICE_FLAGS += -DMAX_MPU_REGIONS=8
264 else
265 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
266 endif
268 ifneq ($(DEBUG),GDB)
269 OPTIMISE_DEFAULT := -Os
270 OPTIMISE_SPEED := -Os
271 OPTIMISE_SIZE := -Os
273 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
274 endif
276 else
277 $(error Unknown MCU for H7 target)
278 endif
280 ifeq ($(LD_SCRIPT),)
281 LD_SCRIPT = $(DEFAULT_LD_SCRIPT)
282 endif
284 ifneq ($(FIRMWARE_SIZE),)
285 DEVICE_FLAGS += -DFIRMWARE_SIZE=$(FIRMWARE_SIZE)
286 endif
288 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE) -DHSE_STARTUP_TIMEOUT=1000 -DSTM32
290 VCP_SRC = \
291 drivers/stm32/vcp_hal/usbd_desc.c \
292 drivers/stm32/vcp_hal/usbd_conf_stm32h7xx.c \
293 drivers/stm32/vcp_hal/usbd_cdc_hid.c \
294 drivers/stm32/vcp_hal/usbd_cdc_interface.c \
295 drivers/stm32/serial_usb_vcp.c \
296 drivers/usb_io.c
298 MCU_COMMON_SRC = \
299 drivers/bus_i2c_timing.c \
300 drivers/bus_quadspi.c \
301 drivers/dshot_bitbang_decode.c \
302 drivers/pwm_output_dshot_shared.c \
303 drivers/stm32/adc_stm32h7xx.c \
304 drivers/stm32/audio_stm32h7xx.c \
305 drivers/stm32/bus_i2c_hal_init.c \
306 drivers/stm32/bus_i2c_hal.c \
307 drivers/stm32/bus_spi_ll.c \
308 drivers/stm32/bus_quadspi_hal.c \
309 drivers/stm32/bus_octospi_stm32h7xx.c \
310 drivers/stm32/debug.c \
311 drivers/stm32/dma_reqmap_mcu.c \
312 drivers/stm32/dma_stm32h7xx.c \
313 drivers/stm32/dshot_bitbang_ll.c \
314 drivers/stm32/dshot_bitbang.c \
315 drivers/stm32/exti.c \
316 drivers/stm32/io_stm32.c \
317 drivers/stm32/light_ws2811strip_hal.c \
318 drivers/stm32/memprot_hal.c \
319 drivers/stm32/memprot_stm32h7xx.c \
320 drivers/stm32/persistent.c \
321 drivers/stm32/pwm_output.c \
322 drivers/stm32/pwm_output_dshot_hal.c \
323 drivers/stm32/rcc_stm32.c \
324 drivers/stm32/sdio_h7xx.c \
325 drivers/stm32/serial_uart_hal.c \
326 drivers/stm32/serial_uart_stm32h7xx.c \
327 drivers/stm32/system_stm32h7xx.c \
328 drivers/stm32/timer_hal.c \
329 drivers/stm32/timer_stm32h7xx.c \
330 drivers/stm32/transponder_ir_io_hal.c \
331 startup/system_stm32h7xx.c
333 MCU_EXCLUDES = \
334 drivers/bus_i2c.c
336 MSC_SRC = \
337 drivers/stm32/usb_msc_h7xx.c \
338 drivers/usb_msc_common.c \
339 msc/usbd_storage.c \
340 msc/usbd_storage_emfat.c \
341 msc/emfat.c \
342 msc/emfat_file.c \
343 msc/usbd_storage_sd_spi.c \
344 msc/usbd_storage_sdio.c
346 DSP_LIB := $(ROOT)/lib/main/CMSIS/DSP
347 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE -DARM_MATH_CM7