17
17
/**
18
18
* This file configures the system clock as follows:
19
19
*-----------------------------------------------------------------------------
20
- * System clock source | 1- PLL_HSE_EXTC | 3- PLL_HSI
21
- * | (external 8 MHz clock) | (internal 16 MHz)
22
- * | 2- PLL_HSE_XTAL |
23
- * | (external 8 MHz xtal) |
20
+ * System clock source | 1- USE_PLL_HSE_EXTC (external 8 MHz clock)
21
+ * | 2- USE_PLL_HSE_XTAL (external 8 MHz xtal)
22
+ * | 3- USE_PLL_HSI (internal 16 MHz)
24
23
*-----------------------------------------------------------------------------
25
- * SYSCLK(MHz) | 168 | 168
26
- *-----------------------------------------------------------------------------
27
- * AHBCLK (MHz) | 168 | 168
28
- *-----------------------------------------------------------------------------
29
- * APB1CLK (MHz) | 42 | 42
30
- *-----------------------------------------------------------------------------
31
- * APB2CLK (MHz) | 84 | 84
32
- *-----------------------------------------------------------------------------
33
- * USB capable (48 MHz precise clock) | YES | NO
24
+ * SYSCLK(MHz) | 168
25
+ * AHBCLK (MHz) | 168
26
+ * APB1CLK (MHz) | 42
27
+ * APB2CLK (MHz) | 84
28
+ * USB capable | YES
34
29
*-----------------------------------------------------------------------------
35
30
**/
36
31
37
32
#include "stm32f4xx.h"
38
-
33
+ #include "mbed_assert.h"
39
34
40
35
/*!< Uncomment the following line if you need to relocate your vector Table in
41
36
Internal SRAM. */
44
39
This value must be a multiple of 0x200. */
45
40
46
41
47
- /* Select the clock sources (other than HSI) to start with (0=OFF, 1=ON) */
48
- #define USE_PLL_HSE_EXTC (1) /* Use external clock */
49
- #define USE_PLL_HSE_XTAL (1) /* Use external xtal */
42
+ // clock source is selected with CLOCK_SOURCE in json config
43
+ #define USE_PLL_HSE_EXTC 0x8 // Use external clock (ST Link MCO)
44
+ #define USE_PLL_HSE_XTAL 0x4 // Use external xtal (X3 on board - not provided by default)
45
+ #define USE_PLL_HSI 0x2 // Use HSI internal clock
50
46
51
47
52
- #if (USE_PLL_HSE_XTAL != 0 ) || (USE_PLL_HSE_EXTC != 0 )
48
+ #if ( (( CLOCK_SOURCE ) & USE_PLL_HSE_XTAL ) || (( CLOCK_SOURCE ) & USE_PLL_HSE_EXTC ) )
53
49
uint8_t SetSysClock_PLL_HSE (uint8_t bypass );
54
- #endif
50
+ #endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */
55
51
52
+ #if ((CLOCK_SOURCE ) & USE_PLL_HSI )
56
53
uint8_t SetSysClock_PLL_HSI (void );
54
+ #endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */
55
+
57
56
58
57
/**
59
58
* @brief Setup the microcontroller system
@@ -110,20 +109,23 @@ void SystemInit(void)
110
109
*/
111
110
void SetSysClock (void )
112
111
{
112
+ #if ((CLOCK_SOURCE ) & USE_PLL_HSE_EXTC )
113
113
/* 1- Try to start with HSE and external clock */
114
- #if USE_PLL_HSE_EXTC != 0
115
114
if (SetSysClock_PLL_HSE (1 ) == 0 )
116
115
#endif
117
116
{
117
+ #if ((CLOCK_SOURCE ) & USE_PLL_HSE_XTAL )
118
118
/* 2- If fail try to start with HSE and external xtal */
119
- #if USE_PLL_HSE_XTAL != 0
120
119
if (SetSysClock_PLL_HSE (0 ) == 0 )
121
120
#endif
122
121
{
122
+ #if ((CLOCK_SOURCE ) & USE_PLL_HSI )
123
123
/* 3- If fail start with HSI clock */
124
- if (SetSysClock_PLL_HSI () == 0 ) {
124
+ if (SetSysClock_PLL_HSI () == 0 )
125
+ #endif
126
+ {
125
127
while (1 ) {
126
- // [TODO] Put something here to tell the user that a problem occured...
128
+ MBED_ASSERT ( 1 );
127
129
}
128
130
}
129
131
}
@@ -133,14 +135,14 @@ void SetSysClock(void)
133
135
//HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1); // 84 MHz
134
136
}
135
137
136
- #if (USE_PLL_HSE_XTAL != 0 ) || (USE_PLL_HSE_EXTC != 0 )
138
+ #if ( (( CLOCK_SOURCE ) & USE_PLL_HSE_XTAL ) || (( CLOCK_SOURCE ) & USE_PLL_HSE_EXTC ) )
137
139
/******************************************************************************/
138
140
/* PLL (clocked by HSE) used as System clock source */
139
141
/******************************************************************************/
140
142
uint8_t SetSysClock_PLL_HSE (uint8_t bypass )
141
143
{
142
- RCC_ClkInitTypeDef RCC_ClkInitStruct ;
143
144
RCC_OscInitTypeDef RCC_OscInitStruct ;
145
+ RCC_ClkInitTypeDef RCC_ClkInitStruct ;
144
146
145
147
/* The voltage scaling allows optimizing the power consumption when the device is
146
148
clocked below the maximum system frequency, to update the voltage scaling value
@@ -186,15 +188,16 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
186
188
187
189
return 1 ; // OK
188
190
}
189
- #endif
191
+ #endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */
190
192
193
+ #if ((CLOCK_SOURCE ) & USE_PLL_HSI )
191
194
/******************************************************************************/
192
195
/* PLL (clocked by HSI) used as System clock source */
193
196
/******************************************************************************/
194
197
uint8_t SetSysClock_PLL_HSI (void )
195
198
{
196
- RCC_ClkInitTypeDef RCC_ClkInitStruct ;
197
199
RCC_OscInitTypeDef RCC_OscInitStruct ;
200
+ RCC_ClkInitTypeDef RCC_ClkInitStruct ;
198
201
199
202
/* The voltage scaling allows optimizing the power consumption when the device is
200
203
clocked below the maximum system frequency, to update the voltage scaling value
@@ -232,3 +235,4 @@ uint8_t SetSysClock_PLL_HSI(void)
232
235
233
236
return 1 ; // OK
234
237
}
238
+ #endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */
0 commit comments