Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define TIMEOUT_VALUE
Private function prototypes
main()
StartHSE()
RCC_WaitForHSEReady()
LED_Init()
LED_On()
LED_Blinking(uint32_t)
HSEReady_Callback()
HSEFailureDetection_Callback()
Files
loading...
SourceVuSTM32 Libraries and SamplesRCC_UseHSEasSystemClockSrc/main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSEasSystemClock/Src/main.c * @author MCD Application Team * @brief This example describes how to use the RCC LL API how to start the HSE * and use it as system clock. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F4xx_LL_Examples * @{ *//* ... */ /** @addtogroup RCC_UseHSEasSystemClock * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #if (USE_TIMEOUT == 1) #define TIMEOUT_VALUE 1000 /* Time-out set to 1 sec */ #endif /* USE_TIMEOUT */ Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void StartHSE(void); uint32_t RCC_WaitForHSEReady(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None *//* ... */ int main(void) { register uint32_t frequency = 0; /* Configure Systick to 1 ms with the current frequency which should be HSI */ frequency = HSI_VALUE; LL_Init1msTick(frequency); /* Initialize LED2 */ LED_Init(); /* Start HSE */ StartHSE(); if (RCC_WaitForHSEReady() == RCC_ERROR_NONE) { /* Turn-on LED2 to indicate that HSE is ready */ LED_On(); }if (RCC_WaitForHSEReady() == RCC_ERROR_NONE) { ... } else { /* Problem to switch to HSE, blink LED2 */ LED_Blinking(LED_BLINK_ERROR); }else { ... } /* Infinite loop */ while (1) { }while (1) { ... } }{ ... } /** * Brief This function enables the interruption HSE ready, * and start the HSE as external clock. * @param None * Retval None *//* ... */ void StartHSE(void) { /* Configure NVIC for RCC */ NVIC_EnableIRQ(RCC_IRQn); NVIC_SetPriority(RCC_IRQn,0); /* Enable interrupt on HSE ready */ /* Enable the CSS Enable the HSE and set HSEBYP to use the external clock instead of an oscillator Enable HSE *//* ... */ /* Note : the clock is switched to HSE in the RCC_IRQHandler ISR */ LL_RCC_EnableIT_HSERDY(); LL_RCC_HSE_EnableCSS(); LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); }{ ... } /** * @brief Wait for HSE ready * @param None * @retval RCC_ERROR_NONE if no error *//* ... */ uint32_t RCC_WaitForHSEReady() { #if (USE_TIMEOUT == 1) /* Set timeout to 1 sec */ uint32_t timeout = TIMEOUT_VALUE;/* ... */ #endif /* USE_TIMEOUT */ /* Check that the condition is met */ while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(--timeout == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; }if (--timeout == 0) { ... } }if (LL_SYSTICK_IsActiveCounterFlag()) { ... } /* ... */ #endif /* USE_TIMEOUT */ }while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE) { ... } return RCC_ERROR_NONE; }{ ... } /** * @brief Initialize LED2. * @param None * @retval None *//* ... */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); }{ ... } /** * @brief Turn-on LED2. * @param None * @retval None *//* ... */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); }{ ... } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None *//* ... */ void LED_Blinking(uint32_t Period) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); /* Toggle IO in an infinite loop */ while (1) { /* Error if LED2 is slowly blinking (1 sec. period) */ LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); }while (1) { ... } }{ ... } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief This function handles the HSE ready detection (called in RCC_IRQHandler) * @param None * @retval None *//* ... */ void HSEReady_Callback(void) { /* Switch the system clock to HSE */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE); /* 1ms config with HSE 8MHz*/ LL_Init1msTick(HSE_VALUE); }{ ... } /** * @brief This function handles failure detected on the HSE clock (called in NMI_Handler) * @param None * @retval None *//* ... */ void HSEFailureDetection_Callback(void) { LED_Blinking(LED_BLINK_ERROR); }{ ... } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None *//* ... */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) *//* ... */ /* Infinite loop */ while (1) { }while (1) { ... } }assert_failed (uint8_t *file, uint32_t line) { ... } /* ... */#endif /** * @} *//* ... */ /** * @} *//* ... */
Details