summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHierophect <hierophect@gmail.com>2020-01-14 15:50:00 -0500
committerHierophect <hierophect@gmail.com>2020-01-14 15:50:00 -0500
commit05093f7f54d5f0a375d120df40e3335fa92e0a22 (patch)
treefb847c1fbdc5d91d82171edb4e33ae36a77c44b1
parentc0dacba80f3c7490f36dda3fa2c7b0df842c8bcf (diff)
Fix VTOR relocate, add bootloader makefile handling
-rwxr-xr-xports/stm32f4/Makefile6
-rw-r--r--ports/stm32f4/boards/meowbit_v121/mpconfigboard.h1
-rw-r--r--ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk2
-rw-r--r--ports/stm32f4/system_stm32f4xx.c35
4 files changed, 39 insertions, 5 deletions
diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile
index c3eb4aa3b..d948996ea 100755
--- a/ports/stm32f4/Makefile
+++ b/ports/stm32f4/Makefile
@@ -90,6 +90,10 @@ else
### 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)
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
@@ -257,7 +261,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
$(BUILD)/firmware.uf2: $(BUILD)/firmware.hex
$(ECHO) "Create $@"
- $(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0x57755a57 -b 0x08010000 -c -o "$(BUILD)/firmware.uf2" $^
+ $(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0x57755a57 -b $(BOOTLOADER_OFFSET) -c -o "$(BUILD)/firmware.uf2" $^
include $(TOP)/py/mkrules.mk
diff --git a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h
index 0371685d8..0de74a946 100644
--- a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h
+++ b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.h
@@ -37,6 +37,7 @@
#define BOARD_OSC_DIV 12
#define BOARD_NO_VBUS_SENSE
+#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
// On-board flash
#define SPI_FLASH_MOSI_PIN (&pin_PB15)
diff --git a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk
index c033d1d4b..1d6f68b13 100644
--- a/ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk
+++ b/ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk
@@ -9,6 +9,8 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = W25Q16JV_IQ
LONGINT_IMPL = MPZ
+BOOTLOADER_OFFSET = 0x8010000
+
# INTERNAL_FLASH_FILESYSTEM = 1
# LONGINT_IMPL = NONE
diff --git a/ports/stm32f4/system_stm32f4xx.c b/ports/stm32f4/system_stm32f4xx.c
index 3303f969d..bce420056 100644
--- a/ports/stm32f4/system_stm32f4xx.c
+++ b/ports/stm32f4/system_stm32f4xx.c
@@ -1,3 +1,27 @@
+/*
+ * Taken from ST Cube library and modified. See below for original header.
+ *
+ * Modifications copyright (c) 2019 Lucian Copeland for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
/**
******************************************************************************
* @file system_stm32f4xx.c
@@ -63,6 +87,7 @@
#include "stm32f4xx.h"
+#include "py/mpconfig.h"
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */
@@ -193,10 +218,12 @@ void SystemInit(void)
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
/* Configure the Vector Table location add offset address ------------------*/
-#ifdef VECT_TAB_SRAM
- SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
-#else
- SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
+#if !defined(BOARD_VTOR_DEFER) //only set VTOR if the bootloader hasn't already
+ #ifdef VECT_TAB_SRAM
+ SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
+ #else
+ SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
+ #endif
#endif
}