Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private variables
sUTILS_PLLInitStruct
sUTILS_ClkInitStruct
Private function prototypes
main()
LED_Init()
MCO_ConfigGPIO()
Files
loading...
SourceVuSTM32 Libraries and SamplesUTILS_ConfigureSystemClockSrc/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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file Examples_LL/UTILS/UTILS_ConfigureSystemClock/Src/main.c * @author MCD Application Team * @brief This example describes how to configure system clock using PLL with * HSI as source clock through the STM32F4xx UTILS LL API. ****************************************************************************** * @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 UTILS_ConfigureSystemClock * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Variable to store PLL parameters */ /* Configuration will allow to reach a SYSCLK frequency set to 100MHz: Syst freq = ((HSI_VALUE / PLLM) * PLLN)/ PLLR) ((16MHz /8) * 200)/ 4) = 100MHz *//* ... */ LL_UTILS_PLLInitTypeDef sUTILS_PLLInitStruct = {LL_RCC_PLLM_DIV_8, 200, LL_RCC_PLLP_DIV_4}; /* Variable to store AHB and APB buses clock configuration */ /* Settings to have HCLK set to 100MHz, APB1 to 54MHz and APB2 to 100MHz */ LL_UTILS_ClkInitTypeDef sUTILS_ClkInitStruct = {LL_RCC_SYSCLK_DIV_1, LL_RCC_APB1_DIV_2, LL_RCC_APB2_DIV_1}; Private variables /* Private function prototypes -----------------------------------------------*/ void LED_Init(void); void MCO_ConfigGPIO(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None *//* ... */ int main(void) { /* System started with default clock used after reset */ /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); /* Switch to PLL with HSI as clock source */ LL_PLL_ConfigSystemClock_HSI(&sUTILS_PLLInitStruct, &sUTILS_ClkInitStruct); /* CMSIS variable automatically updated according to new configuration. SystemCoreClock should be equal to calculated HCLK frequency. FLASH latency is also tuned according to system constraints described in the reference manual. *//* ... */ /* Set Systick to 1ms in using frequency set to SystemCoreClock */ LL_Init1msTick(SystemCoreClock); /* Initialize LED2 */ LED_Init(); /* Configure SYSCLK for MCO */ MCO_ConfigGPIO(); /* Toggle LED2 in an infinite loop with a period of 1Hz */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(1000); }while (1) { ... } }{ ... } /** * @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); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); }{ ... } /** * @brief Configure MCO pin (PA8). * @param None * @retval None *//* ... */ void MCO_ConfigGPIO(void) { /* MCO Clock Enable */ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); /* Configure the MCO pin in alternate function mode */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_PUSHPULL); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_8, LL_GPIO_PULL_NO); LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_8, LL_GPIO_AF_0); /* Select MCO clock source and prescaler */ LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_PLLCLK, LL_RCC_MCO1_DIV_4); }{ ... } #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