3
3
* @file system_stm32l1xx.c
4
4
* @author MCD Application Team
5
5
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
6
- *
7
- * This file provides two functions and one global variable to be called from
6
+ *
7
+ * This file provides two functions and one global variable to be called from
8
8
* user application:
9
- * - SystemInit(): This function is called at startup just after reset and
9
+ * - SystemInit(): This function is called at startup just after reset and
10
10
* before branch to main program. This call is made inside
11
11
* the "startup_stm32l1xx.s" file.
12
- *
12
+ *
13
13
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
14
- * by the user application to setup the SysTick
14
+ * by the user application to setup the SysTick
15
15
* timer or configure other parameters.
16
- *
16
+ *
17
17
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
18
18
* be called whenever the core clock is changed
19
- * during program execution.
20
- *
19
+ * during program execution.
20
+ *
21
21
******************************************************************************
22
22
* @attention
23
23
*
38
38
39
39
/** @addtogroup stm32l1xx_system
40
40
* @{
41
- */
42
-
41
+ */
42
+
43
43
/** @addtogroup STM32L1xx_System_Private_Includes
44
44
* @{
45
45
*/
65
65
/*!< Uncomment the following line if you need to use external SRAM mounted
66
66
on STM32L152D_EVAL board as data memory */
67
67
/* #define DATA_IN_ExtSRAM */
68
-
69
- /*!< Uncomment the following line if you need to relocate your vector Table in
70
- Internal SRAM. */
71
- /* #define VECT_TAB_SRAM */
68
+
69
+
72
70
#ifndef VECT_TAB_OFFSET
73
- #define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field.
74
- This value must be a multiple of 0x200. */
71
+ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
72
+ This value must be a multiple of 0x200. */
73
+ #else
74
+ #define USER_VECT_TAB_ADDRESS
75
75
#endif
76
+
77
+ /* Note: Following vector table addresses must be defined in line with linker
78
+ configuration. */
79
+ /*!< Uncomment the following line if you need to relocate the vector table
80
+ anywhere in Flash or Sram, else the vector table is kept at the automatic
81
+ remap of boot address selected */
82
+ /* #define USER_VECT_TAB_ADDRESS */
83
+
84
+ #if defined(USER_VECT_TAB_ADDRESS )
85
+ /*!< Uncomment the following line if you need to relocate your vector Table
86
+ in Sram else user remap will be done in Flash. */
87
+ /* #define VECT_TAB_SRAM */
88
+ #if defined(VECT_TAB_SRAM )
89
+ #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
90
+ This value must be a multiple of 0x200. */
91
+ #else
92
+ #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
93
+ This value must be a multiple of 0x200. */
94
+ #endif /* VECT_TAB_SRAM */
95
+ #endif /* USER_VECT_TAB_ADDRESS */
96
+
97
+ /******************************************************************************/
76
98
/**
77
99
* @}
78
100
*/
@@ -111,7 +133,7 @@ const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
111
133
112
134
#if defined (STM32L151xD ) || defined (STM32L152xD ) || defined (STM32L162xD )
113
135
#ifdef DATA_IN_ExtSRAM
114
- static void SystemInit_ExtMemCtl (void );
136
+ static void SystemInit_ExtMemCtl (void );
115
137
#endif /* DATA_IN_ExtSRAM */
116
138
#endif /* STM32L151xD || STM32L152xD || STM32L162xD */
117
139
@@ -125,7 +147,7 @@ const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
125
147
126
148
/**
127
149
* @brief Setup the microcontroller system.
128
- * Initialize the Embedded Flash Interface, the PLL and update the
150
+ * Initialize the Embedded Flash Interface, the PLL and update the
129
151
* SystemCoreClock variable.
130
152
* @param None
131
153
* @retval None
@@ -151,49 +173,48 @@ void SystemInit (void)
151
173
RCC -> CIR = 0x00000000 ;
152
174
153
175
#ifdef DATA_IN_ExtSRAM
154
- SystemInit_ExtMemCtl ();
176
+ SystemInit_ExtMemCtl ();
155
177
#endif /* DATA_IN_ExtSRAM */
156
-
157
- #ifdef VECT_TAB_SRAM
158
- SCB -> VTOR = SRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM. */
159
- #else
160
- SCB -> VTOR = FLASH_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH. */
161
- #endif
178
+
179
+ /* Configure the Vector Table location -------------------------------------*/
180
+ #if defined(USER_VECT_TAB_ADDRESS )
181
+ SCB -> VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH or SRAM. */
182
+ #endif /* USER_VECT_TAB_ADDRESS */
162
183
}
163
184
164
185
/**
165
186
* @brief Update SystemCoreClock according to Clock Register Values
166
187
* The SystemCoreClock variable contains the core clock (HCLK), it can
167
188
* be used by the user application to setup the SysTick timer or configure
168
189
* other parameters.
169
- *
190
+ *
170
191
* @note Each time the core clock (HCLK) changes, this function must be called
171
192
* to update SystemCoreClock variable value. Otherwise, any configuration
172
- * based on this variable will be incorrect.
173
- *
174
- * @note - The system frequency computed by this function is not the real
175
- * frequency in the chip. It is calculated based on the predefined
193
+ * based on this variable will be incorrect.
194
+ *
195
+ * @note - The system frequency computed by this function is not the real
196
+ * frequency in the chip. It is calculated based on the predefined
176
197
* constant and the selected clock source:
177
- *
178
- * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI
198
+ *
199
+ * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI
179
200
* value as defined by the MSI range.
180
- *
201
+ *
181
202
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
182
- *
203
+ *
183
204
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
184
- *
205
+ *
185
206
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
186
207
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
187
- *
208
+ *
188
209
* (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value
189
210
* 16 MHz) but the real value may vary depending on the variations
190
- * in voltage and temperature.
191
- *
211
+ * in voltage and temperature.
212
+ *
192
213
* (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value
193
214
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
194
215
* frequency of the crystal used. Otherwise, this function may
195
216
* have wrong result.
196
- *
217
+ *
197
218
* - The result of this function could be not correct when using fractional
198
219
* value for HSE crystal.
199
220
* @param None
@@ -205,7 +226,7 @@ void SystemCoreClockUpdate (void)
205
226
206
227
/* Get SYSCLK source -------------------------------------------------------*/
207
228
tmp = RCC -> CFGR & RCC_CFGR_SWS ;
208
-
229
+
209
230
switch (tmp )
210
231
{
211
232
case 0x00 : /* MSI used as system clock */
@@ -224,7 +245,7 @@ void SystemCoreClockUpdate (void)
224
245
plldiv = RCC -> CFGR & RCC_CFGR_PLLDIV ;
225
246
pllmul = PLLMulTable [(pllmul >> 18 )];
226
247
plldiv = (plldiv >> 22 ) + 1 ;
227
-
248
+
228
249
pllsource = RCC -> CFGR & RCC_CFGR_PLLSRC ;
229
250
230
251
if (pllsource == 0x00 )
@@ -266,21 +287,21 @@ void SystemInit_ExtMemCtl(void)
266
287
267
288
/* Flash 1 wait state */
268
289
FLASH -> ACR |= FLASH_ACR_LATENCY ;
269
-
290
+
270
291
/* Power enable */
271
292
RCC -> APB1ENR |= RCC_APB1ENR_PWREN ;
272
-
293
+
273
294
/* Delay after an RCC peripheral clock enabling */
274
295
tmpreg = READ_BIT (RCC -> APB1ENR , RCC_APB1ENR_PWREN );
275
296
276
297
/* Select the Voltage Range 1 (1.8 V) */
277
298
PWR -> CR = PWR_CR_VOS_0 ;
278
-
299
+
279
300
/* Wait Until the Voltage Regulator is ready */
280
301
while ((PWR -> CSR & PWR_CSR_VOSF ) != RESET )
281
302
{
282
303
}
283
-
304
+
284
305
/*-- GPIOs Configuration -----------------------------------------------------*/
285
306
/*
286
307
+-------------------+--------------------+------------------+------------------+
@@ -294,76 +315,76 @@ void SystemInit_ExtMemCtl(void)
294
315
| PD9 <-> FSMC_D14 | PE10 <-> FSMC_D7 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 |
295
316
| PD10 <-> FSMC_D15 | PE11 <-> FSMC_D8 | PF12 <-> FSMC_A6 | PG10<-> FSMC_NE2 |
296
317
| PD11 <-> FSMC_A16 | PE12 <-> FSMC_D9 | PF13 <-> FSMC_A7 |------------------+
297
- | PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 |
298
- | PD13 <-> FSMC_A18 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 |
318
+ | PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 |
319
+ | PD13 <-> FSMC_A18 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 |
299
320
| PD14 <-> FSMC_D0 | PE15 <-> FSMC_D12 |------------------+
300
- | PD15 <-> FSMC_D1 |--------------------+
321
+ | PD15 <-> FSMC_D1 |--------------------+
301
322
+-------------------+
302
323
*/
303
324
304
325
/* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
305
326
RCC -> AHBENR = 0x000080D8 ;
306
-
327
+
307
328
/* Delay after an RCC peripheral clock enabling */
308
329
tmpreg = READ_BIT (RCC -> AHBENR , RCC_AHBENR_GPIODEN );
309
-
330
+
310
331
/* Connect PDx pins to FSMC Alternate function */
311
332
GPIOD -> AFR [0 ] = 0x00CC00CC ;
312
333
GPIOD -> AFR [1 ] = 0xCCCCCCCC ;
313
- /* Configure PDx pins in Alternate function mode */
334
+ /* Configure PDx pins in Alternate function mode */
314
335
GPIOD -> MODER = 0xAAAA0A0A ;
315
- /* Configure PDx pins speed to 40 MHz */
336
+ /* Configure PDx pins speed to 40 MHz */
316
337
GPIOD -> OSPEEDR = 0xFFFF0F0F ;
317
- /* Configure PDx pins Output type to push-pull */
338
+ /* Configure PDx pins Output type to push-pull */
318
339
GPIOD -> OTYPER = 0x00000000 ;
319
- /* No pull-up, pull-down for PDx pins */
340
+ /* No pull-up, pull-down for PDx pins */
320
341
GPIOD -> PUPDR = 0x00000000 ;
321
342
322
343
/* Connect PEx pins to FSMC Alternate function */
323
344
GPIOE -> AFR [0 ] = 0xC00000CC ;
324
345
GPIOE -> AFR [1 ] = 0xCCCCCCCC ;
325
- /* Configure PEx pins in Alternate function mode */
346
+ /* Configure PEx pins in Alternate function mode */
326
347
GPIOE -> MODER = 0xAAAA800A ;
327
- /* Configure PEx pins speed to 40 MHz */
348
+ /* Configure PEx pins speed to 40 MHz */
328
349
GPIOE -> OSPEEDR = 0xFFFFC00F ;
329
- /* Configure PEx pins Output type to push-pull */
350
+ /* Configure PEx pins Output type to push-pull */
330
351
GPIOE -> OTYPER = 0x00000000 ;
331
- /* No pull-up, pull-down for PEx pins */
352
+ /* No pull-up, pull-down for PEx pins */
332
353
GPIOE -> PUPDR = 0x00000000 ;
333
354
334
355
/* Connect PFx pins to FSMC Alternate function */
335
356
GPIOF -> AFR [0 ] = 0x00CCCCCC ;
336
357
GPIOF -> AFR [1 ] = 0xCCCC0000 ;
337
- /* Configure PFx pins in Alternate function mode */
358
+ /* Configure PFx pins in Alternate function mode */
338
359
GPIOF -> MODER = 0xAA000AAA ;
339
- /* Configure PFx pins speed to 40 MHz */
360
+ /* Configure PFx pins speed to 40 MHz */
340
361
GPIOF -> OSPEEDR = 0xFF000FFF ;
341
- /* Configure PFx pins Output type to push-pull */
362
+ /* Configure PFx pins Output type to push-pull */
342
363
GPIOF -> OTYPER = 0x00000000 ;
343
- /* No pull-up, pull-down for PFx pins */
364
+ /* No pull-up, pull-down for PFx pins */
344
365
GPIOF -> PUPDR = 0x00000000 ;
345
366
346
367
/* Connect PGx pins to FSMC Alternate function */
347
368
GPIOG -> AFR [0 ] = 0x00CCCCCC ;
348
369
GPIOG -> AFR [1 ] = 0x00000C00 ;
349
- /* Configure PGx pins in Alternate function mode */
370
+ /* Configure PGx pins in Alternate function mode */
350
371
GPIOG -> MODER = 0x00200AAA ;
351
- /* Configure PGx pins speed to 40 MHz */
372
+ /* Configure PGx pins speed to 40 MHz */
352
373
GPIOG -> OSPEEDR = 0x00300FFF ;
353
- /* Configure PGx pins Output type to push-pull */
374
+ /* Configure PGx pins Output type to push-pull */
354
375
GPIOG -> OTYPER = 0x00000000 ;
355
- /* No pull-up, pull-down for PGx pins */
376
+ /* No pull-up, pull-down for PGx pins */
356
377
GPIOG -> PUPDR = 0x00000000 ;
357
-
378
+
358
379
/*-- FSMC Configuration ------------------------------------------------------*/
359
380
/* Enable the FSMC interface clock */
360
381
RCC -> AHBENR = 0x400080D8 ;
361
382
362
383
/* Delay after an RCC peripheral clock enabling */
363
384
tmpreg = READ_BIT (RCC -> AHBENR , RCC_AHBENR_FSMCEN );
364
-
385
+
365
386
(void )(tmpreg );
366
-
387
+
367
388
/* Configure and enable Bank1_SRAM3 */
368
389
FSMC_Bank1 -> BTCR [4 ] = 0x00001011 ;
369
390
FSMC_Bank1 -> BTCR [5 ] = 0x00000300 ;
@@ -395,11 +416,11 @@ void SystemInit_ExtMemCtl(void)
395
416
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
396
417
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
397
418
398
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
419
+ FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
399
420
400
421
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
401
422
*/
402
-
423
+
403
424
}
404
425
#endif /* DATA_IN_ExtSRAM */
405
426
#endif /* STM32L151xD || STM32L152xD || STM32L162xD */
0 commit comments