Skip to content

Commit

Permalink
relocate isr vector to ram
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 8, 2023
1 parent 4fbcf1a commit e17417b
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 41 deletions.
5 changes: 4 additions & 1 deletion src/system/stm32f405/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 9 additions & 2 deletions src/system/stm32f405/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

#include "stm32f4xx.h"

#include <string.h>

/**
* @}
*/
Expand All @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/system/stm32f411/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 9 additions & 2 deletions src/system/stm32f411/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

#include "stm32f4xx.h"

#include <string.h>

/**
* @}
*/
Expand All @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/system/stm32f722/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 9 additions & 2 deletions src/system/stm32f722/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

#include "stm32f7xx.h"

#include <string.h>

#if !defined(HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
#endif /* HSE_VALUE */
Expand Down Expand Up @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/system/stm32f745/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 9 additions & 2 deletions src/system/stm32f745/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

#include "stm32f7xx.h"

#include <string.h>

#if !defined(HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
#endif /* HSE_VALUE */
Expand Down Expand Up @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/system/stm32f765/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 9 additions & 2 deletions src/system/stm32f765/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

#include "stm32f7xx.h"

#include <string.h>

#if !defined(HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
#endif /* HSE_VALUE */
Expand Down Expand Up @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/system/stm32h743/flash_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
31 changes: 8 additions & 23 deletions src/system/stm32h743/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

#include "stm32h7xx.h"

#include <string.h>

/** @addtogroup CMSIS
* @{
*/
Expand Down Expand Up @@ -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. */
/******************************************************************************/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e17417b

Please sign in to comment.