From 81a7293ed63bb39e05e4303f7ad297807748c7ea Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Jun 2020 13:56:20 +1000 Subject: [PATCH] stm32/mboot: Set VTOR on start up to ensure it has the correct value. Commit 8675858465f3d83aab709170eab6dc141570acf4 switched to using the CMSIS provided SystemInit function which sets VTOR to 0x00000000 (previously it was 0x08000000). A VTOR of 0x00000000 will be correct on some MCUs but not on others where the built-in bootloader is remapped to this address, via __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(). To make sure mboot has the correct vector table, this commit explicitly sets VTOR to the correct value of 0x08000000. Signed-off-by: Damien George --- ports/stm32/mboot/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index b3af495261..b3e63ccc26 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -1285,6 +1285,9 @@ void stm32_main(int initial_r0) { RCC->D3CCIPR = 0x00000000; #endif + // Make sure IRQ vector table points to flash where this bootloader lives. + SCB->VTOR = FLASH_BASE; + // Enable 8-byte stack alignment for IRQ handlers, in accord with EABI SCB->CCR |= SCB_CCR_STKALIGN_Msk;