Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b7d2390

Browse files
fprfpistm
fpr
authored andcommittedJul 11, 2017
Allow VECT_TAB_OFFSET to be override
Signed-off-by: fpr <[email protected]>
1 parent b71f887 commit b7d2390

File tree

1 file changed

+77
-75
lines changed

1 file changed

+77
-75
lines changed
 

‎system/STM32F1xx/system_stm32f1xx.c

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
* @version V4.1.0
66
* @date 29-April-2016
77
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
8-
*
9-
* 1. This file provides two functions and one global variable to be called from
8+
*
9+
* 1. This file provides two functions and one global variable to be called from
1010
* user application:
1111
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
12-
* factors, AHB/APBx prescalers and Flash settings).
13-
* This function is called at startup just after reset and
12+
* factors, AHB/APBx prescalers and Flash settings).
13+
* This function is called at startup just after reset and
1414
* before branch to main program. This call is made inside
1515
* the "startup_stm32f1xx_xx.s" file.
1616
*
1717
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
18-
* by the user application to setup the SysTick
18+
* by the user application to setup the SysTick
1919
* timer or configure other parameters.
20-
*
20+
*
2121
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
2222
* be called whenever the core clock is changed
2323
* during program execution.
@@ -27,11 +27,11 @@
2727
* configure the system clock before to branch to main program.
2828
*
2929
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
30-
* the product used), refer to "HSE_VALUE".
30+
* the product used), refer to "HSE_VALUE".
3131
* When HSE is used as system clock source, directly or through PLL, and you
3232
* are using different crystal you have to adapt the HSE value to your own
3333
* configuration.
34-
*
34+
*
3535
******************************************************************************
3636
* @attention
3737
*
@@ -68,8 +68,8 @@
6868

6969
/** @addtogroup stm32f1xx_system
7070
* @{
71-
*/
72-
71+
*/
72+
7373
/** @addtogroup STM32F1xx_System_Private_Includes
7474
* @{
7575
*/
@@ -92,7 +92,7 @@
9292
* @{
9393
*/
9494

95-
#if !defined (HSE_VALUE)
95+
#if !defined (HSE_VALUE)
9696
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz.
9797
This value can be provided and adapted by the user application. */
9898
#endif /* HSE_VALUE */
@@ -102,16 +102,18 @@
102102
This value can be provided and adapted by the user application. */
103103
#endif /* HSI_VALUE */
104104

105-
/*!< Uncomment the following line if you need to use external SRAM */
105+
/*!< Uncomment the following line if you need to use external SRAM */
106106
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
107107
/* #define DATA_IN_ExtSRAM */
108108
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
109109

110110
/*!< Uncomment the following line if you need to relocate your vector Table in
111-
Internal SRAM. */
111+
Internal SRAM. */
112112
/* #define VECT_TAB_SRAM */
113-
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
113+
#ifndef VECT_TAB_OFFSET
114+
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
114115
This value must be a multiple of 0x200. */
116+
#endif
115117

116118

117119
/**
@@ -148,7 +150,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
148150

149151
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
150152
#ifdef DATA_IN_ExtSRAM
151-
static void SystemInit_ExtMemCtl(void);
153+
static void SystemInit_ExtMemCtl(void);
152154
#endif /* DATA_IN_ExtSRAM */
153155
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
154156

@@ -162,7 +164,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
162164

163165
/**
164166
* @brief Setup the microcontroller system
165-
* Initialize the Embedded Flash Interface, the PLL and update the
167+
* Initialize the Embedded Flash Interface, the PLL and update the
166168
* SystemCoreClock variable.
167169
* @note This function should be used only after reset.
168170
* @param None
@@ -179,8 +181,8 @@ void SystemInit (void)
179181
RCC->CFGR &= (uint32_t)0xF8FF0000;
180182
#else
181183
RCC->CFGR &= (uint32_t)0xF0FF0000;
182-
#endif /* STM32F105xC */
183-
184+
#endif /* STM32F105xC */
185+
184186
/* Reset HSEON, CSSON and PLLON bits */
185187
RCC->CR &= (uint32_t)0xFEF6FFFF;
186188

@@ -204,55 +206,55 @@ void SystemInit (void)
204206
RCC->CIR = 0x009F0000;
205207

206208
/* Reset CFGR2 register */
207-
RCC->CFGR2 = 0x00000000;
209+
RCC->CFGR2 = 0x00000000;
208210
#else
209211
/* Disable all interrupts and clear pending bits */
210212
RCC->CIR = 0x009F0000;
211213
#endif /* STM32F105xC */
212-
214+
213215
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
214216
#ifdef DATA_IN_ExtSRAM
215-
SystemInit_ExtMemCtl();
217+
SystemInit_ExtMemCtl();
216218
#endif /* DATA_IN_ExtSRAM */
217-
#endif
219+
#endif
218220

219221
#ifdef VECT_TAB_SRAM
220222
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
221223
#else
222224
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
223-
#endif
225+
#endif
224226
}
225227

226228
/**
227229
* @brief Update SystemCoreClock variable according to Clock Register Values.
228230
* The SystemCoreClock variable contains the core clock (HCLK), it can
229231
* be used by the user application to setup the SysTick timer or configure
230232
* other parameters.
231-
*
233+
*
232234
* @note Each time the core clock (HCLK) changes, this function must be called
233235
* to update SystemCoreClock variable value. Otherwise, any configuration
234-
* based on this variable will be incorrect.
235-
*
236-
* @note - The system frequency computed by this function is not the real
237-
* frequency in the chip. It is calculated based on the predefined
236+
* based on this variable will be incorrect.
237+
*
238+
* @note - The system frequency computed by this function is not the real
239+
* frequency in the chip. It is calculated based on the predefined
238240
* constant and the selected clock source:
239-
*
241+
*
240242
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
241-
*
243+
*
242244
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
243-
*
244-
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
245+
*
246+
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
245247
* or HSI_VALUE(*) multiplied by the PLL factors.
246-
*
248+
*
247249
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
248250
* 8 MHz) but the real value may vary depending on the variations
249-
* in voltage and temperature.
250-
*
251+
* in voltage and temperature.
252+
*
251253
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
252254
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
253255
* that HSE_VALUE is same as the real frequency of the crystal used.
254256
* Otherwise, this function may have wrong result.
255-
*
257+
*
256258
* - The result of this function could be not correct when using fractional
257259
* value for HSE crystal.
258260
* @param None
@@ -269,10 +271,10 @@ void SystemCoreClockUpdate (void)
269271
#if defined(STM32F100xB) || defined(STM32F100xE)
270272
uint32_t prediv1factor = 0;
271273
#endif /* STM32F100xB or STM32F100xE */
272-
274+
273275
/* Get SYSCLK source -------------------------------------------------------*/
274276
tmp = RCC->CFGR & RCC_CFGR_SWS;
275-
277+
276278
switch (tmp)
277279
{
278280
case 0x00: /* HSI used as system clock */
@@ -286,10 +288,10 @@ void SystemCoreClockUpdate (void)
286288
/* Get PLL clock source and multiplication factor ----------------------*/
287289
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
288290
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
289-
290-
#if !defined(STM32F105xC) && !defined(STM32F107xC)
291+
292+
#if !defined(STM32F105xC) && !defined(STM32F107xC)
291293
pllmull = ( pllmull >> 18) + 2;
292-
294+
293295
if (pllsource == 0x00)
294296
{
295297
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
@@ -300,7 +302,7 @@ void SystemCoreClockUpdate (void)
300302
#if defined(STM32F100xB) || defined(STM32F100xE)
301303
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
302304
/* HSE oscillator clock selected as PREDIV1 clock entry */
303-
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
305+
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
304306
#else
305307
/* HSE selected as PLL clock entry */
306308
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
@@ -315,115 +317,115 @@ void SystemCoreClockUpdate (void)
315317
}
316318
#else
317319
pllmull = pllmull >> 18;
318-
320+
319321
if (pllmull != 0x0D)
320322
{
321323
pllmull += 2;
322324
}
323325
else
324326
{ /* PLL multiplication factor = PLL input clock * 6.5 */
325-
pllmull = 13 / 2;
327+
pllmull = 13 / 2;
326328
}
327-
329+
328330
if (pllsource == 0x00)
329331
{
330332
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
331333
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
332334
}
333335
else
334336
{/* PREDIV1 selected as PLL clock entry */
335-
337+
336338
/* Get PREDIV1 clock source and division factor */
337339
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
338340
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
339-
341+
340342
if (prediv1source == 0)
341-
{
343+
{
342344
/* HSE oscillator clock selected as PREDIV1 clock entry */
343-
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
345+
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
344346
}
345347
else
346348
{/* PLL2 clock selected as PREDIV1 clock entry */
347-
349+
348350
/* Get PREDIV2 division factor and PLL2 multiplication factor */
349351
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;
350-
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;
351-
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
352+
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;
353+
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
352354
}
353355
}
354-
#endif /* STM32F105xC */
356+
#endif /* STM32F105xC */
355357
break;
356358

357359
default:
358360
SystemCoreClock = HSI_VALUE;
359361
break;
360362
}
361-
363+
362364
/* Compute HCLK clock frequency ----------------*/
363365
/* Get HCLK prescaler */
364366
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
365367
/* HCLK clock frequency */
366-
SystemCoreClock >>= tmp;
368+
SystemCoreClock >>= tmp;
367369
}
368370

369371
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
370372
/**
371-
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
373+
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
372374
* before jump to __main
373375
* @param None
374376
* @retval None
375-
*/
377+
*/
376378
#ifdef DATA_IN_ExtSRAM
377379
/**
378-
* @brief Setup the external memory controller.
380+
* @brief Setup the external memory controller.
379381
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
380382
* This function configures the external SRAM mounted on STM3210E-EVAL
381383
* board (STM32 High density devices). This SRAM will be used as program
382384
* data memory (including heap and stack).
383385
* @param None
384386
* @retval None
385-
*/
386-
void SystemInit_ExtMemCtl(void)
387+
*/
388+
void SystemInit_ExtMemCtl(void)
387389
{
388390
__IO uint32_t tmpreg;
389-
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
391+
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
390392
required, then adjust the Register Addresses */
391393

392394
/* Enable FSMC clock */
393395
RCC->AHBENR = 0x00000114;
394396

395397
/* Delay after an RCC peripheral clock enabling */
396398
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
397-
399+
398400
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
399401
RCC->APB2ENR = 0x000001E0;
400-
402+
401403
/* Delay after an RCC peripheral clock enabling */
402404
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
403405

404406
(void)(tmpreg);
405-
407+
406408
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
407409
/*---------------- SRAM Address lines configuration -------------------------*/
408-
/*---------------- NOE and NWE configuration --------------------------------*/
410+
/*---------------- NOE and NWE configuration --------------------------------*/
409411
/*---------------- NE3 configuration ----------------------------------------*/
410412
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
411-
412-
GPIOD->CRL = 0x44BB44BB;
413+
414+
GPIOD->CRL = 0x44BB44BB;
413415
GPIOD->CRH = 0xBBBBBBBB;
414416

415-
GPIOE->CRL = 0xB44444BB;
417+
GPIOE->CRL = 0xB44444BB;
416418
GPIOE->CRH = 0xBBBBBBBB;
417419

418-
GPIOF->CRL = 0x44BBBBBB;
420+
GPIOF->CRL = 0x44BBBBBB;
419421
GPIOF->CRH = 0xBBBB4444;
420422

421-
GPIOG->CRL = 0x44BBBBBB;
423+
GPIOG->CRL = 0x44BBBBBB;
422424
GPIOG->CRH = 0x444B4B44;
423-
424-
/*---------------- FSMC Configuration ---------------------------------------*/
425+
426+
/*---------------- FSMC Configuration ---------------------------------------*/
425427
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
426-
428+
427429
FSMC_Bank1->BTCR[4] = 0x00001091;
428430
FSMC_Bank1->BTCR[5] = 0x00110212;
429431
}
@@ -437,8 +439,8 @@ void SystemInit_ExtMemCtl(void)
437439
/**
438440
* @}
439441
*/
440-
442+
441443
/**
442444
* @}
443-
*/
445+
*/
444446
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)
Please sign in to comment.