From 632d53ceb993969a4ea88bdcc13258386b5936b7 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Fri, 11 Aug 2023 15:51:22 +0200 Subject: [PATCH] relocate isr vector to ram --- src/system/stm32f405/flash_layout.ld | 5 ++++- src/system/stm32f405/system.c | 11 ++++++++-- src/system/stm32f411/flash_layout.ld | 5 ++++- src/system/stm32f411/system.c | 11 ++++++++-- src/system/stm32f722/flash_layout.ld | 7 +++++-- src/system/stm32f722/system.c | 11 ++++++++-- src/system/stm32f745/flash_layout.ld | 7 +++++-- src/system/stm32f745/system.c | 11 ++++++++-- src/system/stm32f765/flash_layout.ld | 5 ++++- src/system/stm32f765/system.c | 11 ++++++++-- src/system/stm32h743/flash_layout.ld | 5 ++++- src/system/stm32h743/system.c | 31 +++++++--------------------- 12 files changed, 79 insertions(+), 41 deletions(-) diff --git a/src/system/stm32f405/flash_layout.ld b/src/system/stm32f405/flash_layout.ld index ef3b63885..ef3a3d667 100644 --- a/src/system/stm32f405/flash_layout.ld +++ b/src/system/stm32f405/flash_layout.ld @@ -69,12 +69,15 @@ SECTIONS } >FLASH_CONFIG /* The startup code goes first into FLASH */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data goes into FLASH */ .text : diff --git a/src/system/stm32f405/system.c b/src/system/stm32f405/system.c index cebf49908..76da01d0b 100644 --- a/src/system/stm32f405/system.c +++ b/src/system/stm32f405/system.c @@ -119,6 +119,8 @@ #include "stm32f4xx.h" +#include + /** * @} */ @@ -142,7 +144,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -243,7 +245,12 @@ __attribute__((__used__)) void SystemInit() { /* 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 */ + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); + + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif diff --git a/src/system/stm32f411/flash_layout.ld b/src/system/stm32f411/flash_layout.ld index 621caee06..96423120e 100644 --- a/src/system/stm32f411/flash_layout.ld +++ b/src/system/stm32f411/flash_layout.ld @@ -67,12 +67,15 @@ SECTIONS } >FLASH_CONFIG /* The startup code goes first into FLASH */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data goes into FLASH */ .text : diff --git a/src/system/stm32f411/system.c b/src/system/stm32f411/system.c index 073389890..b0c7f1d01 100644 --- a/src/system/stm32f411/system.c +++ b/src/system/stm32f411/system.c @@ -119,6 +119,8 @@ #include "stm32f4xx.h" +#include + /** * @} */ @@ -142,7 +144,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ \ \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -243,7 +245,12 @@ __attribute__((__used__)) void SystemInit() { /* 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 */ + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); + + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif diff --git a/src/system/stm32f722/flash_layout.ld b/src/system/stm32f722/flash_layout.ld index f42c4f394..2f86ec716 100644 --- a/src/system/stm32f722/flash_layout.ld +++ b/src/system/stm32f722/flash_layout.ld @@ -35,13 +35,16 @@ SECTIONS _config_flash_end = .; } >FLASH_CONFIG - /* The startup code into "FLASH" Rom type memory */ + /* The startup code goes first into FLASH */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data into "FLASH_CODE" Rom type memory */ .text : diff --git a/src/system/stm32f722/system.c b/src/system/stm32f722/system.c index 84373a490..579dc6e7a 100644 --- a/src/system/stm32f722/system.c +++ b/src/system/stm32f722/system.c @@ -65,6 +65,8 @@ #include "stm32f7xx.h" +#include + #if !defined(HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */ #endif /* HSE_VALUE */ @@ -114,7 +116,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -284,7 +286,12 @@ __attribute__((__used__)) void SystemInit() { /* Configure the Vector Table location add offset address ------------------*/ #ifdef VECT_TAB_SRAM - SCB->VTOR = RAMDTCM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); + + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif diff --git a/src/system/stm32f745/flash_layout.ld b/src/system/stm32f745/flash_layout.ld index d3380b20e..2d7b5de69 100644 --- a/src/system/stm32f745/flash_layout.ld +++ b/src/system/stm32f745/flash_layout.ld @@ -35,13 +35,16 @@ SECTIONS _config_flash_end = .; } >FLASH_CONFIG - /* The startup code into "FLASH" Rom type memory */ + /* The startup code goes first into FLASH */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data into "FLASH_CODE" Rom type memory */ .text : diff --git a/src/system/stm32f745/system.c b/src/system/stm32f745/system.c index 84373a490..afd43c688 100644 --- a/src/system/stm32f745/system.c +++ b/src/system/stm32f745/system.c @@ -65,6 +65,8 @@ #include "stm32f7xx.h" +#include + #if !defined(HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */ #endif /* HSE_VALUE */ @@ -114,7 +116,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -284,7 +286,12 @@ __attribute__((__used__)) void SystemInit() { /* Configure the Vector Table location add offset address ------------------*/ #ifdef VECT_TAB_SRAM - SCB->VTOR = RAMDTCM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); + + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif diff --git a/src/system/stm32f765/flash_layout.ld b/src/system/stm32f765/flash_layout.ld index b95003db8..f872e4e6d 100644 --- a/src/system/stm32f765/flash_layout.ld +++ b/src/system/stm32f765/flash_layout.ld @@ -37,12 +37,15 @@ SECTIONS } >FLASH_CONFIG /* The startup code into "FLASH" Rom type memory */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data into "FLASH_CODE" Rom type memory */ .text : diff --git a/src/system/stm32f765/system.c b/src/system/stm32f765/system.c index 84373a490..579dc6e7a 100644 --- a/src/system/stm32f765/system.c +++ b/src/system/stm32f765/system.c @@ -65,6 +65,8 @@ #include "stm32f7xx.h" +#include + #if !defined(HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */ #endif /* HSE_VALUE */ @@ -114,7 +116,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -284,7 +286,12 @@ __attribute__((__used__)) void SystemInit() { /* Configure the Vector Table location add offset address ------------------*/ #ifdef VECT_TAB_SRAM - SCB->VTOR = RAMDTCM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); + + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif diff --git a/src/system/stm32h743/flash_layout.ld b/src/system/stm32h743/flash_layout.ld index e7b10ebcb..5fc81e68a 100644 --- a/src/system/stm32h743/flash_layout.ld +++ b/src/system/stm32h743/flash_layout.ld @@ -38,12 +38,15 @@ SECTIONS } >FLASH_CONFIG /* The startup code into "FLASH" Rom type memory */ + _isr_vector_data = LOADADDR(.isr_vector); .isr_vector : { . = ALIGN(4); + _isr_vector_start = .; KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + _isr_vector_end = .; + } >RAM AT> FLASH /* The program code and other data into "FLASH_CODE" Rom type memory */ .text : diff --git a/src/system/stm32h743/system.c b/src/system/stm32h743/system.c index 1dc040051..345de2904 100644 --- a/src/system/stm32h743/system.c +++ b/src/system/stm32h743/system.c @@ -51,6 +51,8 @@ #include "stm32h7xx.h" +#include + /** @addtogroup CMSIS * @{ */ @@ -103,7 +105,7 @@ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ -/* #define VECT_TAB_SRAM */ +#define VECT_TAB_SRAM #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. \ This value must be a multiple of 0x200. */ /******************************************************************************/ @@ -783,29 +785,12 @@ __attribute__((__used__)) void SystemInit(void) { /* Configure the Vector Table location add offset address ------------------*/ #if defined(VECT_TAB_SRAM) -#if defined(STM32H743xx) || defined(STM32H750xx) || defined(STM32H723xx) || defined(STM32H725xx) || defined(STM32H730xx) - SCB->VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal ITCMSRAM */ -#elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) - SCB->VTOR = CD_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal ITCMSRAM */ -#else -#error Unknown MCU type -#endif -#elif defined(USE_EXST) - extern uint8_t isr_vector_table_base; + extern uint8_t _isr_vector_start; + extern uint8_t _isr_vector_end; + extern uint8_t _isr_vector_data; + memcpy(&_isr_vector_start, &_isr_vector_data, (size_t)(&_isr_vector_end - &_isr_vector_start)); - SCB->VTOR = (uint32_t)&isr_vector_table_base; -#if defined(STM32H730xx) - /* Configure the Vector Table location add offset address ------------------*/ - - extern uint8_t isr_vector_table_flash_base; - extern uint8_t isr_vector_table_end; - - extern uint8_t ram_isr_vector_table_base; - - memcpy(&ram_isr_vector_table_base, &isr_vector_table_flash_base, (size_t)(&isr_vector_table_end - &isr_vector_table_base)); - - SCB->VTOR = (uint32_t)&ram_isr_vector_table_base; -#endif + SCB->VTOR = (uint32_t)&_isr_vector_start; #else SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif