5
5
* @version V4.1.0
6
6
* @date 29-April-2016
7
7
* @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
10
10
* user application:
11
11
* - 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
14
14
* before branch to main program. This call is made inside
15
15
* the "startup_stm32f1xx_xx.s" file.
16
16
*
17
17
* - 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
19
19
* timer or configure other parameters.
20
- *
20
+ *
21
21
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
22
22
* be called whenever the core clock is changed
23
23
* during program execution.
27
27
* configure the system clock before to branch to main program.
28
28
*
29
29
* 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".
31
31
* When HSE is used as system clock source, directly or through PLL, and you
32
32
* are using different crystal you have to adapt the HSE value to your own
33
33
* configuration.
34
- *
34
+ *
35
35
******************************************************************************
36
36
* @attention
37
37
*
68
68
69
69
/** @addtogroup stm32f1xx_system
70
70
* @{
71
- */
72
-
71
+ */
72
+
73
73
/** @addtogroup STM32F1xx_System_Private_Includes
74
74
* @{
75
75
*/
92
92
* @{
93
93
*/
94
94
95
- #if !defined (HSE_VALUE )
95
+ #if !defined (HSE_VALUE )
96
96
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz.
97
97
This value can be provided and adapted by the user application. */
98
98
#endif /* HSE_VALUE */
102
102
This value can be provided and adapted by the user application. */
103
103
#endif /* HSI_VALUE */
104
104
105
- /*!< Uncomment the following line if you need to use external SRAM */
105
+ /*!< Uncomment the following line if you need to use external SRAM */
106
106
#if defined(STM32F100xE ) || defined(STM32F101xE ) || defined(STM32F101xG ) || defined(STM32F103xE ) || defined(STM32F103xG )
107
107
/* #define DATA_IN_ExtSRAM */
108
108
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
109
109
110
110
/*!< Uncomment the following line if you need to relocate your vector Table in
111
- Internal SRAM. */
111
+ Internal SRAM. */
112
112
/* #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.
114
115
This value must be a multiple of 0x200. */
116
+ #endif
115
117
116
118
117
119
/**
@@ -148,7 +150,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
148
150
149
151
#if defined(STM32F100xE ) || defined(STM32F101xE ) || defined(STM32F101xG ) || defined(STM32F103xE ) || defined(STM32F103xG )
150
152
#ifdef DATA_IN_ExtSRAM
151
- static void SystemInit_ExtMemCtl (void );
153
+ static void SystemInit_ExtMemCtl (void );
152
154
#endif /* DATA_IN_ExtSRAM */
153
155
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
154
156
@@ -162,7 +164,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
162
164
163
165
/**
164
166
* @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
166
168
* SystemCoreClock variable.
167
169
* @note This function should be used only after reset.
168
170
* @param None
@@ -179,8 +181,8 @@ void SystemInit (void)
179
181
RCC -> CFGR &= (uint32_t )0xF8FF0000 ;
180
182
#else
181
183
RCC -> CFGR &= (uint32_t )0xF0FF0000 ;
182
- #endif /* STM32F105xC */
183
-
184
+ #endif /* STM32F105xC */
185
+
184
186
/* Reset HSEON, CSSON and PLLON bits */
185
187
RCC -> CR &= (uint32_t )0xFEF6FFFF ;
186
188
@@ -204,55 +206,55 @@ void SystemInit (void)
204
206
RCC -> CIR = 0x009F0000 ;
205
207
206
208
/* Reset CFGR2 register */
207
- RCC -> CFGR2 = 0x00000000 ;
209
+ RCC -> CFGR2 = 0x00000000 ;
208
210
#else
209
211
/* Disable all interrupts and clear pending bits */
210
212
RCC -> CIR = 0x009F0000 ;
211
213
#endif /* STM32F105xC */
212
-
214
+
213
215
#if defined(STM32F100xE ) || defined(STM32F101xE ) || defined(STM32F101xG ) || defined(STM32F103xE ) || defined(STM32F103xG )
214
216
#ifdef DATA_IN_ExtSRAM
215
- SystemInit_ExtMemCtl ();
217
+ SystemInit_ExtMemCtl ();
216
218
#endif /* DATA_IN_ExtSRAM */
217
- #endif
219
+ #endif
218
220
219
221
#ifdef VECT_TAB_SRAM
220
222
SCB -> VTOR = SRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM. */
221
223
#else
222
224
SCB -> VTOR = FLASH_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH. */
223
- #endif
225
+ #endif
224
226
}
225
227
226
228
/**
227
229
* @brief Update SystemCoreClock variable according to Clock Register Values.
228
230
* The SystemCoreClock variable contains the core clock (HCLK), it can
229
231
* be used by the user application to setup the SysTick timer or configure
230
232
* other parameters.
231
- *
233
+ *
232
234
* @note Each time the core clock (HCLK) changes, this function must be called
233
235
* 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
238
240
* constant and the selected clock source:
239
- *
241
+ *
240
242
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
241
- *
243
+ *
242
244
* - 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(**)
245
247
* or HSI_VALUE(*) multiplied by the PLL factors.
246
- *
248
+ *
247
249
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
248
250
* 8 MHz) but the real value may vary depending on the variations
249
- * in voltage and temperature.
250
- *
251
+ * in voltage and temperature.
252
+ *
251
253
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
252
254
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
253
255
* that HSE_VALUE is same as the real frequency of the crystal used.
254
256
* Otherwise, this function may have wrong result.
255
- *
257
+ *
256
258
* - The result of this function could be not correct when using fractional
257
259
* value for HSE crystal.
258
260
* @param None
@@ -269,10 +271,10 @@ void SystemCoreClockUpdate (void)
269
271
#if defined(STM32F100xB ) || defined(STM32F100xE )
270
272
uint32_t prediv1factor = 0 ;
271
273
#endif /* STM32F100xB or STM32F100xE */
272
-
274
+
273
275
/* Get SYSCLK source -------------------------------------------------------*/
274
276
tmp = RCC -> CFGR & RCC_CFGR_SWS ;
275
-
277
+
276
278
switch (tmp )
277
279
{
278
280
case 0x00 : /* HSI used as system clock */
@@ -286,10 +288,10 @@ void SystemCoreClockUpdate (void)
286
288
/* Get PLL clock source and multiplication factor ----------------------*/
287
289
pllmull = RCC -> CFGR & RCC_CFGR_PLLMULL ;
288
290
pllsource = RCC -> CFGR & RCC_CFGR_PLLSRC ;
289
-
290
- #if !defined(STM32F105xC ) && !defined(STM32F107xC )
291
+
292
+ #if !defined(STM32F105xC ) && !defined(STM32F107xC )
291
293
pllmull = ( pllmull >> 18 ) + 2 ;
292
-
294
+
293
295
if (pllsource == 0x00 )
294
296
{
295
297
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
@@ -300,7 +302,7 @@ void SystemCoreClockUpdate (void)
300
302
#if defined(STM32F100xB ) || defined(STM32F100xE )
301
303
prediv1factor = (RCC -> CFGR2 & RCC_CFGR2_PREDIV1 ) + 1 ;
302
304
/* HSE oscillator clock selected as PREDIV1 clock entry */
303
- SystemCoreClock = (HSE_VALUE / prediv1factor ) * pllmull ;
305
+ SystemCoreClock = (HSE_VALUE / prediv1factor ) * pllmull ;
304
306
#else
305
307
/* HSE selected as PLL clock entry */
306
308
if ((RCC -> CFGR & RCC_CFGR_PLLXTPRE ) != (uint32_t )RESET )
@@ -315,115 +317,115 @@ void SystemCoreClockUpdate (void)
315
317
}
316
318
#else
317
319
pllmull = pllmull >> 18 ;
318
-
320
+
319
321
if (pllmull != 0x0D )
320
322
{
321
323
pllmull += 2 ;
322
324
}
323
325
else
324
326
{ /* PLL multiplication factor = PLL input clock * 6.5 */
325
- pllmull = 13 / 2 ;
327
+ pllmull = 13 / 2 ;
326
328
}
327
-
329
+
328
330
if (pllsource == 0x00 )
329
331
{
330
332
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
331
333
SystemCoreClock = (HSI_VALUE >> 1 ) * pllmull ;
332
334
}
333
335
else
334
336
{/* PREDIV1 selected as PLL clock entry */
335
-
337
+
336
338
/* Get PREDIV1 clock source and division factor */
337
339
prediv1source = RCC -> CFGR2 & RCC_CFGR2_PREDIV1SRC ;
338
340
prediv1factor = (RCC -> CFGR2 & RCC_CFGR2_PREDIV1 ) + 1 ;
339
-
341
+
340
342
if (prediv1source == 0 )
341
- {
343
+ {
342
344
/* HSE oscillator clock selected as PREDIV1 clock entry */
343
- SystemCoreClock = (HSE_VALUE / prediv1factor ) * pllmull ;
345
+ SystemCoreClock = (HSE_VALUE / prediv1factor ) * pllmull ;
344
346
}
345
347
else
346
348
{/* PLL2 clock selected as PREDIV1 clock entry */
347
-
349
+
348
350
/* Get PREDIV2 division factor and PLL2 multiplication factor */
349
351
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 ;
352
354
}
353
355
}
354
- #endif /* STM32F105xC */
356
+ #endif /* STM32F105xC */
355
357
break ;
356
358
357
359
default :
358
360
SystemCoreClock = HSI_VALUE ;
359
361
break ;
360
362
}
361
-
363
+
362
364
/* Compute HCLK clock frequency ----------------*/
363
365
/* Get HCLK prescaler */
364
366
tmp = AHBPrescTable [((RCC -> CFGR & RCC_CFGR_HPRE ) >> 4 )];
365
367
/* HCLK clock frequency */
366
- SystemCoreClock >>= tmp ;
368
+ SystemCoreClock >>= tmp ;
367
369
}
368
370
369
371
#if defined(STM32F100xE ) || defined(STM32F101xE ) || defined(STM32F101xG ) || defined(STM32F103xE ) || defined(STM32F103xG )
370
372
/**
371
- * @brief Setup the external memory controller. Called in startup_stm32f1xx.s
373
+ * @brief Setup the external memory controller. Called in startup_stm32f1xx.s
372
374
* before jump to __main
373
375
* @param None
374
376
* @retval None
375
- */
377
+ */
376
378
#ifdef DATA_IN_ExtSRAM
377
379
/**
378
- * @brief Setup the external memory controller.
380
+ * @brief Setup the external memory controller.
379
381
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
380
382
* This function configures the external SRAM mounted on STM3210E-EVAL
381
383
* board (STM32 High density devices). This SRAM will be used as program
382
384
* data memory (including heap and stack).
383
385
* @param None
384
386
* @retval None
385
- */
386
- void SystemInit_ExtMemCtl (void )
387
+ */
388
+ void SystemInit_ExtMemCtl (void )
387
389
{
388
390
__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
390
392
required, then adjust the Register Addresses */
391
393
392
394
/* Enable FSMC clock */
393
395
RCC -> AHBENR = 0x00000114 ;
394
396
395
397
/* Delay after an RCC peripheral clock enabling */
396
398
tmpreg = READ_BIT (RCC -> AHBENR , RCC_AHBENR_FSMCEN );
397
-
399
+
398
400
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
399
401
RCC -> APB2ENR = 0x000001E0 ;
400
-
402
+
401
403
/* Delay after an RCC peripheral clock enabling */
402
404
tmpreg = READ_BIT (RCC -> APB2ENR , RCC_APB2ENR_IOPDEN );
403
405
404
406
(void )(tmpreg );
405
-
407
+
406
408
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
407
409
/*---------------- SRAM Address lines configuration -------------------------*/
408
- /*---------------- NOE and NWE configuration --------------------------------*/
410
+ /*---------------- NOE and NWE configuration --------------------------------*/
409
411
/*---------------- NE3 configuration ----------------------------------------*/
410
412
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
411
-
412
- GPIOD -> CRL = 0x44BB44BB ;
413
+
414
+ GPIOD -> CRL = 0x44BB44BB ;
413
415
GPIOD -> CRH = 0xBBBBBBBB ;
414
416
415
- GPIOE -> CRL = 0xB44444BB ;
417
+ GPIOE -> CRL = 0xB44444BB ;
416
418
GPIOE -> CRH = 0xBBBBBBBB ;
417
419
418
- GPIOF -> CRL = 0x44BBBBBB ;
420
+ GPIOF -> CRL = 0x44BBBBBB ;
419
421
GPIOF -> CRH = 0xBBBB4444 ;
420
422
421
- GPIOG -> CRL = 0x44BBBBBB ;
423
+ GPIOG -> CRL = 0x44BBBBBB ;
422
424
GPIOG -> CRH = 0x444B4B44 ;
423
-
424
- /*---------------- FSMC Configuration ---------------------------------------*/
425
+
426
+ /*---------------- FSMC Configuration ---------------------------------------*/
425
427
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
426
-
428
+
427
429
FSMC_Bank1 -> BTCR [4 ] = 0x00001091 ;
428
430
FSMC_Bank1 -> BTCR [5 ] = 0x00110212 ;
429
431
}
@@ -437,8 +439,8 @@ void SystemInit_ExtMemCtl(void)
437
439
/**
438
440
* @}
439
441
*/
440
-
442
+
441
443
/**
442
444
* @}
443
- */
445
+ */
444
446
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
0 commit comments