annotate f103c8/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c @ 5:0d3eea2dd7ea

working on devices and timers
author cin
date Fri, 20 Jan 2017 03:40:30 +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_ex.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 Extended 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 RCC extension peripheral:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * + Extended Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42 /* Includes ------------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 #include "stm32f1xx_hal.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 /** @addtogroup STM32F1xx_HAL_Driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 #ifdef HAL_RCC_MODULE_ENABLED
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 /** @defgroup RCCEx RCCEx
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 * @brief RCC Extension HAL module driver.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 /* Private typedef -----------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 /* Private define ------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 /** @defgroup RCCEx_Private_Constants RCCEx Private Constants
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65 /* Private macro -------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 /* Private variables ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 /* Private function prototypes -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 /* Private functions ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
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
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 /** @defgroup RCCEx_Exported_Functions_Group1 Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82 * @brief Extended Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86 ##### Extended Peripheral Control functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 This subsection provides a set of functions allowing to control the RCC Clocks
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 frequencies.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92 (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 select the RTC clock source; in this case the Backup domain will be reset in
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 order to modify the RTC Clock source, as consequence RTC registers (including
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 the backup registers) are set to their reset values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102 * @brief Initializes the RCC extended peripherals clocks according to the specified parameters in the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 * RCC_PeriphCLKInitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105 * contains the configuration information for the Extended Peripherals clocks(RTC clock).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 * the RTC clock source; in this case the Backup domain will be reset in
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109 * order to modify the RTC Clock source, as consequence RTC registers (including
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 * the backup registers) are set to their reset values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 * @note In case of STM32F105xC or STM32F107xC devices, PLLI2S will be enabled if requested on
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 * one of 2 I2S interfaces. When PLLI2S is enabled, you need to call HAL_RCCEx_DisablePLLI2S to
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114 * manually disable it.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 uint32_t tickstart = 0, temp_reg = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 uint32_t pllactive = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 #endif /* STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126 assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 /*------------------------------- RTC/LCD Configuration ------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 /* check for RTC Parameters used to output RTCCLK */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132 assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134 /* Enable Power Clock*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 __HAL_RCC_PWR_CLK_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137 /* Enable write access to Backup domain */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 SET_BIT(PWR->CR, PWR_CR_DBP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 /* Wait for Backup domain Write protection disable */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143 while((PWR->CR & PWR_CR_DBP) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145 if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151 /* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152 temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 if((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 /* Store the content of BDCR register before the reset of Backup Domain */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156 temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 /* RTC Clock selection can be changed only if the Backup Domain is reset */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158 __HAL_RCC_BACKUPRESET_FORCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159 __HAL_RCC_BACKUPRESET_RELEASE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160 /* Restore the Content of BDCR register */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 RCC->BDCR = temp_reg;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 /* Wait for LSERDY if LSE was enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166 /* Get timeout */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169 /* Wait till LSE is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172 if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 /*------------------------------ ADC clock Configuration ------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 assert_param(IS_RCC_ADCPLLCLK_DIV(PeriphClkInit->AdcClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 /* Configure the ADC clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189 __HAL_RCC_ADC_CONFIG(PeriphClkInit->AdcClockSelection);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193 /*------------------------------ I2S2 Configuration ------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 assert_param(IS_RCC_I2S2CLKSOURCE(PeriphClkInit->I2s2ClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 /* Configure the I2S2 clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200 __HAL_RCC_I2S2_CONFIG(PeriphClkInit->I2s2ClockSelection);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203 /*------------------------------ I2S3 Configuration ------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207 assert_param(IS_RCC_I2S3CLKSOURCE(PeriphClkInit->I2s3ClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209 /* Configure the I2S3 clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 __HAL_RCC_I2S3_CONFIG(PeriphClkInit->I2s3ClockSelection);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213 /*------------------------------ PLL I2S Configuration ----------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 /* Check that PLLI2S need to be enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215 if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 /* Update flag to indicate that PLL I2S should be active */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218 pllactive = 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221 /* Check if PLL I2S need to be enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222 if (pllactive == 1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224 /* Enable PLL I2S only if not active */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225 if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228 assert_param(IS_RCC_PLLI2S_MUL(PeriphClkInit->PLLI2S.PLLI2SMUL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229 assert_param(IS_RCC_HSE_PREDIV2(PeriphClkInit->PLLI2S.HSEPrediv2Value));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231 /* Prediv2 can be written only when the PLL2 is disabled. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 /* Return an error only if new value is different from the programmed value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233 if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234 (__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239 /* Configure the HSE prediv2 factor --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 __HAL_RCC_HSE_PREDIV2_CONFIG(PeriphClkInit->PLLI2S.HSEPrediv2Value);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242 /* Configure the main PLLI2S multiplication factors. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SMUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245 /* Enable the main PLLI2S. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 __HAL_RCC_PLLI2S_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251 /* Wait till PLLI2S is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262 /* Return an error only if user wants to change the PLLI2SMUL whereas PLLI2S is active */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263 if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269 #endif /* STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 #if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272 || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273 || defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 /*------------------------------ USB clock Configuration ------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278 assert_param(IS_RCC_USBPLLCLK_DIV(PeriphClkInit->UsbClockSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280 /* Configure the USB clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 __HAL_RCC_USB_CONFIG(PeriphClkInit->UsbClockSelection);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283 #endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 return HAL_OK;
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 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289 * @brief Get the PeriphClkInit according to the internal
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 * RCC configuration registers.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291 * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292 * returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 uint32_t srcclk = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299 /* Set all possible values for the extended clock type parameter------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302 /* Get the RTC configuration -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 srcclk = __HAL_RCC_GET_RTC_SOURCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 /* Source clock is LSE or LSI*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305 PeriphClkInit->RTCClockSelection = srcclk;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307 /* Get the ADC clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_ADC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 PeriphClkInit->AdcClockSelection = __HAL_RCC_GET_ADC_SOURCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 /* Get the I2S2 clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314 PeriphClkInit->I2s2ClockSelection = __HAL_RCC_GET_I2S2_SOURCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316 /* Get the I2S3 clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318 PeriphClkInit->I2s3ClockSelection = __HAL_RCC_GET_I2S3_SOURCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320 #endif /* STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322 #if defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 /* Get the I2S2 clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325 PeriphClkInit->I2s2ClockSelection = RCC_I2S2CLKSOURCE_SYSCLK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 /* Get the I2S3 clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 PeriphClkInit->I2s3ClockSelection = RCC_I2S3CLKSOURCE_SYSCLK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331 #endif /* STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 #if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334 || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 || defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 /* Get the USB clock configuration -----------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337 PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339 #endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343 * @brief Returns the peripheral clock frequency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 * @note Returns 0 if peripheral clock is unknown
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345 * @param PeriphClk Peripheral clock identifier
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 * @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348 * @arg @ref RCC_PERIPHCLK_ADC ADC peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 @if STM32F103xE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354 @if STM32F103xG
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360 @if STM32F105xC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 @if STM32F107xC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376 * @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 * @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380 @if STM32F102xx
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 @if STM32F103xx
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 @endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 #if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391 || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392 || defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394 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
395 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
396 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397 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
398 const uint8_t aPredivFactorTable[2] = { 1, 2};
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401 uint32_t temp_reg = 0, frequency = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 #if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404 || defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 uint32_t prediv1 = 0, pllclk = 0, pllmul = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406 #endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408 uint32_t pll2mul = 0, pll3mul = 0, prediv2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409 #endif /* STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412 assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 switch (PeriphClk)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416 #if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418 || defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419 case RCC_PERIPHCLK_USB:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421 /* Get RCC configuration ------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422 temp_reg = RCC->CFGR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424 /* Check if PLL is enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLLON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427 pllmul = aPLLMULFactorTable[(uint32_t)(temp_reg & RCC_CFGR_PLLMULL) >> POSITION_VAL(RCC_CFGR_PLLMULL)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428 if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430 #if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 || defined(STM32F100xE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> POSITION_VAL(RCC_CFGR2_PREDIV1)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> POSITION_VAL(RCC_CFGR_PLLXTPRE)];
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 #endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440 /* PLL2 selected as Prediv1 source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 /* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442 prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> POSITION_VAL(RCC_CFGR2_PREDIV2)) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443 pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> POSITION_VAL(RCC_CFGR2_PLL2MUL)) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444 pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv1) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448 /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
449 pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
450 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
451
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
452 /* 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
453 /* In this case need to divide pllclk by 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
454 if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> POSITION_VAL(RCC_CFGR_PLLMULL)])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
455 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
456 pllclk = pllclk / 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
457 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
458 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
459 if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
460 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
461 /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
462 pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
463 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
464 #endif /* STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
465 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
466 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
467 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
468 /* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
469 pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
470 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
471
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
472 /* Calcul of the USB frequency*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
473 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
474 /* USBCLK = PLLVCO = (2 x PLLCLK) / USB prescaler */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
475 if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
476 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
477 /* Prescaler of 2 selected for USB */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
478 frequency = pllclk;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
479 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
480 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
481 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
482 /* Prescaler of 3 selected for USB */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
483 frequency = (2 * pllclk) / 3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
484 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
485 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
486 /* USBCLK = PLLCLK / USB prescaler */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
487 if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
488 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
489 /* No prescaler selected for USB */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
490 frequency = pllclk;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
491 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
492 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
493 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
494 /* Prescaler of 1.5 selected for USB */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
495 frequency = (pllclk * 2) / 3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
496 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
497 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
498 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
499 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
500 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
501 #endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
502 #if defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC)\
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
503 || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
504 case RCC_PERIPHCLK_I2S2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
505 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
506 #if defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
507 /* SYSCLK used as source clock for I2S2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
508 frequency = HAL_RCC_GetSysClockFreq();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
509 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
510 if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
511 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
512 /* SYSCLK used as source clock for I2S2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
513 frequency = HAL_RCC_GetSysClockFreq();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
514 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
515 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
516 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
517 /* Check if PLLI2S is enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
518 if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
519 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
520 /* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
521 prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> POSITION_VAL(RCC_CFGR2_PREDIV2)) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
522 pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> POSITION_VAL(RCC_CFGR2_PLL3MUL)) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
523 frequency = (uint32_t)(2 * ((HSE_VALUE / prediv2) * pll3mul));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
524 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
525 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
526 #endif /* STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
527 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
528 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
529 case RCC_PERIPHCLK_I2S3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
530 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
531 #if defined(STM32F103xE) || defined(STM32F103xG)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
532 /* SYSCLK used as source clock for I2S3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
533 frequency = HAL_RCC_GetSysClockFreq();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
534 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
535 if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
536 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
537 /* SYSCLK used as source clock for I2S3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
538 frequency = HAL_RCC_GetSysClockFreq();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
539 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
540 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
541 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
542 /* Check if PLLI2S is enabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
543 if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
544 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
545 /* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
546 prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> POSITION_VAL(RCC_CFGR2_PREDIV2)) + 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
547 pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> POSITION_VAL(RCC_CFGR2_PLL3MUL)) + 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
548 frequency = (uint32_t)(2 * ((HSE_VALUE / prediv2) * pll3mul));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
549 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
550 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
551 #endif /* STM32F103xE || STM32F103xG */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
552 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
553 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
554 #endif /* STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
555 case RCC_PERIPHCLK_RTC:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
556 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
557 /* Get RCC BDCR configuration ------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
558 temp_reg = RCC->BDCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
559
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
560 /* Check if LSE is ready if RTC clock selection is LSE */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
561 if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
562 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
563 frequency = LSE_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
564 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
565 /* Check if LSI is ready if RTC clock selection is LSI */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
566 else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
567 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
568 frequency = LSI_VALUE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
569 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
570 else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
571 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
572 frequency = HSE_VALUE / 128;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
573 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
574 /* Clock not enabled for RTC*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
575 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
576 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
577 frequency = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
578 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
579 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
580 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
581 case RCC_PERIPHCLK_ADC:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
582 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
583 frequency = HAL_RCC_GetPCLK2Freq() / (((__HAL_RCC_GET_ADC_SOURCE() >> POSITION_VAL(RCC_CFGR_ADCPRE_DIV4)) + 1) * 2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
584 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
585 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
586 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
587 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
588 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
589 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
590 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
591 return(frequency);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
592 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
593
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
594 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
595 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
596 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
597
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
598 #if defined(STM32F105xC) || defined(STM32F107xC)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
599 /** @defgroup RCCEx_Exported_Functions_Group2 PLLI2S Management function
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
600 * @brief PLLI2S Management functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
601 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
602 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
603 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
604 ##### Extended PLLI2S Management functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
605 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
606 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
607 This subsection provides a set of functions allowing to control the PLLI2S
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
608 activation or deactivation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
609 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
610 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
611 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
612
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
613 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
614 * @brief Enable PLLI2S
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
615 * @param PLLI2SInit pointer to an RCC_PLLI2SInitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
616 * contains the configuration information for the PLLI2S
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
617 * @note The PLLI2S configuration not modified if used by I2S2 or I2S3 Interface.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
618 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
619 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
620 HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
621 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
622 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
623
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
624 /* Check that PLL I2S has not been already enabled by I2S2 or I2S3*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
625 if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
626 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
627 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
628 assert_param(IS_RCC_PLLI2S_MUL(PLLI2SInit->PLLI2SMUL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
629 assert_param(IS_RCC_HSE_PREDIV2(PLLI2SInit->HSEPrediv2Value));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
630
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
631 /* Prediv2 can be written only when the PLL2 is disabled. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
632 /* Return an error only if new value is different from the programmed value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
633 if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
634 (__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
635 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
636 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
637 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
638
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
639 /* Disable the main PLLI2S. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
640 __HAL_RCC_PLLI2S_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
641
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
642 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
643 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
644
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
645 /* Wait till PLLI2S is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
646 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
647 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
648 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
649 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
650 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
651 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
652 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
653
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
654 /* Configure the HSE prediv2 factor --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
655 __HAL_RCC_HSE_PREDIV2_CONFIG(PLLI2SInit->HSEPrediv2Value);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
656
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
657
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
658 /* Configure the main PLLI2S multiplication factors. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
659 __HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SMUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
660
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
661 /* Enable the main PLLI2S. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
662 __HAL_RCC_PLLI2S_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
663
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
664 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
665 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
666
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
667 /* Wait till PLLI2S is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
668 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
669 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
670 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
671 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
672 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
673 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
674 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
675 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
676 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
677 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
678 /* PLLI2S cannot be modified as already used by I2S2 or I2S3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
679 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
680 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
681
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
682 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
683 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
684
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
685 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
686 * @brief Disable PLLI2S
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
687 * @note PLLI2S is not disabled if used by I2S2 or I2S3 Interface.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
688 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
689 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
690 HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
691 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
692 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
693
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
694 /* Disable PLL I2S as not requested by I2S2 or I2S3*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
695 if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
696 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
697 /* Disable the main PLLI2S. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
698 __HAL_RCC_PLLI2S_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
699
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
700 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
701 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
702
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
703 /* Wait till PLLI2S is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
704 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
705 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
706 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
707 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
708 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
709 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
710 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
711 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
712 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
713 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
714 /* PLLI2S is currently used by I2S2 or I2S3. Cannot be disabled.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
715 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
716 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
717
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
718 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
719 }
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 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
724
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
725 /** @defgroup RCCEx_Exported_Functions_Group3 PLL2 Management function
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
726 * @brief PLL2 Management functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
727 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
728 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
729 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
730 ##### Extended PLL2 Management functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
731 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
732 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
733 This subsection provides a set of functions allowing to control the PLL2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
734 activation or deactivation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
735 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
736 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
737 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
738
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
739 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
740 * @brief Enable PLL2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
741 * @param PLL2Init pointer to an RCC_PLL2InitTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
742 * contains the configuration information for the PLL2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
743 * @note The PLL2 configuration not modified if used indirectly as system clock.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
744 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
745 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
746 HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
747 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
748 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
749
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
750 /* 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
751 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
752 if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
753 (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
754 ((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
755 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
756 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
757 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
758 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
759 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
760 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
761 assert_param(IS_RCC_PLL2_MUL(PLL2Init->PLL2MUL));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
762 assert_param(IS_RCC_HSE_PREDIV2(PLL2Init->HSEPrediv2Value));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
763
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
764 /* Prediv2 can be written only when the PLLI2S is disabled. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
765 /* Return an error only if new value is different from the programmed value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
766 if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
767 (__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
768 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
769 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
770 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
771
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
772 /* Disable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
773 __HAL_RCC_PLL2_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
774
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
775 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
776 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
777
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
778 /* Wait till PLL2 is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
779 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
780 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
781 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
782 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
783 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
784 }
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 /* Configure the HSE prediv2 factor --------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
788 __HAL_RCC_HSE_PREDIV2_CONFIG(PLL2Init->HSEPrediv2Value);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
789
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
790 /* Configure the main PLL2 multiplication factors. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
791 __HAL_RCC_PLL2_CONFIG(PLL2Init->PLL2MUL);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
792
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
793 /* Enable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
794 __HAL_RCC_PLL2_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
795
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
796 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
797 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
798
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
799 /* Wait till PLL2 is ready */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
800 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
801 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
802 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
803 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
804 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
805 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
806 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
807 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
808
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
809 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
810 }
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 * @brief Disable PLL2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
814 * @note PLL2 is not disabled if used indirectly as system clock.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
815 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
816 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
817 HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
818 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
819 uint32_t tickstart = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
820
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
821 /* 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
822 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
823 if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
824 (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
825 ((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
826 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
827 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
828 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
829 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
830 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
831 /* Disable the main PLL2. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
832 __HAL_RCC_PLL2_DISABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
833
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
834 /* Get Start Tick*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
835 tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
836
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
837 /* Wait till PLL2 is disabled */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
838 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
839 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
840 if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
841 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
842 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
843 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
844 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
845 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
846
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
847 return HAL_OK;
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 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
851 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
852 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
853 #endif /* STM32F105xC || STM32F107xC */
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
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
859 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
860 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
861 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
862
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
863 #endif /* HAL_RCC_MODULE_ENABLED */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
864
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
865 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
866 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
867 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
868
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
869 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
870