Shared altitude control parameters (#13884)
[betaflight.git] / mk / mcu / STM32H7.mk
blob817ab40ed5e69c54e4a03876f5201a23033964d8
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 = \
15 stm32h7xx_hal_adc.c \
16 stm32h7xx_hal_adc_ex.c \
17 stm32h7xx_hal.c \
18 stm32h7xx_hal_cordic.c \
19 stm32h7xx_hal_cortex.c \
20 stm32h7xx_hal_dac.c \
21 stm32h7xx_hal_dac_ex.c \
22 stm32h7xx_hal_dfsdm_ex.c \
23 stm32h7xx_hal_dma.c \
24 stm32h7xx_hal_dma_ex.c \
25 stm32h7xx_hal_dts.c \
26 stm32h7xx_hal_exti.c \
27 stm32h7xx_hal_flash.c \
28 stm32h7xx_hal_flash_ex.c \
29 stm32h7xx_hal_fmac.c \
30 stm32h7xx_hal_gfxmmu.c \
31 stm32h7xx_hal_gpio.c \
32 stm32h7xx_hal_i2c.c \
33 stm32h7xx_hal_i2c_ex.c \
34 stm32h7xx_hal_ospi.c \
35 stm32h7xx_hal_otfdec.c \
36 stm32h7xx_hal_pcd.c \
37 stm32h7xx_hal_pcd_ex.c \
38 stm32h7xx_hal_pssi.c \
39 stm32h7xx_hal_pwr.c \
40 stm32h7xx_hal_pwr_ex.c \
41 stm32h7xx_hal_qspi.c \
42 stm32h7xx_hal_rcc.c \
43 stm32h7xx_hal_rcc_ex.c \
44 stm32h7xx_hal_rng_ex.c \
45 stm32h7xx_hal_rtc_ex.c \
46 stm32h7xx_hal_sd.c \
47 stm32h7xx_hal_spi_ex.c \
48 stm32h7xx_hal_tim.c \
49 stm32h7xx_hal_tim_ex.c \
50 stm32h7xx_hal_uart.c \
51 stm32h7xx_hal_uart_ex.c \
52 stm32h7xx_ll_cordic.c \
53 stm32h7xx_ll_crs.c \
54 stm32h7xx_ll_dma.c \
55 stm32h7xx_ll_fmac.c \
56 stm32h7xx_ll_sdmmc.c \
57 stm32h7xx_ll_spi.c \
58 stm32h7xx_ll_tim.c \
59 stm32h7xx_ll_usb.c
61 #USB
62 USBCORE_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Core
63 USBCORE_SRC = \
64 usbd_core.c \
65 usbd_ctlreq.c \
66 usbd_ioreq.c
68 USBCDC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
69 USBCDC_SRC = usbd_cdc.c
71 USBHID_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/HID
72 USBHID_SRC = usbd_hid.c
74 USBMSC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC
75 USBMSC_SRC = \
76 usbd_msc_bot.c \
77 usbd_msc.c \
78 usbd_msc_data.c \
79 usbd_msc_scsi.c
81 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src:$(USBHID_DIR)/Src:$(USBMSC_DIR)/Src:$(STDPERIPH_DIR)/src
83 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
84 $(USBCORE_SRC) \
85 $(USBCDC_SRC) \
86 $(USBHID_SRC) \
87 $(USBMSC_SRC)
89 #CMSIS
90 VPATH := $(VPATH):$(CMSIS_DIR)/Include:$(CMSIS_DIR)/Device/ST/STM32H7xx
91 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
92 CMSIS_SRC :=
93 INCLUDE_DIRS := $(INCLUDE_DIRS) \
94 $(SRC_DIR)/startup/stm32 \
95 $(STDPERIPH_DIR)/Inc \
96 $(USBCORE_DIR)/Inc \
97 $(USBCDC_DIR)/Inc \
98 $(USBHID_DIR)/Inc \
99 $(USBMSC_DIR)/Inc \
100 $(CMSIS_DIR)/Core/Include \
101 $(ROOT)/lib/main/STM32H7/Drivers/CMSIS/Device/ST/STM32H7xx/Include \
102 $(SRC_DIR)/drivers/mcu/stm32 \
103 $(SRC_DIR)/drivers/mcu/stm32/vcp_hal
105 #Flags
106 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant
108 # Flags that are used in the STM32 libraries
109 DEVICE_FLAGS = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER
112 # H743xI : 2M FLASH, 512KB AXI SRAM + 512KB D2 & D3 SRAM (H753xI also)
113 # H743xG : 1M FLASH, 512KB AXI SRAM + 512KB D2 & D3 SRAM (H753xG also)
114 # H7A3xI : 2M FLASH, 1MB AXI SRAM + 160KB AHB & SRD SRAM
115 # H750xB : 128K FLASH, 1M RAM
117 ifeq ($(TARGET_MCU),STM32H743xx)
118 DEVICE_FLAGS += -DSTM32H743xx
119 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h743_2m.ld
120 STARTUP_SRC = stm32/startup_stm32h743xx.s
121 MCU_FLASH_SIZE := 2048
122 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
124 ifeq ($(RAM_BASED),yes)
125 FIRMWARE_SIZE := 448
126 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
127 # and the maximum size of the data stored on the external storage device.
128 MCU_FLASH_SIZE := FIRMWARE_SIZE
129 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h743.ld
130 endif
132 else ifeq ($(TARGET_MCU),STM32H7A3xxQ)
133 DEVICE_FLAGS += -DSTM32H7A3xxQ
134 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_2m.ld
135 STARTUP_SRC = stm32/startup_stm32h7a3xx.s
136 MCU_FLASH_SIZE := 2048
137 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
139 ifeq ($(RAM_BASED),yes)
140 FIRMWARE_SIZE := 448
141 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
142 # and the maximum size of the data stored on the external storage device.
143 MCU_FLASH_SIZE := FIRMWARE_SIZE
144 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_ram_based.ld
145 endif
147 else ifeq ($(TARGET_MCU),STM32H7A3xx)
148 DEVICE_FLAGS += -DSTM32H7A3xx
149 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_2m.ld
150 STARTUP_SRC = stm32/startup_stm32h7a3xx.s
151 MCU_FLASH_SIZE := 2048
152 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
154 ifeq ($(RAM_BASED),yes)
155 FIRMWARE_SIZE := 448
156 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
157 # and the maximum size of the data stored on the external storage device.
158 MCU_FLASH_SIZE := FIRMWARE_SIZE
159 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h7a3_ram_based.ld
160 endif
162 else ifeq ($(TARGET_MCU),STM32H723xx)
163 DEVICE_FLAGS += -DSTM32H723xx
164 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h723_1m.ld
165 STARTUP_SRC = stm32/startup_stm32h723xx.s
166 DEFAULT_TARGET_FLASH := 1024
167 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
169 ifeq ($(TARGET_FLASH),)
170 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
171 endif
173 ifeq ($(EXST),yes)
174 FIRMWARE_SIZE := 1024
175 # TARGET_FLASH now becomes the amount of MEMORY-MAPPED address space that is occupied by the firmware
176 # and the maximum size of the data stored on the external flash device.
177 MCU_FLASH_SIZE := FIRMWARE_SIZE
178 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h723_exst.ld
179 LD_SCRIPTS = $(LINKER_DIR)/stm32_h723_common.ld $(LINKER_DIR)/stm32_h723_common_post.ld
180 endif
182 else ifeq ($(TARGET_MCU),STM32H725xx)
183 DEVICE_FLAGS += -DSTM32H725xx
184 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h723_1m.ld
185 STARTUP_SRC = stm32/startup_stm32h723xx.s
186 MCU_FLASH_SIZE := 1024
187 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
189 else ifeq ($(TARGET_MCU),STM32H730xx)
190 DEVICE_FLAGS += -DSTM32H730xx
191 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h730_128m.ld
192 STARTUP_SRC = stm32/startup_stm32h730xx.s
193 DEFAULT_TARGET_FLASH := 128
194 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
197 ifeq ($(TARGET_FLASH),)
198 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
199 endif
201 ifeq ($(EXST),yes)
202 FIRMWARE_SIZE := 1024
203 # TARGET_FLASH now becomes the amount of MEMORY-MAPPED address space that is occupied by the firmware
204 # and the maximum size of the data stored on the external flash device.
205 MCU_FLASH_SIZE := FIRMWARE_SIZE
206 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h730_exst.ld
207 LD_SCRIPTS = $(LINKER_DIR)/stm32_h730_common.ld $(LINKER_DIR)/stm32_h730_common_post.ld
208 endif
211 else ifeq ($(TARGET_MCU),STM32H750xx)
212 DEVICE_FLAGS += -DSTM32H750xx
213 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h750_128k.ld
214 STARTUP_SRC = stm32/startup_stm32h743xx.s
215 DEFAULT_TARGET_FLASH := 128
217 ifeq ($(TARGET_FLASH),)
218 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
219 endif
221 ifeq ($(EXST),yes)
222 FIRMWARE_SIZE := 448
223 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
224 # and the maximum size of the data stored on the external storage device.
225 MCU_FLASH_SIZE := FIRMWARE_SIZE
226 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h750_exst.ld
227 endif
229 ifeq ($(EXST),yes)
230 # Upper 8 regions are reserved for a boot loader in EXST environment
231 DEVICE_FLAGS += -DMAX_MPU_REGIONS=8
232 else
233 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
234 endif
236 ifneq ($(DEBUG),GDB)
237 OPTIMISE_DEFAULT := -Os
238 OPTIMISE_SPEED := -Os
239 OPTIMISE_SIZE := -Os
241 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
242 endif
244 else
245 $(error Unknown MCU for H7 target)
246 endif
248 ifeq ($(LD_SCRIPT),)
249 LD_SCRIPT = $(DEFAULT_LD_SCRIPT)
250 endif
252 ifneq ($(FIRMWARE_SIZE),)
253 DEVICE_FLAGS += -DFIRMWARE_SIZE=$(FIRMWARE_SIZE)
254 endif
256 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE) -DHSE_STARTUP_TIMEOUT=1000 -DSTM32
258 VCP_SRC = \
259 drivers/mcu/stm32/vcp_hal/usbd_desc.c \
260 drivers/mcu/stm32/vcp_hal/usbd_conf_stm32h7xx.c \
261 drivers/mcu/stm32/vcp_hal/usbd_cdc_hid.c \
262 drivers/mcu/stm32/vcp_hal/usbd_cdc_interface.c \
263 drivers/mcu/stm32/serial_usb_vcp.c \
264 drivers/usb_io.c
266 MCU_COMMON_SRC = \
267 drivers/bus_i2c_timing.c \
268 drivers/bus_quadspi.c \
269 drivers/dshot_bitbang_decode.c \
270 drivers/pwm_output_dshot_shared.c \
271 drivers/mcu/stm32/adc_stm32h7xx.c \
272 drivers/mcu/stm32/audio_stm32h7xx.c \
273 drivers/mcu/stm32/bus_i2c_hal_init.c \
274 drivers/mcu/stm32/bus_i2c_hal.c \
275 drivers/mcu/stm32/bus_spi_ll.c \
276 drivers/mcu/stm32/bus_quadspi_hal.c \
277 drivers/mcu/stm32/bus_octospi_stm32h7xx.c \
278 drivers/mcu/stm32/debug.c \
279 drivers/mcu/stm32/dma_reqmap_mcu.c \
280 drivers/mcu/stm32/dma_stm32h7xx.c \
281 drivers/mcu/stm32/dshot_bitbang_ll.c \
282 drivers/mcu/stm32/dshot_bitbang.c \
283 drivers/mcu/stm32/exti.c \
284 drivers/mcu/stm32/io_stm32.c \
285 drivers/mcu/stm32/light_ws2811strip_hal.c \
286 drivers/mcu/stm32/memprot_hal.c \
287 drivers/mcu/stm32/memprot_stm32h7xx.c \
288 drivers/mcu/stm32/persistent.c \
289 drivers/mcu/stm32/pwm_output.c \
290 drivers/mcu/stm32/pwm_output_dshot_hal.c \
291 drivers/mcu/stm32/rcc_stm32.c \
292 drivers/mcu/stm32/sdio_h7xx.c \
293 drivers/mcu/stm32/serial_uart_hal.c \
294 drivers/mcu/stm32/serial_uart_stm32h7xx.c \
295 drivers/mcu/stm32/system_stm32h7xx.c \
296 drivers/mcu/stm32/timer_hal.c \
297 drivers/mcu/stm32/timer_stm32h7xx.c \
298 drivers/mcu/stm32/transponder_ir_io_hal.c \
299 drivers/mcu/stm32/camera_control.c \
300 startup/stm32/system_stm32h7xx.c
302 MCU_EXCLUDES = \
303 drivers/bus_i2c.c
305 MSC_SRC = \
306 drivers/mcu/stm32/usb_msc_hal.c \
307 drivers/usb_msc_common.c \
308 msc/usbd_storage.c \
309 msc/usbd_storage_emfat.c \
310 msc/emfat.c \
311 msc/emfat_file.c \
312 msc/usbd_storage_sd_spi.c \
313 msc/usbd_storage_sdio.c
315 DSP_LIB := $(ROOT)/lib/main/CMSIS/DSP
316 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE -DARM_MATH_CM7