6
6
* @date 8-January-2016
7
7
* @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File.
8
8
*
9
- * This file provides two functions and one global variable to be called from
9
+ * This file provides two functions and one global variable to be called from
10
10
* user application:
11
- * - SystemInit(): This function is called at startup just after reset and
11
+ * - SystemInit(): This function is called at startup just after reset and
12
12
* before branch to main program. This call is made inside
13
13
* the "startup_stm32l0xx.s" file.
14
14
*
15
15
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
16
- * by the user application to setup the SysTick
16
+ * by the user application to setup the SysTick
17
17
* timer or configure other parameters.
18
- *
18
+ *
19
19
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
20
20
* be called whenever the core clock is changed
21
21
* during program execution.
36
36
* APB2CLK (MHz) | 32 | 32
37
37
*-----------------------------------------------------------------------------
38
38
* USB capable (48 MHz precise clock) | YES | YES
39
- *-----------------------------------------------------------------------------
39
+ *-----------------------------------------------------------------------------
40
40
******************************************************************************
41
41
* @attention
42
42
*
73
73
74
74
/** @addtogroup stm32l0xx_system
75
75
* @{
76
- */
77
-
76
+ */
77
+
78
78
/** @addtogroup STM32L0xx_System_Private_Includes
79
79
* @{
80
80
*/
81
81
82
82
#include "stm32l0xx.h"
83
83
#include "hal_tick.h"
84
84
85
- #if !defined (HSE_VALUE )
85
+ #if !defined (HSE_VALUE )
86
86
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
87
87
#endif /* HSE_VALUE */
88
88
89
89
#if !defined (MSI_VALUE )
90
90
#define MSI_VALUE ((uint32_t)2000000) /*!< Value of the Internal oscillator in Hz*/
91
91
#endif /* MSI_VALUE */
92
-
92
+
93
93
#if !defined (HSI_VALUE )
94
94
#define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
95
95
#endif /* HSI_VALUE */
115
115
/*!< Uncomment the following line if you need to relocate your vector Table in
116
116
Internal SRAM. */
117
117
/* #define VECT_TAB_SRAM */
118
- #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
118
+ #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
119
119
This value must be a multiple of 0x200. */
120
120
/******************************************************************************/
121
121
/**
140
140
/* This variable is updated in three ways:
141
141
1) by calling CMSIS function SystemCoreClockUpdate()
142
142
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
143
- 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
143
+ 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
144
144
Note: If you use this function to configure the system clock; then there
145
145
is no need to call the 2 first functions listed above, since SystemCoreClock
146
146
variable is updated automatically.
147
147
*/
148
148
uint32_t SystemCoreClock = 32000000 ;
149
- const uint8_t AHBPrescTable [16 ] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 };
150
- const uint8_t PLLMulTable [9 ] = {3 , 4 , 6 , 8 , 12 , 16 , 24 , 32 , 48 };
149
+ const uint8_t AHBPrescTable [16 ] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 };
150
+ const uint8_t PLLMulTable [9 ] = {3 , 4 , 6 , 8 , 12 , 16 , 24 , 32 , 48 };
151
151
152
152
/**
153
153
* @}
@@ -177,19 +177,19 @@ uint8_t SetSysClock_PLL_HSI(void);
177
177
* @retval None
178
178
*/
179
179
void SystemInit (void )
180
- {
180
+ {
181
181
/*!< Set MSION bit */
182
182
RCC -> CR |= (uint32_t )0x00000100 ;
183
183
184
184
/*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */
185
185
RCC -> CFGR &= (uint32_t ) 0x88FF400C ;
186
-
186
+
187
187
/*!< Reset HSION, HSIDIVEN, HSEON, CSSON and PLLON bits */
188
188
RCC -> CR &= (uint32_t )0xFEF6FFF6 ;
189
-
189
+
190
190
/*!< Reset HSI48ON bit */
191
191
RCC -> CRRCR &= (uint32_t )0xFFFFFFFE ;
192
-
192
+
193
193
/*!< Reset HSEBYP bit */
194
194
RCC -> CR &= (uint32_t )0xFFFBFFFF ;
195
195
@@ -198,7 +198,7 @@ void SystemInit (void)
198
198
199
199
/*!< Disable all interrupts */
200
200
RCC -> CIER = 0x00000000 ;
201
-
201
+
202
202
/* Configure the Vector Table location add offset address ------------------*/
203
203
#ifdef VECT_TAB_SRAM
204
204
SCB -> VTOR = SRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM */
@@ -224,34 +224,34 @@ void SystemInit (void)
224
224
* The SystemCoreClock variable contains the core clock (HCLK), it can
225
225
* be used by the user application to setup the SysTick timer or configure
226
226
* other parameters.
227
- *
227
+ *
228
228
* @note Each time the core clock (HCLK) changes, this function must be called
229
229
* to update SystemCoreClock variable value. Otherwise, any configuration
230
- * based on this variable will be incorrect.
231
- *
232
- * @note - The system frequency computed by this function is not the real
233
- * frequency in the chip. It is calculated based on the predefined
230
+ * based on this variable will be incorrect.
231
+ *
232
+ * @note - The system frequency computed by this function is not the real
233
+ * frequency in the chip. It is calculated based on the predefined
234
234
* constant and the selected clock source:
235
- *
236
- * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI
235
+ *
236
+ * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI
237
237
* value as defined by the MSI range.
238
- *
238
+ *
239
239
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
240
- *
240
+ *
241
241
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
242
- *
242
+ *
243
243
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
244
244
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
245
- *
245
+ *
246
246
* (*) HSI_VALUE is a constant defined in stm32l0xx_hal.h file (default value
247
247
* 16 MHz) but the real value may vary depending on the variations
248
- * in voltage and temperature.
249
- *
248
+ * in voltage and temperature.
249
+ *
250
250
* (**) HSE_VALUE is a constant defined in stm32l0xx_hal.h file (default value
251
251
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
252
252
* frequency of the crystal used. Otherwise, this function may
253
253
* have wrong result.
254
- *
254
+ *
255
255
* - The result of this function could be not correct when using fractional
256
256
* value for HSE crystal.
257
257
* @param None
@@ -263,7 +263,7 @@ void SystemCoreClockUpdate (void)
263
263
264
264
/* Get SYSCLK source -------------------------------------------------------*/
265
265
tmp = RCC -> CFGR & RCC_CFGR_SWS ;
266
-
266
+
267
267
switch (tmp )
268
268
{
269
269
case 0x00 : /* MSI used as system clock */
@@ -282,7 +282,7 @@ void SystemCoreClockUpdate (void)
282
282
plldiv = RCC -> CFGR & RCC_CFGR_PLLDIV ;
283
283
pllmul = PLLMulTable [(pllmul >> 18 )];
284
284
plldiv = (plldiv >> 22 ) + 1 ;
285
-
285
+
286
286
pllsource = RCC -> CFGR & RCC_CFGR_PLLSRC ;
287
287
288
288
if (pllsource == 0x00 )
@@ -311,8 +311,8 @@ void SystemCoreClockUpdate (void)
311
311
/**
312
312
* @brief Configures the System clock source, PLL Multiplier and Divider factors,
313
313
* AHB/APBx prescalers and Flash settings
314
- * @note This function should be called only once the RCC clock configuration
315
- * is reset to the default reset state (done in SystemInit() function).
314
+ * @note This function should be called only once the RCC clock configuration
315
+ * is reset to the default reset state (done in SystemInit() function).
316
316
* @param None
317
317
* @retval None
318
318
*/
@@ -338,7 +338,7 @@ void SetSysClock(void)
338
338
}
339
339
}
340
340
}
341
-
341
+
342
342
/* Output clock on MCO1 pin(PA8) for debugging purpose */
343
343
//HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
344
344
//HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI48, RCC_MCODIV_1);
@@ -358,13 +358,13 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
358
358
{
359
359
return 0 ;
360
360
}
361
-
362
- /* The voltage scaling allows optimizing the power consumption when the device is
363
- clocked below the maximum system frequency, to update the voltage scaling value
361
+
362
+ /* The voltage scaling allows optimizing the power consumption when the device is
363
+ clocked below the maximum system frequency, to update the voltage scaling value
364
364
regarding system frequency refer to product datasheet. */
365
365
__PWR_CLK_ENABLE ();
366
366
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
367
-
367
+
368
368
/* Enable HSE and HSI48 oscillators and activate PLL with HSE as source */
369
369
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48 ;
370
370
if (bypass == 0 )
@@ -389,7 +389,7 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
389
389
{
390
390
return 0 ; // FAIL
391
391
}
392
-
392
+
393
393
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
394
394
RCC_ClkInitStruct .ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 );
395
395
RCC_ClkInitStruct .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK ; // 32 MHz
@@ -406,7 +406,7 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
406
406
// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2); // 4 MHz
407
407
//else
408
408
// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); // 8 MHz
409
-
409
+
410
410
return 1 ; // OK
411
411
}
412
412
#endif
@@ -419,12 +419,12 @@ uint8_t SetSysClock_PLL_HSI(void)
419
419
RCC_ClkInitTypeDef RCC_ClkInitStruct ;
420
420
RCC_OscInitTypeDef RCC_OscInitStruct ;
421
421
422
- /* The voltage scaling allows optimizing the power consumption when the device is
423
- clocked below the maximum system frequency, to update the voltage scaling value
422
+ /* The voltage scaling allows optimizing the power consumption when the device is
423
+ clocked below the maximum system frequency, to update the voltage scaling value
424
424
regarding system frequency refer to product datasheet. */
425
425
__PWR_CLK_ENABLE ();
426
426
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
427
-
427
+
428
428
/* Enable HSI and HSI48 oscillators and activate PLL with HSI as source */
429
429
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI48 ;
430
430
RCC_OscInitStruct .HSEState = RCC_HSE_OFF ;
@@ -442,7 +442,7 @@ uint8_t SetSysClock_PLL_HSI(void)
442
442
{
443
443
return 0 ; // FAIL
444
444
}
445
-
445
+
446
446
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
447
447
RCC_ClkInitStruct .ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 );
448
448
RCC_ClkInitStruct .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK ; // 32 MHz
@@ -456,7 +456,7 @@ uint8_t SetSysClock_PLL_HSI(void)
456
456
457
457
/* Output clock on MCO1 pin(PA8) for debugging purpose */
458
458
//HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 16 MHz
459
-
459
+
460
460
return 1 ; // OK
461
461
}
462
462
0 commit comments