From b4dcecb266bd1aba0a94d11ac6d8a044f6822b69 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Fri, 31 Jan 2020 13:12:58 -0500 Subject: [PATCH] Add build option for UF2 flash offset --- ports/stm32f4/Makefile | 49 ++++++++++++------- .../feather_stm32f405_express/mpconfigboard.h | 4 +- .../mpconfigboard.mk | 8 +-- .../boards/pyboard_v11/mpconfigboard.mk | 3 +- .../stm32f411ce_blackpill/mpconfigboard.mk | 3 +- .../stm32f411ve_discovery/mpconfigboard.mk | 2 - .../stm32f412zg_discovery/mpconfigboard.mk | 3 +- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index ccadeac8a4..082d050390 100755 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -26,11 +26,11 @@ # Select the board to build for. ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) + $(error You must provide a BOARD parameter) else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif + ifeq ($(wildcard boards/$(BOARD)/.),) + $(error Invalid BOARD specified) + endif endif # If the build directory is not given, make it reflect the board name. @@ -80,19 +80,16 @@ INC += -I../../supervisor/shared/usb #Debugging/Optimization ifeq ($(DEBUG), 1) - CFLAGS += -ggdb - # You may want to enable these flags to make setting breakpoints easier. - CFLAGS += -fno-inline -fno-ipa-sra + CFLAGS += -ggdb + # You may want to enable these flags to make setting breakpoints easier. + CFLAGS += -fno-inline -fno-ipa-sra else - CFLAGS += -Os -DNDEBUG - CFLAGS += -ggdb - # TODO: Test with -flto - ### CFLAGS += -flto + CFLAGS += -Os -DNDEBUG + CFLAGS += -ggdb + # TODO: Test with -flto + ### CFLAGS += -flto endif -ifndef BOOTLOADER_OFFSET - BOOTLOADER_OFFSET := 0x8000000 -endif C_DEFS = -DMCU_PACKAGE=$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(CMSIS_MCU) @@ -115,6 +112,22 @@ CFLAGS += \ # TODO: check this CFLAGS += -D__START=main +#need both command and valid file to use uf2 bootloader +ifndef LD_FILE + ifneq ($(and $(UF2_BOOTLOADER),$(LD_BOOT)),) + LD_FILE = $(LD_BOOT) + BOOTLOADER_OFFSET = $(UF2_OFFSET) + CFLAGS += -DUF2_BOOTLOADER_ENABLED + else + LD_FILE = $(LD_FS) + endif +endif + +# Add bootloader specific items +ifndef BOOTLOADER_OFFSET + BOOTLOADER_OFFSET := 0x8000000 +endif + LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs LIBS := -lgcc -lc @@ -210,12 +223,12 @@ SRC_S = \ boards/startup_$(MCU_SUB_VARIANT).s SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ - $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ - $(addprefix common-hal/, $(SRC_COMMON_HAL)) + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ - $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ - $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) ifneq ($(FROZEN_MPY_DIR),) diff --git a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h index fb98397a98..ad9bba7b0a 100644 --- a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h +++ b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h @@ -41,7 +41,9 @@ #define SPI_FLASH_CS_PIN (&pin_PA15) // Bootloader only -#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader +#ifdef UF2_BOOTLOADER_ENABLED + #define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader +#endif #define DEFAULT_I2C_BUS_SCL (&pin_PB06) #define DEFAULT_I2C_BUS_SDA (&pin_PB07) diff --git a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.mk b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.mk index 4fa59d70fb..95bc6c75e6 100644 --- a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.mk +++ b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.mk @@ -9,12 +9,12 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ -BOOTLOADER_OFFSET = 0x8010000 - MCU_SERIES = m4 MCU_VARIANT = stm32f4 MCU_SUB_VARIANT = stm32f405xx MCU_PACKAGE = 64 CMSIS_MCU = STM32F405xx -LD_FILE = boards/STM32F405_boot.ld # use for bootloader (external fs only) -# LD_FILE = boards/STM32F405_fs.ld # use for internal filesystem \ No newline at end of file + +LD_FS = boards/STM32F405_fs.ld # Default to internal FS +LD_BOOT = boards/STM32F405_boot.ld # UF2 boot option +UF2_OFFSET = 0x8010000 diff --git a/ports/stm32f4/boards/pyboard_v11/mpconfigboard.mk b/ports/stm32f4/boards/pyboard_v11/mpconfigboard.mk index a01ff7923c..b83852c4cf 100644 --- a/ports/stm32f4/boards/pyboard_v11/mpconfigboard.mk +++ b/ports/stm32f4/boards/pyboard_v11/mpconfigboard.mk @@ -13,5 +13,4 @@ MCU_SUB_VARIANT = stm32f405xx MCU_PACKAGE = 64 CMSIS_MCU = STM32F405xx LD_FILE = boards/STM32F405.ld -TEXT0_ADDR = 0x08000000 -TEXT1_ADDR = 0x08010000 + diff --git a/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.mk index d4f0f9577f..68c6a1eeaa 100644 --- a/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.mk @@ -18,5 +18,4 @@ MCU_SUB_VARIANT = stm32f411xe MCU_PACKAGE = 48 CMSIS_MCU = STM32F411xE LD_FILE = boards/STM32F411VETx_FLASH.ld -TEXT0_ADDR = 0x08000000 -TEXT1_ADDR = 0x08020000 + diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index d6f369b6ea..1f91bd8bc5 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -13,5 +13,3 @@ MCU_SUB_VARIANT = stm32f411xe MCU_PACKAGE = 100 CMSIS_MCU = STM32F411xE LD_FILE = boards/STM32F411VETx_FLASH.ld -TEXT0_ADDR = 0x08000000 -TEXT1_ADDR = 0x08020000 \ No newline at end of file diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk index d642f243ef..b0205fc733 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk @@ -18,6 +18,5 @@ MCU_SUB_VARIANT = stm32f412zx MCU_PACKAGE = 144 CMSIS_MCU = STM32F412Zx LD_FILE = boards/STM32F412ZGTx_FLASH.ld -TEXT0_ADDR = 0x08000000 -TEXT1_ADDR = 0x08020000 +