Update Ubuntu development
[betaflight.git] / make / mcu / STM32H7.mk
blob382720906fe75bfa2f28c895221baa644655a935
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_sram.c \
64 stm32h7xx_hal_swpmi.c \
65 stm32h7xx_hal_usart.c \
66 stm32h7xx_hal_usart_ex.c \
67 stm32h7xx_hal_wwdg.c \
68 stm32h7xx_ll_adc.c \
69 stm32h7xx_ll_bdma.c \
70 stm32h7xx_ll_comp.c \
71 stm32h7xx_ll_crc.c \
72 stm32h7xx_ll_dac.c \
73 stm32h7xx_ll_delayblock.c \
74 stm32h7xx_ll_dma2d.c \
75 stm32h7xx_ll_exti.c \
76 stm32h7xx_ll_fmc.c \
77 stm32h7xx_ll_gpio.c \
78 stm32h7xx_ll_hrtim.c \
79 stm32h7xx_ll_i2c.c \
80 stm32h7xx_ll_lptim.c \
81 stm32h7xx_ll_lpuart.c \
82 stm32h7xx_ll_mdma.c \
83 stm32h7xx_ll_opamp.c \
84 stm32h7xx_ll_pwr.c \
85 stm32h7xx_ll_rcc.c \
86 stm32h7xx_ll_rng.c \
87 stm32h7xx_ll_rtc.c \
88 stm32h7xx_ll_spi.c \
89 stm32h7xx_ll_swpmi.c \
90 stm32h7xx_ll_usart.c \
91 stm32h7xx_ll_utils.c
94 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
96 #USB
97 USBCORE_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Core
98 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
99 EXCLUDES = usbd_conf_template.c
100 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
102 USBCDC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
103 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
104 EXCLUDES = usbd_cdc_if_template.c
105 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
107 USBHID_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/HID
108 USBHID_SRC = $(notdir $(wildcard $(USBHID_DIR)/Src/*.c))
110 USBMSC_DIR = $(ROOT)/lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC
111 USBMSC_SRC = $(notdir $(wildcard $(USBMSC_DIR)/Src/*.c))
112 EXCLUDES = usbd_msc_storage_template.c usbd_msc_scsi.c
113 USBMSC_SRC := $(filter-out ${EXCLUDES}, $(USBMSC_SRC))
115 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src:$(USBHID_DIR)/Src:$(USBMSC_DIR)/Src
117 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
118 $(USBCORE_SRC) \
119 $(USBCDC_SRC) \
120 $(USBHID_SRC) \
121 $(USBMSC_SRC)
123 #CMSIS
124 VPATH := $(VPATH):$(CMSIS_DIR)/Include:$(CMSIS_DIR)/Device/ST/STM32H7xx
125 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
126 CMSIS_SRC :=
127 INCLUDE_DIRS := $(INCLUDE_DIRS) \
128 $(STDPERIPH_DIR)/Inc \
129 $(USBCORE_DIR)/Inc \
130 $(USBCDC_DIR)/Inc \
131 $(USBHID_DIR)/Inc \
132 $(USBMSC_DIR)/Inc \
133 $(CMSIS_DIR)/Core/Include \
134 $(ROOT)/lib/main/STM32H7/Drivers/CMSIS/Device/ST/STM32H7xx/Include \
135 $(ROOT)/src/main/vcp_hal
137 ifneq ($(filter SDCARD_SPI,$(FEATURES)),)
138 INCLUDE_DIRS := $(INCLUDE_DIRS) \
139 $(FATFS_DIR)
140 VPATH := $(VPATH):$(FATFS_DIR)
141 endif
143 ifneq ($(filter SDCARD_SDIO,$(FEATURES)),)
144 INCLUDE_DIRS := $(INCLUDE_DIRS) \
145 $(FATFS_DIR)
146 VPATH := $(VPATH):$(FATFS_DIR)
147 endif
149 #Flags
150 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
152 # Flags that are used in the STM32 libraries
153 DEVICE_FLAGS = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER
156 # H743xI : 2M FLASH, 1M RAM (H753xI also)
157 # H743xG : 1M FLASH, 1M RAM (H753xG also)
158 # H750xB : 128K FLASH, 1M RAM
160 ifeq ($(TARGET),$(filter $(TARGET),$(H743xI_TARGETS)))
161 DEVICE_FLAGS += -DSTM32H743xx
162 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h743_2m.ld
163 STARTUP_SRC = startup_stm32h743xx.s
164 MCU_FLASH_SIZE := 2048
165 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
167 ifeq ($(RAM_BASED),yes)
168 FIRMWARE_SIZE := 448
169 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
170 # and the maximum size of the data stored on the external storage device.
171 MCU_FLASH_SIZE := FIRMWARE_SIZE
172 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h743.ld
173 endif
175 else ifeq ($(TARGET),$(filter $(TARGET),$(H750xB_TARGETS)))
176 DEVICE_FLAGS += -DSTM32H750xx
177 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_flash_h750_128k.ld
178 STARTUP_SRC = startup_stm32h743xx.s
179 DEFAULT_TARGET_FLASH := 128
181 ifeq ($(TARGET_FLASH),)
182 MCU_FLASH_SIZE := $(DEFAULT_TARGET_FLASH)
183 endif
185 ifeq ($(EXST),yes)
186 FIRMWARE_SIZE := 448
187 # TARGET_FLASH now becomes the amount of RAM memory that is occupied by the firmware
188 # and the maximum size of the data stored on the external storage device.
189 MCU_FLASH_SIZE := FIRMWARE_SIZE
190 DEFAULT_LD_SCRIPT = $(LINKER_DIR)/stm32_ram_h750_exst.ld
191 endif
193 ifeq ($(EXST),yes)
194 # Upper 8 regions are reserved for a boot loader in EXST environment
195 DEVICE_FLAGS += -DMAX_MPU_REGIONS=8
196 else
197 DEVICE_FLAGS += -DMAX_MPU_REGIONS=16
198 endif
200 ifneq ($(DEBUG),GDB)
201 OPTIMISE_DEFAULT := -Os
202 OPTIMISE_SPEED := -Os
203 OPTIMISE_SIZE := -Os
205 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
206 endif
208 else
209 $(error Unknown MCU for H7 target)
210 endif
212 ifeq ($(LD_SCRIPT),)
213 LD_SCRIPT = $(DEFAULT_LD_SCRIPT)
214 endif
216 ifneq ($(FIRMWARE_SIZE),)
217 DEVICE_FLAGS += -DFIRMWARE_SIZE=$(FIRMWARE_SIZE)
218 endif
220 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE) -DHSE_STARTUP_TIMEOUT=1000
222 TARGET_FLAGS = -D$(TARGET)
224 VCP_SRC = \
225 vcp_hal/usbd_desc.c \
226 vcp_hal/usbd_conf_stm32h7xx.c \
227 vcp_hal/usbd_cdc_hid.c \
228 vcp_hal/usbd_cdc_interface.c \
229 drivers/serial_usb_vcp.c \
230 drivers/usb_io.c
232 MCU_COMMON_SRC = \
233 startup/system_stm32h7xx.c \
234 drivers/system_stm32h7xx.c \
235 drivers/timer_hal.c \
236 drivers/timer_stm32h7xx.c \
237 drivers/serial_uart_hal.c \
238 drivers/serial_uart_stm32h7xx.c \
239 drivers/bus_quadspi_hal.c \
240 drivers/bus_spi_hal.c \
241 drivers/dma_stm32h7xx.c \
242 drivers/dshot_bitbang.c \
243 drivers/dshot_bitbang_decode.c \
244 drivers/dshot_bitbang_ll.c \
245 drivers/light_ws2811strip_hal.c \
246 drivers/adc_stm32h7xx.c \
247 drivers/bus_i2c_hal.c \
248 drivers/bus_i2c_hal_init.c \
249 drivers/pwm_output_dshot_hal.c \
250 drivers/pwm_output_dshot_shared.c \
251 drivers/persistent.c \
252 drivers/transponder_ir_io_hal.c \
253 drivers/audio_stm32h7xx.c \
254 drivers/memprot_hal.c \
255 drivers/memprot_stm32h7xx.c \
256 #drivers/accgyro/accgyro_mpu.c \
258 MCU_EXCLUDES = \
259 drivers/bus_i2c.c \
260 drivers/timer.c
262 #MSC_SRC = \
263 # drivers/usb_msc_common.c \
264 # drivers/usb_msc_h7xx.c \
265 # msc/usbd_storage.c
267 ifneq ($(filter SDCARD_SDIO,$(FEATURES)),)
268 MCU_COMMON_SRC += \
269 drivers/sdio_h7xx.c
270 MSC_SRC += \
271 msc/usbd_storage_sdio.c
272 endif
274 #ifneq ($(filter SDCARD_SPI,$(FEATURES)),)
275 #MSC_SRC += \
276 # msc/usbd_storage_sd_spi.c
277 #endif
279 #ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
280 #MSC_SRC += \
281 # msc/usbd_storage_emfat.c \
282 # msc/emfat.c \
283 # msc/emfat_file.c
284 #endif
286 DSP_LIB := $(ROOT)/lib/main/CMSIS/DSP
287 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE -DARM_MATH_CM7