2018-05-24 09:15:20 -04:00
|
|
|
# Select the board to build for: if not given on the command line,
|
|
|
|
# then default to PYBV10.
|
|
|
|
BOARD ?= PYBV10
|
|
|
|
|
|
|
|
# If the build directory is not given, make it reflect the board name.
|
|
|
|
BUILD ?= build-$(BOARD)
|
|
|
|
|
2019-02-13 08:01:14 -05:00
|
|
|
# Allow the directory containing the board configuration to be specified
|
|
|
|
BOARD_DIR ?= $(abspath ../boards/$(BOARD))
|
|
|
|
|
2019-03-14 22:27:54 -04:00
|
|
|
# Set USE_MBOOT to 1 so that TEXT0_ADDR gets set properly for those boards
|
|
|
|
# that can be built with or without mboot.
|
|
|
|
USE_MBOOT ?= 1
|
|
|
|
|
2021-01-14 11:00:40 -05:00
|
|
|
# Set MBOOT_ENABLE_PACKING to 1 to enable DFU packing with encryption and signing.
|
|
|
|
# Ensure the MBOOT_PACK_xxx values match stm32/Makefile, to build matching application firmware.
|
|
|
|
MBOOT_ENABLE_PACKING ?= 0
|
|
|
|
MBOOT_PACK_CHUNKSIZE ?= 16384
|
|
|
|
MBOOT_PACK_KEYS_FILE ?= $(BOARD_DIR)/mboot_keys.h
|
|
|
|
|
2019-02-13 08:01:14 -05:00
|
|
|
# Sanity check that the board configuration directory exists
|
|
|
|
ifeq ($(wildcard $(BOARD_DIR)/.),)
|
|
|
|
$(error Invalid BOARD specified: $(BOARD_DIR))
|
|
|
|
endif
|
|
|
|
|
2021-04-28 02:10:42 -04:00
|
|
|
# Enable BUILDING_MBOOT so boards can configure their .mk file accordingly.
|
|
|
|
BUILDING_MBOOT = 1
|
|
|
|
|
2018-05-24 09:15:20 -04:00
|
|
|
include ../../../py/mkenv.mk
|
2019-02-13 08:01:14 -05:00
|
|
|
include $(BOARD_DIR)/mpconfigboard.mk
|
2018-05-24 09:15:20 -04:00
|
|
|
|
2021-04-28 02:45:51 -04:00
|
|
|
# A board can set MBOOT_TEXT0_ADDR to a custom location where mboot should reside.
|
|
|
|
MBOOT_TEXT0_ADDR ?= 0x08000000
|
|
|
|
|
2018-05-24 09:15:20 -04:00
|
|
|
USBDEV_DIR=usbdev
|
|
|
|
DFU=$(TOP)/tools/dfu.py
|
|
|
|
PYDFU ?= $(TOP)/tools/pydfu.py
|
2020-02-24 01:20:20 -05:00
|
|
|
BOOTLOADER_DFU_USB_VID ?= 0x0483
|
|
|
|
BOOTLOADER_DFU_USB_PID ?= 0xDF11
|
2018-05-24 09:15:20 -04:00
|
|
|
STFLASH ?= st-flash
|
|
|
|
OPENOCD ?= openocd
|
|
|
|
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
|
2021-02-21 19:54:31 -05:00
|
|
|
|
|
|
|
include ../stm32.mk
|
2018-05-24 09:15:20 -04:00
|
|
|
|
2019-12-21 15:22:26 -05:00
|
|
|
CROSS_COMPILE ?= arm-none-eabi-
|
2018-05-24 09:15:20 -04:00
|
|
|
|
|
|
|
INC += -I.
|
|
|
|
INC += -I..
|
|
|
|
INC += -I$(TOP)
|
|
|
|
INC += -I$(BUILD)
|
|
|
|
INC += -I$(TOP)/lib/cmsis/inc
|
2021-02-21 19:54:31 -05:00
|
|
|
INC += -I$(STM32LIB_CMSIS_ABS)/Include
|
|
|
|
INC += -I$(STM32LIB_HAL_ABS)/Inc
|
2018-05-24 09:15:20 -04:00
|
|
|
INC += -I../$(USBDEV_DIR)/core/inc -I../$(USBDEV_DIR)/class/inc
|
|
|
|
|
2020-06-23 00:00:16 -04:00
|
|
|
# Standard C functions like memset need to be compiled with special flags so
|
|
|
|
# the compiler does not optimise these functions in terms of themselves.
|
|
|
|
CFLAGS_BUILTIN ?= -ffreestanding -fno-builtin -fno-lto
|
|
|
|
|
2020-04-09 07:59:11 -04:00
|
|
|
CFLAGS = $(INC) -Wall -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -Werror -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_EXTRA)
|
2018-05-24 09:15:20 -04:00
|
|
|
CFLAGS += -D$(CMSIS_MCU)
|
|
|
|
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
|
|
|
|
CFLAGS += $(COPT)
|
2019-02-13 08:01:14 -05:00
|
|
|
CFLAGS += -I$(BOARD_DIR)
|
2018-05-24 09:15:20 -04:00
|
|
|
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
|
|
|
|
CFLAGS += -DBOARD_$(BOARD)
|
2021-04-28 02:45:51 -04:00
|
|
|
CFLAGS += -DMBOOT_VTOR=$(MBOOT_TEXT0_ADDR)
|
2018-05-24 09:15:20 -04:00
|
|
|
CFLAGS += -DAPPLICATION_ADDR=$(TEXT0_ADDR)
|
2019-02-14 22:31:48 -05:00
|
|
|
CFLAGS += -DFFCONF_H=\"ports/stm32/mboot/ffconf.h\"
|
2020-06-23 09:58:26 -04:00
|
|
|
CFLAGS += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
|
2020-12-08 19:02:47 -05:00
|
|
|
CFLAGS += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT -DLFS2_READONLY
|
2021-04-28 02:10:42 -04:00
|
|
|
CFLAGS += -DBUILDING_MBOOT=$(BUILDING_MBOOT)
|
2020-11-03 23:29:31 -05:00
|
|
|
CFLAGS += -DMICROPY_HW_STM32WB_FLASH_SYNCRONISATION=0
|
2020-02-24 01:20:20 -05:00
|
|
|
CFLAGS += -DBOOTLOADER_DFU_USB_VID=$(BOOTLOADER_DFU_USB_VID) -DBOOTLOADER_DFU_USB_PID=$(BOOTLOADER_DFU_USB_PID)
|
2018-05-24 09:15:20 -04:00
|
|
|
|
2021-04-28 02:26:20 -04:00
|
|
|
MBOOT_LD_FILES ?= stm32_memory.ld stm32_sections.ld
|
|
|
|
LDFLAGS = -nostdlib -L . $(addprefix -T,$(MBOOT_LD_FILES)) -Map=$(@:.elf=.map) --cref
|
2018-05-24 09:15:20 -04:00
|
|
|
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
|
|
|
|
|
|
|
# Remove uncalled code from the final image.
|
|
|
|
CFLAGS += -fdata-sections -ffunction-sections
|
|
|
|
LDFLAGS += --gc-sections
|
|
|
|
|
|
|
|
# Debugging/Optimization
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CFLAGS += -g -DPENDSV_DEBUG
|
2021-02-01 23:09:15 -05:00
|
|
|
COPT = -Og
|
2018-05-24 09:15:20 -04:00
|
|
|
else
|
|
|
|
COPT += -Os -DNDEBUG
|
|
|
|
endif
|
|
|
|
|
2021-07-09 00:19:15 -04:00
|
|
|
$(BUILD)/shared/libc/string0.o: CFLAGS += $(CFLAGS_BUILTIN)
|
2021-04-28 02:10:42 -04:00
|
|
|
LIB_SRC_C += \
|
2021-07-09 00:19:15 -04:00
|
|
|
shared/libc/string0.c \
|
2020-06-23 09:58:26 -04:00
|
|
|
lib/littlefs/lfs1.c \
|
|
|
|
lib/littlefs/lfs1_util.c \
|
|
|
|
lib/littlefs/lfs2.c \
|
|
|
|
lib/littlefs/lfs2_util.c \
|
2019-02-14 22:31:48 -05:00
|
|
|
lib/oofatfs/ff.c \
|
2019-03-05 23:52:36 -05:00
|
|
|
lib/oofatfs/ffunicode.c \
|
2021-07-12 02:34:43 -04:00
|
|
|
lib/uzlib/adler32.c \
|
|
|
|
lib/uzlib/crc32.c \
|
|
|
|
lib/uzlib/tinfgzip.c \
|
|
|
|
lib/uzlib/tinflate.c
|
2018-05-24 09:15:20 -04:00
|
|
|
|
2021-04-28 02:10:42 -04:00
|
|
|
SRC_C += \
|
2018-05-24 09:15:20 -04:00
|
|
|
main.c \
|
2019-02-14 22:31:48 -05:00
|
|
|
elem.c \
|
|
|
|
fsload.c \
|
2020-06-23 08:57:16 -04:00
|
|
|
gzstream.c \
|
2021-01-14 11:00:40 -05:00
|
|
|
pack.c \
|
2022-03-17 02:11:44 -04:00
|
|
|
sdcard.c \
|
2022-03-23 07:28:58 -04:00
|
|
|
ui.c \
|
2020-06-23 08:57:16 -04:00
|
|
|
vfs_fat.c \
|
2020-06-23 09:58:26 -04:00
|
|
|
vfs_lfs.c \
|
2018-05-24 09:15:20 -04:00
|
|
|
drivers/bus/softspi.c \
|
|
|
|
drivers/bus/softqspi.c \
|
|
|
|
drivers/memory/spiflash.c \
|
2020-06-18 03:27:52 -04:00
|
|
|
ports/stm32/flash.c \
|
|
|
|
ports/stm32/flashbdev.c \
|
2018-05-24 09:15:20 -04:00
|
|
|
ports/stm32/i2cslave.c \
|
2021-04-28 02:12:07 -04:00
|
|
|
ports/stm32/machine_adc.c \
|
2020-06-18 05:35:52 -04:00
|
|
|
ports/stm32/powerctrlboot.c \
|
2018-05-24 09:15:20 -04:00
|
|
|
ports/stm32/qspi.c \
|
|
|
|
ports/stm32/spibdev.c \
|
|
|
|
ports/stm32/usbd_conf.c \
|
2019-02-13 08:01:14 -05:00
|
|
|
$(wildcard $(BOARD_DIR)/*.c)
|
2018-05-24 09:15:20 -04:00
|
|
|
|
2021-04-28 02:10:42 -04:00
|
|
|
SRC_O += \
|
2019-07-08 21:35:47 -04:00
|
|
|
$(STARTUP_FILE) \
|
2020-06-18 04:18:30 -04:00
|
|
|
$(SYSTEM_FILE) \
|
2018-05-24 09:15:20 -04:00
|
|
|
ports/stm32/resethandler.o \
|
|
|
|
|
2021-01-14 11:00:40 -05:00
|
|
|
ifeq ($(MBOOT_ENABLE_PACKING), 1)
|
|
|
|
|
|
|
|
SRC_C += lib/libhydrogen/hydrogen.c
|
|
|
|
|
|
|
|
CFLAGS += -DMBOOT_ENABLE_PACKING=1 -DPARTICLE -DPLATFORM_ID=3
|
|
|
|
CFLAGS += -DMBOOT_PACK_CHUNKSIZE=$(MBOOT_PACK_CHUNKSIZE)
|
|
|
|
CFLAGS += -DMBOOT_PACK_KEYS_FILE=\"$(MBOOT_PACK_KEYS_FILE)\"
|
|
|
|
endif
|
|
|
|
|
2021-02-21 19:54:31 -05:00
|
|
|
$(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_ll_usb.o: CFLAGS += -Wno-attributes
|
|
|
|
SRC_HAL += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
|
2018-05-24 09:15:20 -04:00
|
|
|
hal_cortex.c \
|
2022-03-17 02:11:44 -04:00
|
|
|
hal_dma.c \
|
2018-05-24 09:15:20 -04:00
|
|
|
hal_flash.c \
|
|
|
|
hal_flash_ex.c \
|
|
|
|
hal_pcd.c \
|
|
|
|
hal_pcd_ex.c \
|
2022-01-20 00:08:17 -05:00
|
|
|
hal_rcc.c \
|
2022-01-31 00:55:07 -05:00
|
|
|
hal_rcc_ex.c \
|
2018-05-24 09:15:20 -04:00
|
|
|
ll_usb.c \
|
|
|
|
)
|
|
|
|
|
2022-03-17 02:11:44 -04:00
|
|
|
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h7))
|
|
|
|
SRC_HAL += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
|
|
|
|
hal_mmc.c \
|
|
|
|
hal_sd.c \
|
|
|
|
ll_sdmmc.c \
|
|
|
|
)
|
|
|
|
endif
|
|
|
|
|
2021-04-28 02:10:42 -04:00
|
|
|
SRC_USBDEV += $(addprefix ports/stm32/$(USBDEV_DIR)/,\
|
2018-05-24 09:15:20 -04:00
|
|
|
core/src/usbd_core.c \
|
|
|
|
core/src/usbd_ctlreq.c \
|
|
|
|
core/src/usbd_ioreq.c \
|
|
|
|
)
|
|
|
|
|
2020-04-07 00:50:56 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
2018-05-24 09:15:20 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_O))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
|
|
|
|
|
|
|
|
all: $(TOP)/lib/stm32lib/README.md $(BUILD)/firmware.dfu $(BUILD)/firmware.hex
|
|
|
|
|
|
|
|
# For convenience, automatically fetch required submodules if they don't exist
|
|
|
|
$(TOP)/lib/stm32lib/README.md:
|
|
|
|
$(ECHO) "stm32lib submodule not found, fetching it now..."
|
|
|
|
(cd $(TOP) && git submodule update --init lib/stm32lib)
|
|
|
|
|
2019-02-07 00:06:05 -05:00
|
|
|
.PHONY: deploy deploy-stlink
|
|
|
|
|
2018-05-24 09:15:20 -04:00
|
|
|
deploy: $(BUILD)/firmware.dfu
|
|
|
|
$(ECHO) "Writing $< to the board"
|
|
|
|
$(Q)$(PYTHON) $(PYDFU) -u $<
|
|
|
|
|
2019-02-07 00:06:05 -05:00
|
|
|
deploy-stlink: $(BUILD)/firmware.dfu
|
|
|
|
$(ECHO) "Writing $< to the board via ST-LINK"
|
2021-04-28 02:45:51 -04:00
|
|
|
$(Q)$(STFLASH) write $(BUILD)/firmware.bin $(MBOOT_TEXT0_ADDR)
|
2018-05-24 09:15:20 -04:00
|
|
|
|
|
|
|
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
|
|
|
|
$(ECHO) "Create $@"
|
|
|
|
$(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD)/firmware.bin
|
2021-04-28 02:45:51 -04:00
|
|
|
$(Q)$(PYTHON) $(DFU) -b $(MBOOT_TEXT0_ADDR):$(BUILD)/firmware.bin $@
|
2018-05-24 09:15:20 -04:00
|
|
|
|
|
|
|
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
|
|
|
$(ECHO) "Create $@"
|
|
|
|
$(Q)$(OBJCOPY) -O ihex $< $@
|
|
|
|
|
|
|
|
$(BUILD)/firmware.elf: $(OBJ)
|
|
|
|
$(ECHO) "LINK $@"
|
|
|
|
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
|
|
|
|
$(Q)$(SIZE) $@
|
|
|
|
|
2019-02-13 21:36:32 -05:00
|
|
|
#########################################
|
|
|
|
# Rules to generate header files
|
|
|
|
|
|
|
|
MAKE_PINS = ../boards/make-pins.py
|
|
|
|
PREFIX_FILE = ../boards/stm32f4xx_prefix.c
|
|
|
|
BOARD_PINS = $(BOARD_DIR)/pins.csv
|
|
|
|
HEADER_BUILD = $(BUILD)/genhdr
|
|
|
|
GEN_QSTRDEFS_GENERATED = $(HEADER_BUILD)/qstrdefs.generated.h
|
|
|
|
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
|
|
|
|
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
|
|
|
|
GEN_PINS_QSTR = $(HEADER_BUILD)/pins_qstr.h
|
|
|
|
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
|
|
|
|
GEN_PINS_AF_DEFS = $(HEADER_BUILD)/pins_af_defs.h
|
|
|
|
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
|
|
|
|
|
2019-07-08 21:46:47 -04:00
|
|
|
$(OBJ): $(GEN_QSTRDEFS_GENERATED) $(GEN_PINS_AF_DEFS)
|
2019-02-13 21:36:32 -05:00
|
|
|
|
|
|
|
$(HEADER_BUILD):
|
|
|
|
$(MKDIR) -p $(BUILD)/genhdr
|
|
|
|
|
|
|
|
$(GEN_QSTRDEFS_GENERATED): | $(HEADER_BUILD)
|
|
|
|
$(Q)echo "// empty" > $@
|
|
|
|
|
|
|
|
$(GEN_PINS_AF_DEFS): $(BOARD_PINS) $(MAKE_PINS) ../$(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
|
|
|
|
$(ECHO) "GEN $@"
|
|
|
|
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af ../$(AF_FILE) \
|
|
|
|
--prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) \
|
|
|
|
--af-const $(GEN_PINS_AF_CONST) --af-defs $(GEN_PINS_AF_DEFS) \
|
|
|
|
--af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
|
|
|
|
|
2018-05-24 09:15:20 -04:00
|
|
|
#########################################
|
|
|
|
|
|
|
|
vpath %.S . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.S
|
|
|
|
$(ECHO) "CC $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
vpath %.s . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.s
|
|
|
|
$(ECHO) "AS $<"
|
|
|
|
$(Q)$(AS) -o $@ $<
|
|
|
|
|
|
|
|
define compile_c
|
|
|
|
$(ECHO) "CC $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
|
|
|
|
@# The following fixes the dependency file.
|
|
|
|
@# See http://make.paulandlesley.org/autodep.html for details.
|
|
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
|
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
|
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
|
|
|
$(RM) -f $(@:.o=.d)
|
|
|
|
endef
|
|
|
|
|
|
|
|
vpath %.c . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
|
|
|
# $(sort $(var)) removes duplicates
|
|
|
|
#
|
|
|
|
# The net effect of this, is it causes the objects to depend on the
|
|
|
|
# object directories (but only for existence), and the object directories
|
|
|
|
# will be created if they don't exist.
|
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
|
|
|
$(OBJ_DIRS):
|
|
|
|
$(MKDIR) -p $@
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(RM) -rf $(BUILD) $(CLEAN_EXTRA)
|
|
|
|
.PHONY: clean
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
|
|
|
|
-include $(OBJ:.o=.P)
|