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