| 1 |
# Select the board to build for: |
| 2 |
ifdef BOARD_DIR |
| 3 |
# Custom board path - remove trailing slash and get the final component of |
| 4 |
# the path as the board name. |
| 5 |
BOARD ?= $(notdir $(BOARD_DIR:/=)) |
| 6 |
else |
| 7 |
# If not given on the command line, then default to PYBV10. |
| 8 |
BOARD ?= PYBV10 |
| 9 |
BOARD_DIR ?= boards/$(BOARD) |
| 10 |
endif |
| 11 |
|
| 12 |
ifeq ($(wildcard $(BOARD_DIR)/.),) |
| 13 |
$(error Invalid BOARD specified: $(BOARD_DIR)) |
| 14 |
endif |
| 15 |
|
| 16 |
ifneq ($(BOARD_VARIANT),) |
| 17 |
ifeq ($(wildcard $(BOARD_DIR)/mpconfigvariant_$(BOARD_VARIANT).mk),) |
| 18 |
$(error Invalid BOARD_VARIANT specified: $(BOARD_VARIANT)) |
| 19 |
endif |
| 20 |
endif |
| 21 |
|
| 22 |
# If the build directory is not given, make it reflect the board name (and |
| 23 |
# optionally the board variant). |
| 24 |
ifneq ($(BOARD_VARIANT),) |
| 25 |
BUILD ?= build-$(BOARD)-$(BOARD_VARIANT) |
| 26 |
else |
| 27 |
BUILD ?= build-$(BOARD) |
| 28 |
endif |
| 29 |
|
| 30 |
include ../../py/mkenv.mk |
| 31 |
-include mpconfigport.mk |
| 32 |
|
| 33 |
# Include board specific .mk file, and optional board variant .mk file. |
| 34 |
include $(BOARD_DIR)/mpconfigboard.mk |
| 35 |
ifeq ($(BOARD_VARIANT),) |
| 36 |
-include $(BOARD_DIR)/mpconfigvariant.mk |
| 37 |
else |
| 38 |
include $(BOARD_DIR)/mpconfigvariant_$(BOARD_VARIANT).mk |
| 39 |
endif |
| 40 |
|
| 41 |
# qstr definitions (must come before including py.mk) |
| 42 |
QSTR_DEFS += qstrdefsport.h |
| 43 |
|
| 44 |
# Files that are generated and needed before the QSTR build. |
| 45 |
QSTR_GLOBAL_DEPENDENCIES += mpconfigboard_common.h $(BOARD_DIR)/mpconfigboard.h $(GEN_STMCONST_HDR) |
| 46 |
|
| 47 |
# MicroPython feature configurations |
| 48 |
MICROPY_ROM_TEXT_COMPRESSION ?= 1 |
| 49 |
|
| 50 |
# File containing description of content to be frozen into firmware. |
| 51 |
FROZEN_MANIFEST ?= boards/manifest.py |
| 52 |
|
| 53 |
# Location of mboot (or other bootloader) if the device has one. |
| 54 |
# Used by machine.bootloader(). |
| 55 |
MBOOT_TEXT0_ADDR ?= 0x08000000 |
| 56 |
|
| 57 |
# include py core make definitions |
| 58 |
include $(TOP)/py/py.mk |
| 59 |
include $(TOP)/extmod/extmod.mk |
| 60 |
|
| 61 |
GIT_SUBMODULES += lib/libhydrogen lib/stm32lib |
| 62 |
|
| 63 |
CROSS_COMPILE ?= arm-none-eabi- |
| 64 |
LD_DIR=boards |
| 65 |
USBDEV_DIR=usbdev |
| 66 |
#USBHOST_DIR=usbhost |
| 67 |
DFU=$(TOP)/tools/dfu.py |
| 68 |
MBOOT_PACK_DFU = mboot/mboot_pack_dfu.py |
| 69 |
# may need to prefix dfu-util with sudo |
| 70 |
USE_PYDFU ?= 1 |
| 71 |
PYDFU ?= $(TOP)/tools/pydfu.py |
| 72 |
DFU_UTIL ?= dfu-util |
| 73 |
BOOTLOADER_DFU_USB_VID ?= 0x0483 |
| 74 |
BOOTLOADER_DFU_USB_PID ?= 0xDF11 |
| 75 |
STFLASH ?= st-flash |
| 76 |
OPENOCD ?= openocd |
| 77 |
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg |
| 78 |
|
| 79 |
include stm32.mk |
| 80 |
|
| 81 |
PLLVALUES = boards/pllvalues.py |
| 82 |
PLLI2SVALUES = boards/plli2svalues.py |
| 83 |
MAKE_PINS = boards/make-pins.py |
| 84 |
BOARD_PINS = $(BOARD_DIR)/pins.csv |
| 85 |
PREFIX_FILE = boards/stm32f4xx_prefix.c |
| 86 |
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c |
| 87 |
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h |
| 88 |
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h |
| 89 |
GEN_PINS_AF_DEFS = $(HEADER_BUILD)/pins_af_defs.h |
| 90 |
|
| 91 |
INSERT_USB_IDS = $(TOP)/tools/insert-usb-ids.py |
| 92 |
FILE2H = $(TOP)/tools/file2h.py |
| 93 |
|
| 94 |
USB_IDS_FILE = mpconfigboard_common.h |
| 95 |
CDCINF_TEMPLATE = pybcdc.inf_template |
| 96 |
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf |
| 97 |
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h |
| 98 |
|
| 99 |
GEN_PLLFREQTABLE_HDR = $(HEADER_BUILD)/pllfreqtable.h |
| 100 |
GEN_PLLI2STABLE_HDR = $(HEADER_BUILD)/plli2stable.h |
| 101 |
GEN_STMCONST_HDR = $(HEADER_BUILD)/modstm_const.h |
| 102 |
GEN_STMCONST_MPZ = $(HEADER_BUILD)/modstm_mpz.h |
| 103 |
CMSIS_MCU_HDR = $(STM32LIB_CMSIS_ABS)/Include/$(CMSIS_MCU_LOWER).h |
| 104 |
|
| 105 |
INC += -I. |
| 106 |
INC += -I$(TOP) |
| 107 |
INC += -I$(BUILD) |
| 108 |
INC += -I$(TOP)/lib/cmsis/inc |
| 109 |
INC += -I$(STM32LIB_CMSIS_ABS)/Include |
| 110 |
INC += -I$(STM32LIB_HAL_ABS)/Inc |
| 111 |
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc |
| 112 |
#INC += -I$(USBHOST_DIR) |
| 113 |
INC += -Ilwip_inc |
| 114 |
|
| 115 |
CFLAGS += $(INC) -Wall -Wpointer-arith -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 -nostdlib $(CFLAGS_EXTRA) |
| 116 |
CFLAGS += -D$(CMSIS_MCU) -DUSE_FULL_LL_DRIVER |
| 117 |
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES)) |
| 118 |
CFLAGS += $(COPT) |
| 119 |
CFLAGS += -I$(BOARD_DIR) |
| 120 |
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>' |
| 121 |
CFLAGS += -DMBOOT_VTOR=$(MBOOT_TEXT0_ADDR) |
| 122 |
CFLAGS += -DMICROPY_HW_VTOR=$(TEXT0_ADDR) |
| 123 |
|
| 124 |
ifeq ($(MCU_SERIES),n6) |
| 125 |
ifeq ($(USE_MBOOT),1) |
| 126 |
CFLAGS += -DMICROPY_HW_RUNS_FROM_EXT_FLASH=1 |
| 127 |
endif |
| 128 |
# as doesn't recognise -mcpu=cortex-m55 |
| 129 |
AFLAGS += -march=armv8.1-m.main |
| 130 |
else |
| 131 |
AFLAGS += $(filter -mcpu=%,$(CFLAGS_MCU_$(MCU_SERIES))) |
| 132 |
endif |
| 133 |
|
| 134 |
# Configure for nan-boxing object model if requested |
| 135 |
ifeq ($(NANBOX),1) |
| 136 |
CFLAGS += -DMP_CONFIGFILE='"mpconfigport_nanbox.h"' |
| 137 |
ifneq ($(MICROPY_FLOAT_IMPL),none) |
| 138 |
MICROPY_FLOAT_IMPL = double |
| 139 |
endif |
| 140 |
endif |
| 141 |
|
| 142 |
# Configure floating point support |
| 143 |
ifeq ($(MICROPY_FLOAT_IMPL),double) |
| 144 |
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE |
| 145 |
else ifeq ($(MICROPY_FLOAT_IMPL),none) |
| 146 |
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE |
| 147 |
else |
| 148 |
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT |
| 149 |
CFLAGS += -fsingle-precision-constant |
| 150 |
endif |
| 151 |
|
| 152 |
# Configure linker include dir for ram/rom isr support |
| 153 |
ifeq ($(MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM),1) |
| 154 |
CFLAGS += -DMICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM=1 |
| 155 |
LD_ISR_DIR = boards/common_isr_ram |
| 156 |
else |
| 157 |
LD_ISR_DIR = boards/common_isr_rom |
| 158 |
endif |
| 159 |
|
| 160 |
LDFLAGS += -nostdlib -L $(LD_DIR) -L $(LD_ISR_DIR) $(addprefix -T,$(LD_FILES)) -Wl,-Map=$(@:.elf=.map) -Wl,--cref |
| 161 |
LDFLAGS += -Wl,--defsym=_estack_reserve=8 |
| 162 |
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)" |
| 163 |
|
| 164 |
# Remove uncalled code from the final image. |
| 165 |
CFLAGS += -fdata-sections -ffunction-sections |
| 166 |
LDFLAGS += -Wl,--gc-sections |
| 167 |
|
| 168 |
ifeq ($(LTO),1) |
| 169 |
CFLAGS += -flto=auto |
| 170 |
# LTO requires passing compiler flags to the linker as it will run the assembler. |
| 171 |
# To avoid risk of missing something relevant, pass all flags except for preprocessor args |
| 172 |
LDFLAGS += $(filter-out -I%,$(filter-out -D%,$(CFLAGS))) |
| 173 |
|
| 174 |
$(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto |
| 175 |
endif |
| 176 |
|
| 177 |
# Debugging/Optimization |
| 178 |
ifeq ($(DEBUG), 1) |
| 179 |
CFLAGS += -g -DPENDSV_DEBUG |
| 180 |
COPT ?= -Og |
| 181 |
# Disable text compression in debug builds |
| 182 |
MICROPY_ROM_TEXT_COMPRESSION = 0 |
| 183 |
else |
| 184 |
ifneq ($(LTO), 1) |
| 185 |
CFLAGS += -g # always include debug info in the ELF, unless LTO is on |
| 186 |
endif |
| 187 |
COPT ?= -Os -DNDEBUG |
| 188 |
endif |
| 189 |
|
| 190 |
# Flags for optional C++ source code |
| 191 |
CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu99,$(CFLAGS)) |
| 192 |
|
| 193 |
# TODO make this common -- shouldn't be using these "private" vars from py.mk |
| 194 |
ifneq ($(SRC_CXX)$(SRC_USERMOD_CXX)$(SRC_USERMOD_LIB_CXX),) |
| 195 |
LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)" |
| 196 |
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))" |
| 197 |
endif |
| 198 |
|
| 199 |
# Options for mpy-cross |
| 200 |
MPY_CROSS_FLAGS += -march=$(MPY_CROSS_MCU_ARCH_$(MCU_SERIES)) |
| 201 |
|
| 202 |
SHARED_SRC_C += $(addprefix shared/,\ |
| 203 |
libc/string0.c \ |
| 204 |
netutils/dhcpserver.c \ |
| 205 |
netutils/netutils.c \ |
| 206 |
netutils/trace.c \ |
| 207 |
readline/readline.c \ |
| 208 |
runtime/gchelper_native.c \ |
| 209 |
runtime/interrupt_char.c \ |
| 210 |
runtime/mpirq.c \ |
| 211 |
runtime/pyexec.c \ |
| 212 |
runtime/softtimer.c \ |
| 213 |
runtime/stdout_helpers.c \ |
| 214 |
runtime/sys_stdio_mphal.c \ |
| 215 |
timeutils/timeutils.c \ |
| 216 |
) |
| 217 |
|
| 218 |
ifeq ($(MICROPY_FLOAT_IMPL),double) |
| 219 |
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_C) |
| 220 |
ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1) |
| 221 |
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_HW_C) |
| 222 |
else |
| 223 |
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_SW_C) |
| 224 |
endif |
| 225 |
else |
| 226 |
LIBM_SRC_C += $(SRC_LIB_LIBM_C) |
| 227 |
ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1) |
| 228 |
LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_HW_C) |
| 229 |
else |
| 230 |
LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_SW_C) |
| 231 |
endif |
| 232 |
endif |
| 233 |
|
| 234 |
DRIVERS_SRC_C += $(addprefix drivers/,\ |
| 235 |
bus/softspi.c \ |
| 236 |
bus/softqspi.c \ |
| 237 |
memory/spiflash.c \ |
| 238 |
dht/dht.c \ |
| 239 |
) |
| 240 |
|
| 241 |
SRC_C += \ |
| 242 |
boardctrl.c \ |
| 243 |
main.c \ |
| 244 |
stm32_it.c \ |
| 245 |
usbd_conf.c \ |
| 246 |
usbd_desc.c \ |
| 247 |
usbd_cdc_interface.c \ |
| 248 |
usbd_hid_interface.c \ |
| 249 |
usbd_msc_interface.c \ |
| 250 |
mphalport.c \ |
| 251 |
mpnetworkport.c \ |
| 252 |
mpthreadport.c \ |
| 253 |
irq.c \ |
| 254 |
pendsv.c \ |
| 255 |
systick.c \ |
| 256 |
powerctrl.c \ |
| 257 |
powerctrlboot.c \ |
| 258 |
rfcore.c \ |
| 259 |
pybthread.c \ |
| 260 |
factoryreset.c \ |
| 261 |
timer.c \ |
| 262 |
led.c \ |
| 263 |
pin.c \ |
| 264 |
pin_defs_stm32.c \ |
| 265 |
pin_named_pins.c \ |
| 266 |
bufhelper.c \ |
| 267 |
dma.c \ |
| 268 |
i2c.c \ |
| 269 |
i2cslave.c \ |
| 270 |
pyb_i2c.c \ |
| 271 |
spi.c \ |
| 272 |
pyb_spi.c \ |
| 273 |
qspi.c \ |
| 274 |
octospi.c \ |
| 275 |
uart.c \ |
| 276 |
ulpi.c \ |
| 277 |
can.c \ |
| 278 |
fdcan.c \ |
| 279 |
pyb_can.c \ |
| 280 |
usb.c \ |
| 281 |
eth.c \ |
| 282 |
eth_phy.c \ |
| 283 |
gccollect.c \ |
| 284 |
help.c \ |
| 285 |
machine_bitstream.c \ |
| 286 |
machine_i2c.c \ |
| 287 |
machine_spi.c \ |
| 288 |
modpyb.c \ |
| 289 |
modstm.c \ |
| 290 |
network_lan.c \ |
| 291 |
extint.c \ |
| 292 |
usrsw.c \ |
| 293 |
rng.c \ |
| 294 |
rtc.c \ |
| 295 |
flash.c \ |
| 296 |
flashbdev.c \ |
| 297 |
spibdev.c \ |
| 298 |
storage.c \ |
| 299 |
sdcard.c \ |
| 300 |
sdram.c \ |
| 301 |
vfs_rom_ioctl.c \ |
| 302 |
fatfs_port.c \ |
| 303 |
lcd.c \ |
| 304 |
accel.c \ |
| 305 |
servo.c \ |
| 306 |
dac.c \ |
| 307 |
adc.c \ |
| 308 |
sdio.c \ |
| 309 |
subghz.c \ |
| 310 |
xspi.c \ |
| 311 |
$(wildcard $(BOARD_DIR)/*.c) |
| 312 |
|
| 313 |
SRC_O += \ |
| 314 |
$(STARTUP_FILE) \ |
| 315 |
$(SYSTEM_FILE) |
| 316 |
|
| 317 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 g0 l0)) |
| 318 |
CSUPEROPT = -Os # save some code space |
| 319 |
SRC_O += \ |
| 320 |
resethandler_m0.o \ |
| 321 |
shared/runtime/gchelper_thumb1.o |
| 322 |
else ifeq ($(MCU_SERIES),l1) |
| 323 |
CFLAGS += -DUSE_HAL_DRIVER |
| 324 |
SRC_O += \ |
| 325 |
resethandler_m3.o \ |
| 326 |
shared/runtime/gchelper_thumb2.o |
| 327 |
else ifeq ($(MCU_SERIES),n6) |
| 328 |
SRC_O += shared/runtime/gchelper_thumb2.o |
| 329 |
ifeq ($(USE_MBOOT),1) |
| 330 |
SRC_O += resethandler_iram.o |
| 331 |
else |
| 332 |
SRC_O += resethandler.o |
| 333 |
endif |
| 334 |
else |
| 335 |
SRC_O += \ |
| 336 |
system_stm32.o \ |
| 337 |
resethandler.o \ |
| 338 |
shared/runtime/gchelper_thumb2.o |
| 339 |
endif |
| 340 |
|
| 341 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 342 |
hal.c \ |
| 343 |
hal_adc.c \ |
| 344 |
hal_adc_ex.c \ |
| 345 |
hal_cortex.c \ |
| 346 |
hal_dma.c \ |
| 347 |
hal_gpio.c \ |
| 348 |
hal_i2c.c \ |
| 349 |
hal_pwr.c \ |
| 350 |
hal_pwr_ex.c \ |
| 351 |
hal_rcc.c \ |
| 352 |
hal_rcc_ex.c \ |
| 353 |
hal_rtc.c \ |
| 354 |
hal_rtc_ex.c \ |
| 355 |
hal_spi.c \ |
| 356 |
hal_tim.c \ |
| 357 |
hal_tim_ex.c \ |
| 358 |
hal_uart.c \ |
| 359 |
ll_rcc.c \ |
| 360 |
ll_utils.c \ |
| 361 |
) |
| 362 |
|
| 363 |
ifneq ($(MCU_SERIES),n6) |
| 364 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 365 |
hal_flash.c \ |
| 366 |
hal_flash_ex.c \ |
| 367 |
) |
| 368 |
endif |
| 369 |
|
| 370 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 n6 wb)) |
| 371 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 372 |
hal_pcd.c \ |
| 373 |
hal_pcd_ex.c \ |
| 374 |
ll_usb.c \ |
| 375 |
) |
| 376 |
endif |
| 377 |
|
| 378 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6)) |
| 379 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 380 |
hal_bsec.c \ |
| 381 |
hal_rif.c \ |
| 382 |
hal_xspi.c \ |
| 383 |
) |
| 384 |
endif |
| 385 |
|
| 386 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h5 h7 l4 n6)) |
| 387 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 388 |
hal_sd.c \ |
| 389 |
ll_sdmmc.c \ |
| 390 |
ll_fmc.c \ |
| 391 |
) |
| 392 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h5)) |
| 393 |
# HAL H5-1.0.0 has a bug with uninitialised variable in HAL_SD_ConfigWideBusOperation. |
| 394 |
$(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_sd.o: CFLAGS += -Wno-error=maybe-uninitialized |
| 395 |
endif |
| 396 |
endif |
| 397 |
|
| 398 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h7)) |
| 399 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 400 |
hal_mmc.c \ |
| 401 |
hal_sdram.c \ |
| 402 |
hal_dcmi.c \ |
| 403 |
) |
| 404 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4)) |
| 405 |
# HAL F4-1.16.0 has a bug with missing parentheses in HAL_MMC_Erase. |
| 406 |
# This function is unused so let the error go by as a warning. |
| 407 |
$(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_mmc.o: CFLAGS += -Wno-error=parentheses |
| 408 |
endif |
| 409 |
endif |
| 410 |
|
| 411 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 n6)) |
| 412 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 413 |
hal_dma_ex.c \ |
| 414 |
) |
| 415 |
endif |
| 416 |
|
| 417 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h5)) |
| 418 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 419 |
hal_icache.c \ |
| 420 |
) |
| 421 |
endif |
| 422 |
|
| 423 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 f4 f7)) |
| 424 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_can.c) |
| 425 |
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),g0 g4 h7)) |
| 426 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_fdcan.c) |
| 427 |
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),l4)) |
| 428 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/Legacy/stm32$(MCU_SERIES)xx_, hal_can.c) |
| 429 |
$(BUILD)/$(STM32LIB_HAL_BASE)/Src/Legacy/stm32$(MCU_SERIES)xx_hal_can.o: CFLAGS += -Wno-error=cpp |
| 430 |
endif |
| 431 |
|
| 432 |
ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),STM32H747xx)) |
| 433 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_hsem.c) |
| 434 |
endif |
| 435 |
|
| 436 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 f4 f7 g0 l0)) |
| 437 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 438 |
hal_i2s.c \ |
| 439 |
) |
| 440 |
endif |
| 441 |
|
| 442 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4)) |
| 443 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 444 |
hal_i2s_ex.c \ |
| 445 |
) |
| 446 |
endif |
| 447 |
|
| 448 |
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h7)) |
| 449 |
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ |
| 450 |
hal_uart_ex.c \ |
| 451 |
) |
| 452 |
endif |
| 453 |
|
| 454 |
USBDEV_SRC_C += $(addprefix $(USBDEV_DIR)/,\ |
| 455 |
core/src/usbd_core.c \ |
| 456 |
core/src/usbd_ctlreq.c \ |
| 457 |
core/src/usbd_ioreq.c \ |
| 458 |
class/src/usbd_cdc_msc_hid.c \ |
| 459 |
class/src/usbd_msc_bot.c \ |
| 460 |
class/src/usbd_msc_scsi.c \ |
| 461 |
) |
| 462 |
|
| 463 |
ifeq ($(MICROPY_SSL_MBEDTLS),1) |
| 464 |
LIB_SRC_C += mbedtls/mbedtls_port.c |
| 465 |
endif |
| 466 |
|
| 467 |
ifeq ($(MICROPY_PY_BLUETOOTH),1) |
| 468 |
SRC_C += mpbthciport.c |
| 469 |
|
| 470 |
ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) |
| 471 |
SRC_C += mpnimbleport.c |
| 472 |
endif |
| 473 |
|
| 474 |
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1) |
| 475 |
SRC_C += mpbtstackport.c |
| 476 |
MICROPY_BLUETOOTH_BTSTACK_H4 ?= 1 |
| 477 |
endif |
| 478 |
|
| 479 |
endif # MICROPY_PY_BLUETOOTH |
| 480 |
|
| 481 |
# Add stm32-specific implementation of libmetal (and optionally OpenAMP's rproc). |
| 482 |
# Note: libmetal code is generated via a pre-processor so ensure that runs first. |
| 483 |
ifeq ($(MICROPY_PY_OPENAMP),1) |
| 484 |
SRC_C += mpmetalport.c |
| 485 |
$(BUILD)/mpmetalport.o: $(BUILD)/openamp/metal/config.h |
| 486 |
ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) |
| 487 |
SRC_C += mpremoteprocport.c |
| 488 |
$(BUILD)/mpremoteprocport.o: $(BUILD)/openamp/metal/config.h |
| 489 |
endif |
| 490 |
endif |
| 491 |
|
| 492 |
# SRC_O should be placed first to work around this LTO bug with binutils <2.35: |
| 493 |
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967 |
| 494 |
OBJ += $(addprefix $(BUILD)/, $(SRC_O)) |
| 495 |
OBJ += $(PY_O) |
| 496 |
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) |
| 497 |
OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o)) |
| 498 |
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o)) |
| 499 |
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o)) |
| 500 |
OBJ += $(addprefix $(BUILD)/, $(HAL_SRC_C:.c=.o)) |
| 501 |
OBJ += $(addprefix $(BUILD)/, $(USBDEV_SRC_C:.c=.o)) |
| 502 |
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 503 |
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) |
| 504 |
OBJ += $(GEN_PINS_SRC:.c=.o) |
| 505 |
|
| 506 |
# This file contains performance critical functions so turn up the optimisation |
| 507 |
# level. It doesn't add much to the code size and improves performance a bit. |
| 508 |
# Don't use -O3 with this file because gcc tries to optimise memset in terms of itself. |
| 509 |
$(BUILD)/shared/libc/string0.o: COPT += -O2 |
| 510 |
|
| 511 |
ifneq ($(MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM),1) |
| 512 |
# If MBOOT or RAM_IFS is not used we put several files into the first 16K section with the ISRs. |
| 513 |
# If we compile these using -O0 then it won't fit. So if you really want these |
| 514 |
# to be compiled with -O0, then edit boards/common.ld (in the .isr_vector section) |
| 515 |
# and comment out the following lines. |
| 516 |
$(BUILD)/$(OOFATFS_DIR)/ff.o: COPT += -Os |
| 517 |
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os |
| 518 |
$(PY_BUILD)/formatfloat.o: COPT += -Os |
| 519 |
$(PY_BUILD)/parsenum.o: COPT += -Os |
| 520 |
$(PY_BUILD)/mpprint.o: COPT += -Os |
| 521 |
endif |
| 522 |
|
| 523 |
all: $(TOP)/lib/stm32lib/README.md all_main $(BUILD)/firmware.hex |
| 524 |
|
| 525 |
ifeq ($(MBOOT_ENABLE_PACKING),1) |
| 526 |
all_main: $(BUILD)/firmware.pack.dfu |
| 527 |
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6)) |
| 528 |
ifeq ($(USE_MBOOT),1) |
| 529 |
all_main: $(BUILD)/firmware.dfu |
| 530 |
else |
| 531 |
all_main: $(BUILD)/firmware-trusted.bin |
| 532 |
endif |
| 533 |
else |
| 534 |
all_main: $(BUILD)/firmware.dfu |
| 535 |
endif |
| 536 |
|
| 537 |
# For convenience, automatically fetch required submodules if they don't exist |
| 538 |
$(TOP)/lib/stm32lib/README.md: |
| 539 |
$(ECHO) "stm32lib submodule not found, fetching it now..." |
| 540 |
(cd $(TOP) && git submodule update --init lib/stm32lib) |
| 541 |
|
| 542 |
define RUN_DFU |
| 543 |
$(ECHO) "Writing $(1) to the board" |
| 544 |
$(if $(filter $(USE_PYDFU),1),\ |
| 545 |
$(Q)$(PYTHON) $(PYDFU) --vid $(BOOTLOADER_DFU_USB_VID) --pid $(BOOTLOADER_DFU_USB_PID) -u $(1), |
| 546 |
$(Q)$(DFU_UTIL) -a 0 -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -D $(1) -s :leave) |
| 547 |
endef |
| 548 |
|
| 549 |
define RUN_STLINK |
| 550 |
$(ECHO) "Writing $(1) to the board via ST-LINK" |
| 551 |
$(Q)$(STFLASH) write $(1) $(2) |
| 552 |
endef |
| 553 |
|
| 554 |
define RUN_OPENOCD |
| 555 |
$(ECHO) "Writing $(1) to the board via ST-LINK using OpenOCD" |
| 556 |
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(1) $(2) $(3) $(4)" |
| 557 |
endef |
| 558 |
|
| 559 |
define GENERATE_ELF |
| 560 |
$(ECHO) "LINK $(1)" |
| 561 |
$(Q)$(CC) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS) |
| 562 |
$(Q)$(SIZE) $(1) |
| 563 |
$(if $(filter-out $(TEXT0_ADDR),0x08000000), \ |
| 564 |
$(ECHO) "INFO: this build requires mboot to be installed first") |
| 565 |
$(if $(filter $(TEXT1_ADDR),0x90000000), \ |
| 566 |
$(ECHO) "INFO: this build places firmware in external QSPI flash") |
| 567 |
endef |
| 568 |
|
| 569 |
define GENERATE_BIN |
| 570 |
$(ECHO) "GEN $(1)" |
| 571 |
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(3)) $(2) $(1) |
| 572 |
endef |
| 573 |
|
| 574 |
define GENERATE_DFU |
| 575 |
$(ECHO) "GEN $(1)" |
| 576 |
$(Q)$(PYTHON) $(DFU) \ |
| 577 |
-D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) \ |
| 578 |
$(if $(2),$(addprefix -b ,$(3):$(2))) \ |
| 579 |
$(if $(4),$(addprefix -b ,$(5):$(4))) \ |
| 580 |
$(1) |
| 581 |
endef |
| 582 |
|
| 583 |
define GENERATE_PACK_DFU |
| 584 |
$(ECHO) "GEN $(1)" |
| 585 |
$(Q)$(PYTHON) $(MBOOT_PACK_DFU) --keys $(MBOOT_PACK_KEYS_FILE) pack-dfu --gzip $(MBOOT_PACK_CHUNKSIZE) $(2) $(1) |
| 586 |
endef |
| 587 |
|
| 588 |
define GENERATE_HEX |
| 589 |
$(ECHO) "GEN $(1)" |
| 590 |
$(Q)$(OBJCOPY) -O ihex $(2) $(1) |
| 591 |
endef |
| 592 |
|
| 593 |
.PHONY: deploy deploy-stlink deploy-openocd deploy-trusted |
| 594 |
|
| 595 |
ifeq ($(MBOOT_ENABLE_PACKING),1) |
| 596 |
deploy: $(BUILD)/firmware.pack.dfu |
| 597 |
$(call RUN_DFU,$^) |
| 598 |
else |
| 599 |
deploy: $(BUILD)/firmware.dfu |
| 600 |
$(call RUN_DFU,$^) |
| 601 |
endif |
| 602 |
|
| 603 |
deploy-trusted: $(BUILD)/firmware-trusted.bin |
| 604 |
$(STM32_CUBE_PROGRAMMER)/bin/STM32_Programmer.sh -c port=SWD mode=HOTPLUG ap=1 -el $(DKEL) -w $^ 0x70000000 -hardRst |
| 605 |
|
| 606 |
# A board should specify TEXT0_ADDR if to use a different location than the |
| 607 |
# default for the firmware memory location. A board can also optionally define |
| 608 |
# TEXT1_ADDR to split the firmware into two sections; see below for details. |
| 609 |
TEXT0_ADDR ?= 0x08000000 |
| 610 |
|
| 611 |
ifeq ($(TEXT1_ADDR),) |
| 612 |
# No TEXT1_ADDR given so put all firmware at TEXT0_ADDR location |
| 613 |
|
| 614 |
TEXT0_SECTIONS ?= .isr_vector .isr_extratext .text .data .ARM |
| 615 |
|
| 616 |
deploy-stlink: $(BUILD)/firmware.bin |
| 617 |
$(call RUN_STLINK,$^,$(TEXT0_ADDR)) |
| 618 |
|
| 619 |
deploy-openocd: $(BUILD)/firmware.bin |
| 620 |
$(call RUN_OPENOCD,$^,$(TEXT0_ADDR)) |
| 621 |
|
| 622 |
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf |
| 623 |
$(call GENERATE_BIN,$@,$^,$(TEXT0_SECTIONS)) |
| 624 |
|
| 625 |
$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin |
| 626 |
$(call GENERATE_DFU,$@,$^,$(TEXT0_ADDR)) |
| 627 |
|
| 628 |
else |
| 629 |
# TEXT0_ADDR and TEXT1_ADDR are specified so split firmware between these locations |
| 630 |
|
| 631 |
TEXT0_SECTIONS ?= .isr_vector .isr_extratext |
| 632 |
TEXT1_SECTIONS ?= .text .data .ARM |
| 633 |
|
| 634 |
deploy-stlink: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin |
| 635 |
$(call RUN_STLINK,$(word 1,$^),$(TEXT0_ADDR)) |
| 636 |
$(call RUN_STLINK,$(word 2,$^),$(TEXT1_ADDR)) |
| 637 |
|
| 638 |
deploy-openocd: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin |
| 639 |
$(call RUN_OPENOCD,$(word 1,$^),$(TEXT0_ADDR),$(word 2,$^),$(TEXT1_ADDR)) |
| 640 |
|
| 641 |
$(BUILD)/firmware0.bin: $(BUILD)/firmware.elf |
| 642 |
$(call GENERATE_BIN,$@,$^,$(TEXT0_SECTIONS)) |
| 643 |
|
| 644 |
$(BUILD)/firmware1.bin: $(BUILD)/firmware.elf |
| 645 |
$(call GENERATE_BIN,$@,$^,$(TEXT1_SECTIONS)) |
| 646 |
|
| 647 |
$(BUILD)/firmware.dfu: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin |
| 648 |
$(call GENERATE_DFU,$@,$(word 1,$^),$(TEXT0_ADDR),$(word 2,$^),$(TEXT1_ADDR)) |
| 649 |
endif |
| 650 |
|
| 651 |
$(BUILD)/firmware.pack.dfu: $(BUILD)/firmware.dfu $(MBOOT_PACK_KEYS_FILE) |
| 652 |
$(call GENERATE_PACK_DFU,$@,$<) |
| 653 |
|
| 654 |
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf |
| 655 |
$(call GENERATE_HEX,$@,$^) |
| 656 |
|
| 657 |
$(BUILD)/firmware.elf: $(OBJ) |
| 658 |
$(call GENERATE_ELF,$@,$^) |
| 659 |
|
| 660 |
$(BUILD)/firmware-trusted.bin: $(BUILD)/firmware.bin |
| 661 |
/bin/rm -f $@ |
| 662 |
$(STM32_CUBE_PROGRAMMER)/bin/STM32_SigningTool_CLI -bin $^ -nk -of 0x80000000 -t fsbl -o $@ -hv $(STM32_N6_HEADER_VERSION) |
| 663 |
|
| 664 |
# List of sources for qstr extraction |
| 665 |
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(GEN_PINS_SRC) |
| 666 |
|
| 667 |
# Making OBJ use an order-only dependency on the generated pins.h file |
| 668 |
# has the side effect of making the pins.h file before we actually compile |
| 669 |
# any of the objects. The normal dependency generation will deal with the |
| 670 |
# case when pins.h is modified. But when it doesn't exist, we don't know |
| 671 |
# which source files might need it. |
| 672 |
$(OBJ): | $(GEN_PINS_HDR) |
| 673 |
|
| 674 |
# With conditional pins, we may need to regenerate qstrdefs.h when config |
| 675 |
# options change. |
| 676 |
$(HEADER_BUILD)/qstrdefs.generated.h: $(BOARD_DIR)/mpconfigboard.h |
| 677 |
|
| 678 |
# main.c can't be even preprocessed without $(GEN_CDCINF_HEADER) |
| 679 |
# As main.c is in SRC_QSTR this will also ensure that GEN_CDCINF_HEADER |
| 680 |
# will be run before QSTR extraction. |
| 681 |
main.c: $(GEN_CDCINF_HEADER) |
| 682 |
|
| 683 |
# Use a pattern rule here so that make will only call make-pins.py once to make |
| 684 |
# both pins_$(BOARD).c and pins.h |
| 685 |
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(HEADER_BUILD)/%_af_defs.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) |
| 686 |
$(ECHO) "GEN $@" |
| 687 |
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \ |
| 688 |
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) \ |
| 689 |
--output-af-const $(GEN_PINS_AF_CONST) --output-af-defs $(GEN_PINS_AF_DEFS) |
| 690 |
|
| 691 |
$(BUILD)/powerctrl.o: $(GEN_PLLFREQTABLE_HDR) |
| 692 |
$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)/qstr.i.last |
| 693 |
$(ECHO) "GEN $@" |
| 694 |
$(Q)$(PYTHON) $(PLLVALUES) -c -m $(CMSIS_MCU_LOWER) file:$(HEADER_BUILD)/qstr.i.last > $@ |
| 695 |
|
| 696 |
$(BUILD)/extmod/machine_i2s.o: $(GEN_PLLI2STABLE_HDR) |
| 697 |
$(GEN_PLLI2STABLE_HDR): $(PLLI2SVALUES) | $(HEADER_BUILD)/qstr.i.last |
| 698 |
$(ECHO) "GEN $@" |
| 699 |
$(Q)$(PYTHON) $(PLLI2SVALUES) -c -m $(CMSIS_MCU_LOWER) file:$(HEADER_BUILD)/qstr.i.last > $@ |
| 700 |
|
| 701 |
$(BUILD)/modstm.o: $(GEN_STMCONST_HDR) |
| 702 |
$(HEADER_BUILD)/modstm_const.h: $(CMSIS_MCU_HDR) make-stmconst.py | $(HEADER_BUILD) |
| 703 |
$(ECHO) "GEN stmconst $@" |
| 704 |
$(Q)$(PYTHON) make-stmconst.py --mpz $(GEN_STMCONST_MPZ) $(CMSIS_MCU_HDR) > $(GEN_STMCONST_HDR) |
| 705 |
|
| 706 |
$(GEN_CDCINF_HEADER): $(GEN_CDCINF_FILE) $(FILE2H) | $(HEADER_BUILD) |
| 707 |
$(ECHO) "GEN $@" |
| 708 |
$(Q)$(PYTHON) $(FILE2H) $< > $@ |
| 709 |
|
| 710 |
$(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FILE) | $(HEADER_BUILD) |
| 711 |
$(ECHO) "GEN $@" |
| 712 |
$(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@ |
| 713 |
|
| 714 |
include $(TOP)/py/mkrules.mk |