annotate f103c8/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c @ 4:ca4f5b55b391

working on pwm
author cin
date Wed, 18 Jan 2017 03:27:00 +0300
parents 0c59e7a7782a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 * @file stm32f1xx_hal_rcc.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * @author MCD Application Team
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * @version V1.0.4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 * @date 29-April-2016
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * @brief RCC HAL module driver.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 * This file provides firmware functions to manage the following
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 * functionalities of the Reset and Clock Control (RCC) peripheral:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * + Initialization and de-initialization functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 * + Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 ##### RCC specific features #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 After reset the device is running from Internal High Speed oscillator
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 (HSI 8MHz) with Flash 0 wait state, Flash prefetch buffer is enabled,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 and all peripherals are off except internal SRAM, Flash and JTAG.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 (+) There is no prescaler on High speed (AHB) and Low speed (APB) buses;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 all peripherals mapped on these buses are running at HSI speed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 (+) All GPIOs are in input floating state, except the JTAG pins which
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 are assigned to be used for debug purpose.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 [..] Once the device started from reset, the user application has to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 (+) Configure the clock source to be used to drive the System clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 (if the application needs higher frequency/performance)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 (+) Configure the System clock frequency and Flash settings
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 (+) Configure the AHB and APB buses prescalers
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31 (+) Enable the clock for the peripheral(s) to be used
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 (+) Configure the clock source(s) for peripherals whose clocks are not
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 derived from the System clock (I2S, RTC, ADC, USB OTG FS)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 ##### RCC Limitations #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 A delay between an RCC peripheral clock enable and the effective peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 enabling should be taken into account in order to manage the peripheral read/write
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 from/to registers.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 (+) This delay depends on the peripheral mapping.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42 (++) AHB & APB peripherals, 1 dummy read is necessary
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 Workarounds:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 (#) For AHB & APB peripherals, a dummy read to the peripheral register has been
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 inserted in each __HAL_RCC_PPP_CLK_ENABLE() macro.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 /* Includes ------------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 #include "stm32f1xx_hal.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 /** @addtogroup STM32F1xx_HAL_Driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 /** @defgroup RCC RCC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 * @brief RCC HAL module driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92 #ifdef HAL_RCC_MODULE_ENABLED
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 /* Private typedef -----------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 /* Private define ------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96 /** @defgroup RCC_Private_Constants RCC Private Constants
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 /* Bits position in in the CFGR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 #define RCC_CFGR_HPRE_BITNUMBER POSITION_VAL(RCC_CFGR_HPRE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 #define RCC_CFGR_PPRE1_BITNUMBER POSITION_VAL(RCC_CFGR_PPRE1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102 #define RCC_CFGR_PPRE2_BITNUMBER POSITION_VAL(RCC_CFGR_PPRE2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 /* Private macro -------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 /** @defgroup RCC_Private_Macros RCC Private Macros
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 #define MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 #define MCO1_GPIO_PORT GPIOA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 #define MCO1_PIN GPIO_PIN_8
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 /* Private variables ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 /** @defgroup RCC_Private_Variables RCC Private Variables
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127 /* Private function prototypes -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 /* Exported functions ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130 /** @defgroup RCC_Exported_Functions RCC Exported Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134 /** @defgroup RCC_Exported_Functions_Group1 Initialization and de-initialization functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 * @brief Initialization and Configuration functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139 ##### Initialization and de-initialization functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142 This section provides functions allowing to configure the internal/external oscillators
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143 (HSE, HSI, LSE, LSI, PLL, CSS and MCO) and the System buses clocks (SYSCLK, AHB, APB1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144 and APB2).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 [..] Internal/external clock and PLL configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 (#) HSI (high-speed internal), 8 MHz factory-trimmed RC used directly or through
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148 the PLL as System clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 (#) LSI (low-speed internal), ~40 KHz low consumption RC used as IWDG and/or RTC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150 clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152 (#) HSE (high-speed external), 4 to 24 MHz (STM32F100xx) or 4 to 16 MHz (STM32F101x/STM32F102x/STM32F103x) or 3 to 25 MHz (STM32F105x/STM32F107x) crystal oscillator used directly or
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 through the PLL as System clock source. Can be used also as RTC clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 (#) PLL (clocked by HSI or HSE), featuring different output clocks:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158 (++) The first output is used to generate the high speed system clock (up to 72 MHz for STM32F10xxx or up to 24 MHz for STM32F100xx)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159 (++) The second output is used to generate the clock for the USB OTG FS (48 MHz)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 (#) CSS (Clock security system), once enable using the macro __HAL_RCC_CSS_ENABLE()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162 and if a HSE clock failure occurs(HSE used directly or through PLL as System
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 clock source), the System clocks automatically switched to HSI and an interrupt
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 is generated if enabled. The interrupt is linked to the Cortex-M3 NMI
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 (Non-Maskable Interrupt) exception vector.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167 (#) MCO1 (microcontroller clock output), used to output SYSCLK, HSI,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168 HSE or PLL clock (divided by 2) on PA8 pin + PLL2CLK, PLL3CLK/2, PLL3CLK and XTI for STM32F105x/STM32F107x
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 [..] System, AHB and APB buses clocks configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 (#) Several clock sources can be used to drive the System clock (SYSCLK): HSI,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172 HSE and PLL.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173 The AHB clock (HCLK) is derived from System clock through configurable
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174 prescaler and used to clock the CPU, memory and peripherals mapped
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 from AHB clock through configurable prescalers and used to clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 the peripherals mapped on these buses. You can use
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178 "@ref HAL_RCC_GetSysClockFreq()" function to retrieve the frequencies of these clocks.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180 -@- All the peripheral clocks are derived from the System clock (SYSCLK) except:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181 (+@) RTC: RTC clock can be derived either from the LSI, LSE or HSE clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 divided by 128.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 (+@) USB OTG FS and RTC: USB OTG FS require a frequency equal to 48 MHz
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 to work correctly. This clock is derived of the main PLL through PLL Multiplier.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 (+@) I2S interface on STM32F105x/STM32F107x can be derived from PLL3CLK
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 (+@) IWDG clock which is always the LSI clock.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 (#) For STM32F10xxx, the maximum frequency of the SYSCLK and HCLK/PCLK2 is 72 MHz, PCLK1 36 MHz.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189 For STM32F100xx, the maximum frequency of the SYSCLK and HCLK/PCLK1/PCLK2 is 24 MHz.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190 Depending on the SYSCLK frequency, the flash latency should be adapted accordingly.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195 /*
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196 Additional consideration on the SYSCLK based on Latency settings:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 +-----------------------------------------------+
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198 | Latency | SYSCLK clock frequency (MHz) |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 |---------------|-------------------------------|
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200 |0WS(1CPU cycle)| 0 < SYSCLK <= 24 |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201 |---------------|-------------------------------|
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202 |1WS(2CPU cycle)| 24 < SYSCLK <= 48 |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203 |---------------|-------------------------------|
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 |2WS(3CPU cycle)| 48 < SYSCLK <= 72 |
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 +-----------------------------------------------+
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209 * @brief Resets the RCC clock configuration to the default reset state.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 * @note The default reset state of the clock configuration is given below:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 * - HSI ON and used as system clock source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212 * - HSE and PLL OFF
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213 * - AHB, APB1 and APB2 prescaler set to 1.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 * - CSS and MCO1 OFF
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215 * - All interrupts disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216 * @note This function does not modify the configuration of the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 * - Peripheral clocks
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218 * - LSI, LSE and RTC clocks
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221 void HAL_RCC_DeInit(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223 /* Switch SYSCLK to HSI */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224 CLEAR_BIT(RCC->CFGR, RCC_CFGR_SW);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 /* Reset HSEON, CSSON, & PLLON bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227 CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON | RCC_CR_PLLON);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229 /* Reset HSEBYP bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230 CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 /* Reset CFGR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233 CLEAR_REG(RCC->CFGR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235 /* Set HSITRIM bits to the reset value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236 MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, ((uint32_t)0x10 << POSITION_VAL(RCC_CR_HSITRIM)));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238 #if (defined(STM32F105xC) || defined(STM32F107xC) || defined (STM32F100xB) || defined (STM32F100xE))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239 /* Reset CFGR2 register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 CLEAR_REG(RCC->CFGR2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242 #endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 /* Disable all interrupts */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244 CLEAR_REG(RCC->CIR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 /* Update the SystemCoreClock global variable */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247 SystemCoreClock = HSI_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251 * @brief Initializes the RCC Oscillators according to the specified parameters in the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 * RCC_OscInitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253 * @param RCC_OscInitStruct pointer to an RCC_OscInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254 * contains the configuration information for the RCC Oscillators.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 * @note The PLL is not disabled when used as system clock.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256 * @note The PLL is not disabled when USB OTG FS clock is enabled (specific to devices with USB FS)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257 * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 * supported by this macro. User should request a transition to LSE Off
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259 * first and then LSE On or LSE Bypass.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260 * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 * supported by this macro. User should request a transition to HSE Off
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262 * first and then HSE On or HSE Bypass.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270 assert_param(RCC_OscInitStruct != NULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273 /*------------------------------- HSE Configuration ------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279 /* When the HSE is used as system clock or clock source for PLL in these cases it is not allowed to be disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 || ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
286 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
287 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
288 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 /* Set the new HSE configuration ---------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291 __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294 /* Check the HSE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295 if(RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 /* Wait till HSE is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314 /* Wait till HSE is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325 /*----------------------------- HSI Configuration --------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330 assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332 /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSI)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334 || ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI_DIV2)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 /* When HSI is used as system clock it will not disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341 /* Otherwise, just the calibration is allowed */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 /* Check the HSI State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351 if(RCC_OscInitStruct->HSIState != RCC_HSI_OFF)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353 /* Enable the Internal High Speed oscillator (HSI). */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354 __HAL_RCC_HSI_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 /* Wait till HSI is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373 /* Disable the Internal High Speed oscillator (HSI). */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 __HAL_RCC_HSI_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 /* Wait till HSI is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 /*------------------------------ LSI Configuration -------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394 assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
395
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
396 /* Check the LSI State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397 if(RCC_OscInitStruct->LSIState != RCC_LSI_OFF)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
398 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 /* Enable the Internal Low Speed oscillator (LSI). */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 __HAL_RCC_LSI_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 /* Wait till LSI is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413 /* To have a fully stabilized clock in the specified range, a software delay of 1ms
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 should be added.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415 HAL_Delay(1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419 /* Disable the Internal Low Speed oscillator (LSI). */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 __HAL_RCC_LSI_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 /* Wait till LSI is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 /*------------------------------ LSE Configuration -------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439 assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 /* Enable Power Clock*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442 __HAL_RCC_PWR_CLK_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444 /* Enable write access to Backup domain */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445 SET_BIT(PWR->CR, PWR_CR_DBP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 /* Wait for Backup domain Write protection disable */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
449
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
450 while((PWR->CR & PWR_CR_DBP) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
451 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
452 if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
453 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
454 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
455 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
456 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
457
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
458 /* Set the new LSE configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
459 __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
460 /* Check the LSE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
461 if(RCC_OscInitStruct->LSEState != RCC_LSE_OFF)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
462 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
463 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
464 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
465
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
466 /* Wait till LSE is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
467 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
468 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
469 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
470 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
471 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
472 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
473 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
474 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
475 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
476 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
477 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
478 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
479
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
480 /* Wait till LSE is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
481 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
482 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
483 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
484 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
485 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
486 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
487 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
488 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
489 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
490
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
491 #if defined(RCC_CR_PLL2ON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
492 /*-------------------------------- PLL2 Configuration -----------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
493 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
494 assert_param(IS_RCC_PLL2(RCC_OscInitStruct->PLL2.PLL2State));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
495 if ((RCC_OscInitStruct->PLL2.PLL2State) != RCC_PLL2_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
496 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
497 /* This bit can not be cleared if the PLL2 clock is used indirectly as system
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
498 clock (i.e. it is used as PLL clock entry that is used as system clock). */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
499 if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
500 (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
501 ((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
502 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
503 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
504 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
505 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
506 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
507 if((RCC_OscInitStruct->PLL2.PLL2State) == RCC_PLL2_ON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
508 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
509 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
510 assert_param(IS_RCC_PLL2_MUL(RCC_OscInitStruct->PLL2.PLL2MUL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
511 assert_param(IS_RCC_HSE_PREDIV2(RCC_OscInitStruct->PLL2.HSEPrediv2Value));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
512
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
513 /* Prediv2 can be written only when the PLLI2S is disabled. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
514 /* Return an error only if new value is different from the programmed value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
515 if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
516 (__HAL_RCC_HSE_GET_PREDIV2() != RCC_OscInitStruct->PLL2.HSEPrediv2Value))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
517 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
518 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
519 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
520
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
521 /* Disable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
522 __HAL_RCC_PLL2_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
523
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
524 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
525 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
526
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
527 /* Wait till PLL2 is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
528 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
529 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
530 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
531 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
532 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
533 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
534 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
535
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
536 /* Configure the HSE prediv2 factor --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
537 __HAL_RCC_HSE_PREDIV2_CONFIG(RCC_OscInitStruct->PLL2.HSEPrediv2Value);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
538
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
539 /* Configure the main PLL2 multiplication factors. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
540 __HAL_RCC_PLL2_CONFIG(RCC_OscInitStruct->PLL2.PLL2MUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
541
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
542 /* Enable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
543 __HAL_RCC_PLL2_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
544
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
545 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
546 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
547
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
548 /* Wait till PLL2 is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
549 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
550 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
551 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
552 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
553 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
554 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
555 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
556 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
557 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
558 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
559 /* Set PREDIV1 source to HSE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
560 CLEAR_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
561
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
562 /* Disable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
563 __HAL_RCC_PLL2_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
564
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
565 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
566 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
567
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
568 /* Wait till PLL2 is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
569 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
570 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
571 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
572 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
573 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
574 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
575 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
576 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
577 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
578 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
579
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
580 #endif /* RCC_CR_PLL2ON */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
581 /*-------------------------------- PLL Configuration -----------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
582 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
583 assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
584 if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
585 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
586 /* Check if the PLL is used as system clock or not */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
587 if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
588 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
589 if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
590 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
591 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
592 assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
593 assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
594
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
595 /* Disable the main PLL. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
596 __HAL_RCC_PLL_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
597
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
598 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
599 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
600
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
601 /* Wait till PLL is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
602 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
603 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
604 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
605 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
606 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
607 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
608 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
609
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
610 /* Configure the HSE prediv factor --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
611 /* It can be written only when the PLL is disabled. Not used in PLL source is different than HSE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
612 if(RCC_OscInitStruct->PLL.PLLSource == RCC_PLLSOURCE_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
613 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
614 /* Check the parameter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
615 assert_param(IS_RCC_HSE_PREDIV(RCC_OscInitStruct->HSEPredivValue));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
616 #if defined(RCC_CFGR2_PREDIV1SRC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
617 assert_param(IS_RCC_PREDIV1_SOURCE(RCC_OscInitStruct->Prediv1Source));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
618
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
619 /* Set PREDIV1 source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
620 SET_BIT(RCC->CFGR2, RCC_OscInitStruct->Prediv1Source);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
621 #endif /* RCC_CFGR2_PREDIV1SRC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
622
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
623 /* Set PREDIV1 Value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
624 __HAL_RCC_HSE_PREDIV_CONFIG(RCC_OscInitStruct->HSEPredivValue);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
625 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
626
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
627 /* Configure the main PLL clock source and multiplication factors. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
628 __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
629 RCC_OscInitStruct->PLL.PLLMUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
630 /* Enable the main PLL. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
631 __HAL_RCC_PLL_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
632
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
633 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
634 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
635
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
636 /* Wait till PLL is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
637 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
638 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
639 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
640 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
641 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
642 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
643 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
644 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
645 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
646 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
647 /* Disable the main PLL. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
648 __HAL_RCC_PLL_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
649
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
650 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
651 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
652
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
653 /* Wait till PLL is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
654 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
655 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
656 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
657 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
658 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
659 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
660 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
661 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
662 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
663 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
664 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
665 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
666 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
667 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
668
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
669 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
670 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
671
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
672 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
673 * @brief Initializes the CPU, AHB and APB buses clocks according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
674 * parameters in the RCC_ClkInitStruct.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
675 * @param RCC_ClkInitStruct pointer to an RCC_OscInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
676 * contains the configuration information for the RCC peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
677 * @param FLatency FLASH Latency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
678 * The value of this parameter depend on device used within the same series
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
679 * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
680 * and updated by @ref HAL_RCC_GetHCLKFreq() function called within this function
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
681 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
682 * @note The HSI is used (enabled by hardware) as system clock source after
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
683 * start-up from Reset, wake-up from STOP and STANDBY mode, or in case
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
684 * of failure of the HSE used directly or indirectly as system clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
685 * (if the Clock Security System CSS is enabled).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
686 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
687 * @note A switch from one clock source to another occurs only if the target
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
688 * clock source is ready (clock stable after start-up delay or PLL locked).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
689 * If a clock source which is not yet ready is selected, the switch will
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
690 * occur when the clock source will be ready.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
691 * You can use @ref HAL_RCC_GetClockConfig() function to know which clock is
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
692 * currently used as system clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
693 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
694 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
695 HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
696 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
697 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
698
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
699 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
700 assert_param(RCC_ClkInitStruct != NULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
701 assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
702 assert_param(IS_FLASH_LATENCY(FLatency));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
703
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
704 /* To correctly read data from FLASH memory, the number of wait states (LATENCY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
705 must be correctly programmed according to the frequency of the CPU clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
706 (HCLK) of the device. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
707
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
708 #if defined(FLASH_ACR_LATENCY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
709 /* Increasing the number of wait states because of higher CPU frequency */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
710 if(FLatency > (FLASH->ACR & FLASH_ACR_LATENCY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
711 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
712 /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
713 __HAL_FLASH_SET_LATENCY(FLatency);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
714
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
715 /* Check that the new number of wait states is taken into account to access the Flash
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
716 memory by reading the FLASH_ACR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
717 if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
718 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
719 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
720 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
721 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
722
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
723 #endif /* FLASH_ACR_LATENCY */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
724 /*-------------------------- HCLK Configuration --------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
725 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
726 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
727 assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
728 MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
729 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
730
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
731 /*------------------------- SYSCLK Configuration ---------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
732 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
733 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
734 assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
735
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
736 /* HSE is selected as System Clock Source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
737 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
738 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
739 /* Check the HSE ready flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
740 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
741 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
742 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
743 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
744 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
745 /* PLL is selected as System Clock Source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
746 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
747 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
748 /* Check the PLL ready flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
749 if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
750 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
751 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
752 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
753 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
754 /* HSI is selected as System Clock Source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
755 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
756 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
757 /* Check the HSI ready flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
758 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
759 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
760 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
761 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
762 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
763 __HAL_RCC_SYSCLK_CONFIG(RCC_ClkInitStruct->SYSCLKSource);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
764
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
765 /* Get Start Tick */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
766 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
767
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
768 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
769 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
770 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
771 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
772 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
773 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
774 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
775 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
776 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
777 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
778 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
779 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
780 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
781 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
782 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
783 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
784 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
785 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
786 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
787 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
788 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
789 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
790 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
791 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
792 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
793 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
794 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
795 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
796 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
797 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
798 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
799 #if defined(FLASH_ACR_LATENCY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
800 /* Decreasing the number of wait states because of lower CPU frequency */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
801 if(FLatency < (FLASH->ACR & FLASH_ACR_LATENCY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
802 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
803 /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
804 __HAL_FLASH_SET_LATENCY(FLatency);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
805
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
806 /* Check that the new number of wait states is taken into account to access the Flash
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
807 memory by reading the FLASH_ACR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
808 if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
809 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
810 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
811 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
812 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
813 #endif /* FLASH_ACR_LATENCY */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
814
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
815 /*-------------------------- PCLK1 Configuration ---------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
816 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
817 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
818 assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
819 MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
820 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
821
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
822 /*-------------------------- PCLK2 Configuration ---------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
823 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
824 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
825 assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
826 MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
827 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
828
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
829 /* Update the SystemCoreClock global variable */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
830 SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> RCC_CFGR_HPRE_BITNUMBER];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
831
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
832 /* Configure the source of time base considering new system clocks settings*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
833 HAL_InitTick (TICK_INT_PRIORITY);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
834
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
835 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
836 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
837
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
838 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
839 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
840 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
841
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
842 /** @defgroup RCC_Exported_Functions_Group2 Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
843 * @brief RCC clocks control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
844 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
845 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
846 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
847 ##### Peripheral Control functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
848 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
849 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
850 This subsection provides a set of functions allowing to control the RCC Clocks
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
851 frequencies.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
852
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
853 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
854 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
855 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
856
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
857 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
858 * @brief Selects the clock source to output on MCO pin.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
859 * @note MCO pin should be configured in alternate function mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
860 * @param RCC_MCOx specifies the output direction for the clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
861 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
862 * @arg @ref RCC_MCO1 Clock source to output on MCO1 pin(PA8).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
863 * @param RCC_MCOSource specifies the clock source to output.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
864 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
865 * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
866 * @arg @ref RCC_MCO1SOURCE_SYSCLK System clock selected as MCO clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
867 * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
868 * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
869 @if STM32F105xC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
870 * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
871 * @arg @ref RCC_MCO1SOURCE_PLL2CLK PLL2 clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
872 * @arg @ref RCC_MCO1SOURCE_PLL3CLK_DIV2 PLL3 clock divided by 2 selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
873 * @arg @ref RCC_MCO1SOURCE_EXT_HSE XT1 external 3-25 MHz oscillator clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
874 * @arg @ref RCC_MCO1SOURCE_PLL3CLK PLL3 clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
875 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
876 @if STM32F107xC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
877 * @arg @ref RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
878 * @arg @ref RCC_MCO1SOURCE_PLL2CLK PLL2 clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
879 * @arg @ref RCC_MCO1SOURCE_PLL3CLK_DIV2 PLL3 clock divided by 2 selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
880 * @arg @ref RCC_MCO1SOURCE_EXT_HSE XT1 external 3-25 MHz oscillator clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
881 * @arg @ref RCC_MCO1SOURCE_PLL3CLK PLL3 clock selected as MCO source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
882 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
883 * @param RCC_MCODiv specifies the MCO DIV.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
884 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
885 * @arg @ref RCC_MCODIV_1 no division applied to MCO clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
886 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
887 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
888 void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
889 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
890 GPIO_InitTypeDef gpio = {0};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
891
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
892 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
893 assert_param(IS_RCC_MCO(RCC_MCOx));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
894 assert_param(IS_RCC_MCODIV(RCC_MCODiv));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
895 assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
896
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
897 /* Configure the MCO1 pin in alternate function mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
898 gpio.Mode = GPIO_MODE_AF_PP;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
899 gpio.Speed = GPIO_SPEED_FREQ_HIGH;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
900 gpio.Pull = GPIO_NOPULL;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
901 gpio.Pin = MCO1_PIN;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
902
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
903 /* MCO1 Clock Enable */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
904 MCO1_CLK_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
905
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
906 HAL_GPIO_Init(MCO1_GPIO_PORT, &gpio);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
907
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
908 /* Configure the MCO clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
909 __HAL_RCC_MCO1_CONFIG(RCC_MCOSource, RCC_MCODiv);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
910 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
911
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
912 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
913 * @brief Enables the Clock Security System.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
914 * @note If a failure is detected on the HSE oscillator clock, this oscillator
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
915 * is automatically disabled and an interrupt is generated to inform the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
916 * software about the failure (Clock Security System Interrupt, CSSI),
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
917 * allowing the MCU to perform rescue operations. The CSSI is linked to
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
918 * the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
919 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
920 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
921 void HAL_RCC_EnableCSS(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
922 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
923 *(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)ENABLE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
924 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
925
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
926 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
927 * @brief Disables the Clock Security System.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
928 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
929 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
930 void HAL_RCC_DisableCSS(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
931 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
932 *(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)DISABLE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
933 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
934
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
935 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
936 * @brief Returns the SYSCLK frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
937 * @note The system frequency computed by this function is not the real
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
938 * frequency in the chip. It is calculated based on the predefined
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
939 * constant and the selected clock source:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
940 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
941 * @note If SYSCLK source is HSE, function returns a value based on HSE_VALUE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
942 * divided by PREDIV factor(**)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
943 * @note If SYSCLK source is PLL, function returns a value based on HSE_VALUE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
944 * divided by PREDIV factor(**) or HSI_VALUE(*) multiplied by the PLL factor.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
945 * @note (*) HSI_VALUE is a constant defined in stm32f1xx_hal_conf.h file (default value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
946 * 8 MHz) but the real value may vary depending on the variations
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
947 * in voltage and temperature.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
948 * @note (**) HSE_VALUE is a constant defined in stm32f1xx_hal_conf.h file (default value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
949 * 8 MHz), user has to ensure that HSE_VALUE is same as the real
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
950 * frequency of the crystal used. Otherwise, this function may
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
951 * have wrong result.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
952 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
953 * @note The result of this function could be not correct when using fractional
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
954 * value for HSE crystal.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
955 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
956 * @note This function can be used by the user application to compute the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
957 * baud-rate for the communication peripherals or configure other parameters.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
958 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
959 * @note Each time SYSCLK changes, this function must be called to update the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
960 * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
961 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
962 * @retval SYSCLK frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
963 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
964 uint32_t HAL_RCC_GetSysClockFreq(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
965 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
966 #if defined(RCC_CFGR2_PREDIV1SRC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
967 const uint8_t aPLLMULFactorTable[12] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 13};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
968 const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
969 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
970 const uint8_t aPLLMULFactorTable[16] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
971 #if defined(RCC_CFGR2_PREDIV1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
972 const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
973 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
974 const uint8_t aPredivFactorTable[2] = { 1, 2};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
975 #endif /*RCC_CFGR2_PREDIV1*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
976
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
977 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
978 uint32_t tmpreg = 0, prediv = 0, pllclk = 0, pllmul = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
979 uint32_t sysclockfreq = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
980 #if defined(RCC_CFGR2_PREDIV1SRC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
981 uint32_t prediv2 = 0, pll2mul = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
982 #endif /*RCC_CFGR2_PREDIV1SRC*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
983
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
984 tmpreg = RCC->CFGR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
985
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
986 /* Get SYSCLK source -------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
987 switch (tmpreg & RCC_CFGR_SWS)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
988 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
989 case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
990 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
991 sysclockfreq = HSE_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
992 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
993 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
994 case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
995 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
996 pllmul = aPLLMULFactorTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMULL) >> POSITION_VAL(RCC_CFGR_PLLMULL)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
997 if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
998 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
999 #if defined(RCC_CFGR2_PREDIV1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1000 prediv = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> POSITION_VAL(RCC_CFGR2_PREDIV1)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1001 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1002 prediv = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> POSITION_VAL(RCC_CFGR_PLLXTPRE)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1003 #endif /*RCC_CFGR2_PREDIV1*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1004 #if defined(RCC_CFGR2_PREDIV1SRC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1005
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1006 if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1007 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1008 /* PLL2 selected as Prediv1 source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1009 /* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1010 prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> POSITION_VAL(RCC_CFGR2_PREDIV2)) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1011 pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> POSITION_VAL(RCC_CFGR2_PLL2MUL)) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1012 pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1013 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1014 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1015 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1016 /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1017 pllclk = (uint32_t)((HSE_VALUE / prediv) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1018 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1019
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1020 /* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1021 /* In this case need to divide pllclk by 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1022 if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> POSITION_VAL(RCC_CFGR_PLLMULL)])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1023 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1024 pllclk = pllclk / 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1025 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1026 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1027 /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1028 pllclk = (uint32_t)((HSE_VALUE / prediv) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1029 #endif /*RCC_CFGR2_PREDIV1SRC*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1030 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1031 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1032 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1033 /* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1034 pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1035 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1036 sysclockfreq = pllclk;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1037 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1038 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1039 case RCC_SYSCLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1040 default: /* HSI used as system clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1041 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1042 sysclockfreq = HSI_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1043 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1044 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1045 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1046 return sysclockfreq;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1047 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1048
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1049 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1050 * @brief Returns the HCLK frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1051 * @note Each time HCLK changes, this function must be called to update the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1052 * right HCLK value. Otherwise, any configuration based on this function will be incorrect.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1053 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1054 * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1055 * and updated within this function
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1056 * @retval HCLK frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1057 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1058 uint32_t HAL_RCC_GetHCLKFreq(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1059 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1060 return SystemCoreClock;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1061 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1062
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1063 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1064 * @brief Returns the PCLK1 frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1065 * @note Each time PCLK1 changes, this function must be called to update the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1066 * right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1067 * @retval PCLK1 frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1068 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1069 uint32_t HAL_RCC_GetPCLK1Freq(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1070 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1071 /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1072 return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_BITNUMBER]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1073 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1074
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1075 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1076 * @brief Returns the PCLK2 frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1077 * @note Each time PCLK2 changes, this function must be called to update the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1078 * right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1079 * @retval PCLK2 frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1080 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1081 uint32_t HAL_RCC_GetPCLK2Freq(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1082 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1083 /* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1084 return (HAL_RCC_GetHCLKFreq()>> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_BITNUMBER]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1085 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1086
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1087 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1088 * @brief Configures the RCC_OscInitStruct according to the internal
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1089 * RCC configuration registers.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1090 * @param RCC_OscInitStruct pointer to an RCC_OscInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1091 * will be configured.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1092 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1093 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1094 void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1095 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1096 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1097 assert_param(RCC_OscInitStruct != NULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1098
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1099 /* Set all possible values for the Oscillator type parameter ---------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1100 RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1101 | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1102
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1103 #if defined(RCC_CFGR2_PREDIV1SRC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1104 /* Get the Prediv1 source --------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1105 RCC_OscInitStruct->Prediv1Source = READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1106 #endif /* RCC_CFGR2_PREDIV1SRC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1107
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1108 /* Get the HSE configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1109 if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1110 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1111 RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1112 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1113 else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1114 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1115 RCC_OscInitStruct->HSEState = RCC_HSE_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1116 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1117 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1118 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1119 RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1120 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1121 RCC_OscInitStruct->HSEPredivValue = __HAL_RCC_HSE_GET_PREDIV();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1122
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1123 /* Get the HSI configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1124 if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1125 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1126 RCC_OscInitStruct->HSIState = RCC_HSI_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1127 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1128 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1129 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1130 RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1131 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1132
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1133 RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR & RCC_CR_HSITRIM) >> POSITION_VAL(RCC_CR_HSITRIM));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1134
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1135 /* Get the LSE configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1136 if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1137 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1138 RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1139 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1140 else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1141 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1142 RCC_OscInitStruct->LSEState = RCC_LSE_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1143 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1144 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1145 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1146 RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1147 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1148
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1149 /* Get the LSI configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1150 if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1151 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1152 RCC_OscInitStruct->LSIState = RCC_LSI_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1153 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1154 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1155 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1156 RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1157 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1158
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1159
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1160 /* Get the PLL configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1161 if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1162 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1163 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1164 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1165 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1166 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1167 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1168 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1169 RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1170 RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1171 #if defined(RCC_CR_PLL2ON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1172 /* Get the PLL2 configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1173 if((RCC->CR &RCC_CR_PLL2ON) == RCC_CR_PLL2ON)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1174 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1175 RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_ON;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1176 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1177 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1178 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1179 RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_OFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1180 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1181 RCC_OscInitStruct->PLL2.HSEPrediv2Value = __HAL_RCC_HSE_GET_PREDIV2();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1182 RCC_OscInitStruct->PLL2.PLL2MUL = (uint32_t)(RCC->CFGR2 & RCC_CFGR2_PLL2MUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1183 #endif /* RCC_CR_PLL2ON */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1184 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1185
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1186 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1187 * @brief Get the RCC_ClkInitStruct according to the internal
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1188 * RCC configuration registers.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1189 * @param RCC_ClkInitStruct pointer to an RCC_ClkInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1190 * contains the current clock configuration.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1191 * @param pFLatency Pointer on the Flash Latency.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1192 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1193 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1194 void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1195 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1196 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1197 assert_param(RCC_ClkInitStruct != NULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1198 assert_param(pFLatency != NULL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1199
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1200 /* Set all possible values for the Clock type parameter --------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1201 RCC_ClkInitStruct->ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1202
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1203 /* Get the SYSCLK configuration --------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1204 RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1205
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1206 /* Get the HCLK configuration ----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1207 RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_HPRE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1208
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1209 /* Get the APB1 configuration ----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1210 RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1211
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1212 /* Get the APB2 configuration ----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1213 RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1214
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1215 #if defined(FLASH_ACR_LATENCY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1216 /* Get the Flash Wait State (Latency) configuration ------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1217 *pFLatency = (uint32_t)(FLASH->ACR & FLASH_ACR_LATENCY);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1218 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1219 /* For VALUE lines devices, only LATENCY_0 can be set*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1220 *pFLatency = (uint32_t)FLASH_LATENCY_0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1221 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1222 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1223
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1224 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1225 * @brief This function handles the RCC CSS interrupt request.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1226 * @note This API should be called under the NMI_Handler().
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1227 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1228 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1229 void HAL_RCC_NMI_IRQHandler(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1230 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1231 /* Check RCC CSSF flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1232 if(__HAL_RCC_GET_IT(RCC_IT_CSS))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1233 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1234 /* RCC Clock Security System interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1235 HAL_RCC_CSSCallback();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1236
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1237 /* Clear RCC CSS pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1238 __HAL_RCC_CLEAR_IT(RCC_IT_CSS);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1239 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1240 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1241
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1242 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1243 * @brief RCC Clock Security System interrupt callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1244 * @retval none
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1245 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1246 __weak void HAL_RCC_CSSCallback(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1247 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1248 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1249 the HAL_RCC_CSSCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1250 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1251 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1252
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1253 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1254 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1255 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1256
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1257 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1258 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1259 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1260
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1261 #endif /* HAL_RCC_MODULE_ENABLED */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1262 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1263 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1264 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1265
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1266 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1267 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1268 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1269
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1270 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/