3
3
* @file system_stm32l1xx.c
4
4
* @author MCD Application Team
5
5
* @version V1.2.0
6
- * @date 11-January -2014
6
+ * @date 14-March -2014
7
7
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
8
8
* This file contains the system clock configuration for STM32L1xx Ultra
9
9
* Low power devices, and is generated by the clock configuration
43
43
*=============================================================================
44
44
* System Clock Configuration
45
45
*=============================================================================
46
- * System clock source | HSI
46
+ * System Clock source | PLL( HSI)
47
47
*-----------------------------------------------------------------------------
48
- * SYSCLK | 16000000 Hz
48
+ * SYSCLK | 32000000 Hz
49
49
*-----------------------------------------------------------------------------
50
- * HCLK | 16000000 Hz
50
+ * HCLK | 32000000 Hz
51
51
*-----------------------------------------------------------------------------
52
52
* AHB Prescaler | 1
53
53
*-----------------------------------------------------------------------------
54
54
* APB1 Prescaler | 1
55
55
*-----------------------------------------------------------------------------
56
56
* APB2 Prescaler | 1
57
57
*-----------------------------------------------------------------------------
58
- * HSE Frequency | 8000000 Hz
58
+ * HSE Frequency | Not used
59
59
*-----------------------------------------------------------------------------
60
- * PLL DIV | Not Used
60
+ * PLL DIV | 2
61
61
*-----------------------------------------------------------------------------
62
- * PLL MUL | Not Used
62
+ * PLL MUL | 4
63
63
*-----------------------------------------------------------------------------
64
64
* VDD | 3.3 V
65
65
*-----------------------------------------------------------------------------
66
66
* Vcore | 1.8 V (Range 1)
67
67
*-----------------------------------------------------------------------------
68
- * Flash Latency | 0 WS
68
+ * Flash Latency | 1 WS
69
69
*-----------------------------------------------------------------------------
70
70
* Require 48MHz for USB clock | Disabled
71
71
*-----------------------------------------------------------------------------
149
149
/** @addtogroup STM32L1xx_System_Private_Variables
150
150
* @{
151
151
*/
152
- uint32_t SystemCoreClock = 16000000 ;
152
+ uint32_t SystemCoreClock = 32000000 ;
153
153
__I uint8_t PLLMulTable [9 ] = {3 , 4 , 6 , 8 , 12 , 16 , 24 , 32 , 48 };
154
154
__I uint8_t AHBPrescTable [16 ] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 };
155
155
@@ -161,7 +161,7 @@ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}
161
161
* @{
162
162
*/
163
163
164
- static void SetSysClock (void );
164
+ void SetSysClock (void );
165
165
166
166
/**
167
167
* @}
@@ -206,6 +206,23 @@ void SystemInit (void)
206
206
#else
207
207
SCB -> VTOR = FLASH_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH. */
208
208
#endif
209
+
210
+ /* ADDED FOR MBED DEBUG PURPOSE */
211
+ /*
212
+ // Enable the GPIOA peripheral
213
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
214
+ // Output the system clock on MCO pin (PA.08)
215
+ GPIO_InitTypeDef GPIO_InitStructure;
216
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
217
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
218
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
219
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
220
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
221
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
222
+ // Select the clock to output on MCO pin (PA.08)
223
+ RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1);
224
+ //RCC_MCOConfig(RCC_MCOSource_HSI, RCC_MCODiv_1);
225
+ */
209
226
}
210
227
211
228
/**
@@ -305,7 +322,7 @@ void SystemCoreClockUpdate (void)
305
322
* @param None
306
323
* @retval None
307
324
*/
308
- static void SetSysClock (void )
325
+ void SetSysClock (void )
309
326
{
310
327
__IO uint32_t StartUpCounter = 0 , HSIStatus = 0 ;
311
328
@@ -330,42 +347,54 @@ static void SetSysClock(void)
330
347
331
348
if (HSIStatus == (uint32_t )0x01 )
332
349
{
333
- /* Flash 0 wait state */
334
- FLASH -> ACR &= ~ FLASH_ACR_LATENCY ;
350
+ /* Enable 64-bit access */
351
+ FLASH -> ACR |= FLASH_ACR_ACC64 ;
335
352
336
- /* Disable Prefetch Buffer */
337
- FLASH -> ACR &= ~ FLASH_ACR_PRFTEN ;
353
+ /* Enable Prefetch Buffer */
354
+ FLASH -> ACR |= FLASH_ACR_PRFTEN ;
338
355
339
- /* Disable 64-bit access */
340
- FLASH -> ACR &= ~ FLASH_ACR_ACC64 ;
356
+ /* Flash 1 wait state (latency) */
357
+ FLASH -> ACR |= FLASH_ACR_LATENCY ;
341
358
342
-
343
359
/* Power enable */
344
360
RCC -> APB1ENR |= RCC_APB1ENR_PWREN ;
345
361
346
362
/* Select the Voltage Range 1 (1.8 V) */
347
363
PWR -> CR = PWR_CR_VOS_0 ;
348
-
349
-
364
+
350
365
/* Wait Until the Voltage Regulator is ready */
351
366
while ((PWR -> CSR & PWR_CSR_VOSF ) != RESET )
352
367
{
353
368
}
354
-
355
- /* HCLK = SYSCLK /1*/
369
+
370
+ /* PLL configuration */
371
+ /* SYSCLK = (HSI 16 MHz * 4) / 2 = 32 MHz */
372
+ RCC -> CFGR &= (uint32_t )((uint32_t )~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL | RCC_CFGR_PLLDIV ));
373
+ RCC -> CFGR |= (uint32_t )(RCC_CFGR_PLLSRC_HSI | RCC_CFGR_PLLMUL4 | RCC_CFGR_PLLDIV2 );
374
+
375
+ /* HCLK = 32 MHz */
356
376
RCC -> CFGR |= (uint32_t )RCC_CFGR_HPRE_DIV1 ;
357
- /* PCLK2 = HCLK /1*/
377
+
378
+ /* PCLK2 = 32 MHz */
358
379
RCC -> CFGR |= (uint32_t )RCC_CFGR_PPRE2_DIV1 ;
359
380
360
- /* PCLK1 = HCLK /1 */
381
+ /* PCLK1 = 32 MHz */
361
382
RCC -> CFGR |= (uint32_t )RCC_CFGR_PPRE1_DIV1 ;
362
-
363
- /* Select HSI as system clock source */
383
+
384
+ /* Enable PLL */
385
+ RCC -> CR |= RCC_CR_PLLON ;
386
+
387
+ /* Wait till PLL is ready */
388
+ while ((RCC -> CR & RCC_CR_PLLRDY ) == 0 )
389
+ {
390
+ }
391
+
392
+ /* Select PLL as system clock source */
364
393
RCC -> CFGR &= (uint32_t )((uint32_t )~(RCC_CFGR_SW ));
365
- RCC -> CFGR |= (uint32_t )RCC_CFGR_SW_HSI ;
394
+ RCC -> CFGR |= (uint32_t )RCC_CFGR_SW_PLL ;
366
395
367
- /* Wait till HSI is used as system clock source */
368
- while ((RCC -> CFGR & (uint32_t )RCC_CFGR_SWS ) != (uint32_t )RCC_CFGR_SWS_HSI )
396
+ /* Wait till PLL is used as system clock source */
397
+ while ((RCC -> CFGR & (uint32_t )RCC_CFGR_SWS ) != (uint32_t )RCC_CFGR_SWS_PLL )
369
398
{
370
399
}
371
400
}
0 commit comments