Skip to content

Commit 0152f37

Browse files
committed
system: Set VTOR systematically at SystemInit()
When USART Bootloader jumps to application, it doesn't restore VTOR (Bootloader Vector Table is used). It is thus necessary to configure it unconditionally. By the way get ride of USER_VECT_TAB_ADDRESS Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent 1559816 commit 0152f37

File tree

15 files changed

+259
-251
lines changed

15 files changed

+259
-251
lines changed

system/STM32F1xx/system_stm32f1xx.c

+25-9
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,33 @@
7979
/* #define DATA_IN_ExtSRAM */
8080
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
8181

82-
/*!< Uncomment the following line if you need to relocate your vector Table in
83-
Internal SRAM. */
82+
83+
/* Note: Following vector table addresses must be defined in line with linker
84+
configuration. */
85+
86+
/*!< Uncomment the following line and change the address
87+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
88+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
89+
90+
/*!< Uncomment the following line if you need to relocate your vector Table
91+
in Sram else user remap will be done by default in Flash. */
8492
/* #define VECT_TAB_SRAM */
93+
8594
#ifndef VECT_TAB_OFFSET
86-
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
87-
This value must be a multiple of 0x200. */
95+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
96+
This value must be a multiple of 0x200. */
8897
#endif
8998

99+
#ifndef VECT_TAB_BASE_ADDRESS
100+
#if defined(VECT_TAB_SRAM)
101+
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
102+
This value must be a multiple of 0x200. */
103+
#else
104+
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
105+
This value must be a multiple of 0x200. */
106+
#endif /* VECT_TAB_SRAM */
107+
#endif /* VECT_TAB_BASE_ADDRESS */
108+
90109

91110
/**
92111
* @}
@@ -195,11 +214,8 @@ void SystemInit (void)
195214
#endif /* DATA_IN_ExtSRAM */
196215
#endif
197216

198-
#ifdef VECT_TAB_SRAM
199-
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
200-
#else
201-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
202-
#endif
217+
/* Configure the Vector Table location add offset address ------------------*/
218+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
203219
}
204220

205221
/**

system/STM32F2xx/system_stm32f2xx.c

+24-9
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,32 @@
6666
on STM322xG_EVAL board as data memory */
6767
/* #define DATA_IN_ExtSRAM */
6868

69-
/*!< Uncomment the following line if you need to relocate your vector Table in
70-
Internal SRAM. */
69+
/* Note: Following vector table addresses must be defined in line with linker
70+
configuration. */
71+
72+
/*!< Uncomment the following line and change the address
73+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
74+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
75+
76+
/*!< Uncomment the following line if you need to relocate your vector Table
77+
in Sram else user remap will be done by default in Flash. */
7178
/* #define VECT_TAB_SRAM */
79+
7280
#ifndef VECT_TAB_OFFSET
73-
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
74-
This value must be a multiple of 0x200. */
81+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
82+
This value must be a multiple of 0x200. */
7583
#endif
84+
85+
#ifndef VECT_TAB_BASE_ADDRESS
86+
#if defined(VECT_TAB_SRAM)
87+
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
88+
This value must be a multiple of 0x200. */
89+
#else
90+
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
91+
This value must be a multiple of 0x200. */
92+
#endif /* VECT_TAB_SRAM */
93+
#endif /* VECT_TAB_BASE_ADDRESS */
94+
7695
/******************************************************************************/
7796

7897
/**
@@ -155,11 +174,7 @@ void SystemInit(void)
155174
#endif /* DATA_IN_ExtSRAM */
156175

157176
/* Configure the Vector Table location add offset address ------------------*/
158-
#ifdef VECT_TAB_SRAM
159-
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
160-
#else
161-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
162-
#endif
177+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
163178
}
164179

165180
/**

system/STM32F3xx/system_stm32f3xx.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@
8484
/** @addtogroup STM32F3xx_System_Private_Defines
8585
* @{
8686
*/
87-
#ifndef VECT_TAB_OFFSET
88-
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
89-
This value must be a multiple of 0x200. */
90-
#else
91-
#define USER_VECT_TAB_ADDRESS
92-
#endif
9387

9488
/* Note: Following vector table addresses must be defined in line with linker
9589
configuration. */
96-
/*!< Uncomment the following line if you need to relocate the vector table
97-
anywhere in Flash or Sram, else the vector table is kept at the automatic
98-
remap of boot address selected */
99-
/* #define USER_VECT_TAB_ADDRESS */
10090

101-
#if defined(USER_VECT_TAB_ADDRESS)
91+
/*!< Uncomment the following line and change the address
92+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
93+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
94+
10295
/*!< Uncomment the following line if you need to relocate your vector Table
103-
in Sram else user remap will be done in Flash. */
96+
in Sram else user remap will be done by default in Flash. */
10497
/* #define VECT_TAB_SRAM */
98+
99+
#ifndef VECT_TAB_OFFSET
100+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
101+
This value must be a multiple of 0x200. */
102+
#endif
103+
104+
#ifndef VECT_TAB_BASE_ADDRESS
105105
#if defined(VECT_TAB_SRAM)
106106
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
107107
This value must be a multiple of 0x200. */
108108
#else
109109
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
110110
This value must be a multiple of 0x200. */
111111
#endif /* VECT_TAB_SRAM */
112-
#endif /* USER_VECT_TAB_ADDRESS */
112+
#endif /* VECT_TAB_BASE_ADDRESS */
113113

114114
/******************************************************************************/
115115
/**
@@ -194,9 +194,7 @@ void SystemInit(void)
194194
RCC->CIR = 0x009F0000U;
195195

196196
/* Configure the Vector Table location -------------------------------------*/
197-
#if defined(USER_VECT_TAB_ADDRESS)
198-
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation */
199-
#endif /* USER_VECT_TAB_ADDRESS */
197+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
200198
}
201199

202200
/**

system/STM32F4xx/system_stm32f4xx.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,33 @@
7979
#endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
8080
STM32F479xx */
8181

82-
#ifndef VECT_TAB_OFFSET
83-
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
84-
This value must be a multiple of 0x200. */
85-
#else
86-
#define USER_VECT_TAB_ADDRESS
87-
#endif
88-
8982
/* Note: Following vector table addresses must be defined in line with linker
9083
configuration. */
91-
/*!< Uncomment the following line if you need to relocate the vector table
92-
anywhere in Flash or Sram, else the vector table is kept at the automatic
93-
remap of boot address selected */
94-
/* #define USER_VECT_TAB_ADDRESS */
9584

96-
#if defined(USER_VECT_TAB_ADDRESS)
85+
/*!< Uncomment the following line and change the address
86+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
87+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
88+
9789
/*!< Uncomment the following line if you need to relocate your vector Table
98-
in Sram else user remap will be done in Flash. */
90+
in Sram else user remap will be done by default in Flash. */
9991
/* #define VECT_TAB_SRAM */
92+
93+
#ifndef VECT_TAB_OFFSET
94+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
95+
This value must be a multiple of 0x200. */
96+
#endif
97+
98+
#ifndef VECT_TAB_BASE_ADDRESS
10099
#if defined(VECT_TAB_SRAM)
101100
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
102101
This value must be a multiple of 0x200. */
103102
#else
104103
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
105104
This value must be a multiple of 0x200. */
106105
#endif /* VECT_TAB_SRAM */
107-
#endif /* USER_VECT_TAB_ADDRESS */
106+
#endif /* VECT_TAB_BASE_ADDRESS */
107+
108+
108109
/******************************************************************************/
109110

110111
/**
@@ -193,9 +194,7 @@ void SystemInit(void)
193194
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
194195

195196
/* Configure the Vector Table location -------------------------------------*/
196-
#if defined(USER_VECT_TAB_ADDRESS)
197-
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
198-
#endif /* USER_VECT_TAB_ADDRESS */
197+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
199198
}
200199

201200
/**

system/STM32F7xx/system_stm32f7xx.c

+13-14
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,32 @@
6363
*/
6464

6565
/************************* Miscellaneous Configuration ************************/
66+
/* Note: Following vector table addresses must be defined in line with linker
67+
configuration. */
6668

69+
/*!< Uncomment the following line and change the address
70+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
71+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
72+
73+
/*!< Uncomment the following line if you need to relocate your vector Table
74+
in Sram else user remap will be done by default in Flash. */
75+
/* #define VECT_TAB_SRAM */
6776

6877
#ifndef VECT_TAB_OFFSET
6978
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
7079
This value must be a multiple of 0x200. */
71-
#else
72-
#define USER_VECT_TAB_ADDRESS
7380
#endif
7481

75-
/* Note: Following vector table addresses must be defined in line with linker
76-
configuration. */
77-
/*!< Define USER_VECT_TAB_ADDRESS line if you need to relocate the vector table
78-
anywhere in Flash or Sram, else the vector table is kept at the automatic
79-
remap of boot address selected */
80-
#if defined(USER_VECT_TAB_ADDRESS)
81-
/*!< Define VECT_TAB_SRAM if you need to relocate your vector Table
82-
in Sram else user remap will be done in Flash. */
82+
#ifndef VECT_TAB_BASE_ADDRESS
8383
#if defined(VECT_TAB_SRAM)
8484
#define VECT_TAB_BASE_ADDRESS RAMDTCM_BASE /*!< Vector Table base address field.
8585
This value must be a multiple of 0x200. */
8686
#else
8787
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
8888
This value must be a multiple of 0x200. */
8989
#endif /* VECT_TAB_SRAM */
90-
#endif /* USER_VECT_TAB_ADDRESS */
90+
#endif /* VECT_TAB_BASE_ADDRESS */
91+
9192
/******************************************************************************/
9293

9394
/**
@@ -168,9 +169,7 @@ void SystemInit(void)
168169

169170

170171
/* Configure the Vector Table location -------------------------------------*/
171-
#if defined(USER_VECT_TAB_ADDRESS)
172-
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
173-
#endif /* USER_VECT_TAB_ADDRESS */
172+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
174173
}
175174

176175
/**

system/STM32G0xx/system_stm32g0xx.c

+18-19
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,33 @@
9393
*/
9494

9595
/************************* Miscellaneous Configuration ************************/
96-
#ifndef VECT_TAB_OFFSET
97-
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
98-
This value must be a multiple of 0x200. */
99-
#else
100-
#define USER_VECT_TAB_ADDRESS
101-
#endif
102-
10396
/* Note: Following vector table addresses must be defined in line with linker
10497
configuration. */
105-
/*!< Uncomment the following line if you need to relocate the vector table
106-
anywhere in Flash or Sram, else the vector table is kept at the automatic
107-
remap of boot address selected */
108-
/* #define USER_VECT_TAB_ADDRESS */
10998

110-
#if defined(USER_VECT_TAB_ADDRESS)
99+
/*!< Uncomment the following line and change the address
100+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
101+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
102+
111103
/*!< Uncomment the following line if you need to relocate your vector Table
112-
in Sram else user remap will be done in Flash. */
104+
in Sram else user remap will be done by default in Flash. */
113105
/* #define VECT_TAB_SRAM */
106+
107+
#ifndef VECT_TAB_OFFSET
108+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
109+
This value must be a multiple of 0x100. */
110+
#endif
111+
112+
#ifndef VECT_TAB_BASE_ADDRESS
114113
#if defined(VECT_TAB_SRAM)
115114
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
116-
This value must be a multiple of 0x200. */
115+
This value must be a multiple of 0x100. */
117116
#else
118117
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
119-
This value must be a multiple of 0x200. */
118+
This value must be a multiple of 0x100. */
120119
#endif /* VECT_TAB_SRAM */
121-
#endif /* USER_VECT_TAB_ADDRESS */
120+
#endif /* VECT_TAB_BASE_ADDRESS */
121+
122+
122123
/******************************************************************************/
123124
/**
124125
* @}
@@ -197,9 +198,7 @@ void SystemInit(void)
197198
#endif
198199

199200
/* Configure the Vector Table location -------------------------------------*/
200-
#if defined(USER_VECT_TAB_ADDRESS)
201-
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation */
202-
#endif /* USER_VECT_TAB_ADDRESS */
201+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
203202
}
204203

205204
/**

system/STM32G4xx/system_stm32g4xx.c

+15-16
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,32 @@
9494
*/
9595

9696
/************************* Miscellaneous Configuration ************************/
97-
#ifndef VECT_TAB_OFFSET
98-
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
99-
This value must be a multiple of 0x200. */
100-
#else
101-
#define USER_VECT_TAB_ADDRESS
102-
#endif
103-
10497
/* Note: Following vector table addresses must be defined in line with linker
10598
configuration. */
106-
/*!< Uncomment the following line if you need to relocate the vector table
107-
anywhere in Flash or Sram, else the vector table is kept at the automatic
108-
remap of boot address selected */
10999

110-
#if defined(USER_VECT_TAB_ADDRESS)
100+
/*!< Uncomment the following line and change the address
101+
if you need to relocate your vector Table at a custom base address (+ VECT_TAB_OFFSET) */
102+
/* #define VECT_TAB_BASE_ADDRESS 0x08000000 */
103+
111104
/*!< Uncomment the following line if you need to relocate your vector Table
112-
in Sram else user remap will be done in Flash. */
105+
in Sram else user remap will be done by default in Flash. */
113106
/* #define VECT_TAB_SRAM */
107+
108+
#ifndef VECT_TAB_OFFSET
109+
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
110+
This value must be a multiple of 0x200. */
111+
#endif
112+
113+
#ifndef VECT_TAB_BASE_ADDRESS
114114
#if defined(VECT_TAB_SRAM)
115115
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
116116
This value must be a multiple of 0x200. */
117117
#else
118118
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
119119
This value must be a multiple of 0x200. */
120120
#endif /* VECT_TAB_SRAM */
121-
#endif /* USER_VECT_TAB_ADDRESS */
121+
#endif /* VECT_TAB_BASE_ADDRESS */
122+
122123
/******************************************************************************/
123124
/**
124125
* @}
@@ -195,9 +196,7 @@ void SystemInit(void)
195196
RCC->CICR = 0x0000073BU;
196197

197198
/* Configure the Vector Table location add offset address ------------------*/
198-
#if defined(USER_VECT_TAB_ADDRESS)
199-
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
200-
#endif /* USER_VECT_TAB_ADDRESS */
199+
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
201200
}
202201

203202
/**

0 commit comments

Comments
 (0)