mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 235:685d5f11838f 1 /**
mbed_official 235:685d5f11838f 2 ******************************************************************************
mbed_official 235:685d5f11838f 3 * @file stm32f4xx_hal_rcc_ex.c
mbed_official 235:685d5f11838f 4 * @author MCD Application Team
mbed_official 613:bc40b8d2aec4 5 * @version V1.3.2
mbed_official 613:bc40b8d2aec4 6 * @date 26-June-2015
mbed_official 235:685d5f11838f 7 * @brief Extension RCC HAL module driver.
mbed_official 235:685d5f11838f 8 * This file provides firmware functions to manage the following
mbed_official 235:685d5f11838f 9 * functionalities RCC extension peripheral:
mbed_official 235:685d5f11838f 10 * + Extended Peripheral Control functions
mbed_official 235:685d5f11838f 11 *
mbed_official 235:685d5f11838f 12 ******************************************************************************
mbed_official 235:685d5f11838f 13 * @attention
mbed_official 235:685d5f11838f 14 *
mbed_official 532:fe11edbda85c 15 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 235:685d5f11838f 16 *
mbed_official 235:685d5f11838f 17 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 235:685d5f11838f 18 * are permitted provided that the following conditions are met:
mbed_official 235:685d5f11838f 19 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 235:685d5f11838f 20 * this list of conditions and the following disclaimer.
mbed_official 235:685d5f11838f 21 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 235:685d5f11838f 22 * this list of conditions and the following disclaimer in the documentation
mbed_official 235:685d5f11838f 23 * and/or other materials provided with the distribution.
mbed_official 235:685d5f11838f 24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 235:685d5f11838f 25 * may be used to endorse or promote products derived from this software
mbed_official 235:685d5f11838f 26 * without specific prior written permission.
mbed_official 235:685d5f11838f 27 *
mbed_official 235:685d5f11838f 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 235:685d5f11838f 29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 235:685d5f11838f 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 235:685d5f11838f 31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 235:685d5f11838f 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 235:685d5f11838f 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 235:685d5f11838f 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 235:685d5f11838f 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 235:685d5f11838f 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 235:685d5f11838f 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 235:685d5f11838f 38 *
mbed_official 235:685d5f11838f 39 ******************************************************************************
mbed_official 235:685d5f11838f 40 */
mbed_official 235:685d5f11838f 41
mbed_official 235:685d5f11838f 42 /* Includes ------------------------------------------------------------------*/
mbed_official 235:685d5f11838f 43 #include "stm32f4xx_hal.h"
mbed_official 235:685d5f11838f 44
mbed_official 235:685d5f11838f 45 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 235:685d5f11838f 46 * @{
mbed_official 235:685d5f11838f 47 */
mbed_official 235:685d5f11838f 48
mbed_official 532:fe11edbda85c 49 /** @defgroup RCCEx RCCEx
mbed_official 532:fe11edbda85c 50 * @brief RCCEx HAL module driver
mbed_official 235:685d5f11838f 51 * @{
mbed_official 235:685d5f11838f 52 */
mbed_official 235:685d5f11838f 53
mbed_official 235:685d5f11838f 54 #ifdef HAL_RCC_MODULE_ENABLED
mbed_official 235:685d5f11838f 55
mbed_official 235:685d5f11838f 56 /* Private typedef -----------------------------------------------------------*/
mbed_official 235:685d5f11838f 57 /* Private define ------------------------------------------------------------*/
mbed_official 532:fe11edbda85c 58 /** @addtogroup RCCEx_Private_Constants
mbed_official 532:fe11edbda85c 59 * @{
mbed_official 532:fe11edbda85c 60 */
mbed_official 532:fe11edbda85c 61 /**
mbed_official 532:fe11edbda85c 62 * @}
mbed_official 532:fe11edbda85c 63 */
mbed_official 235:685d5f11838f 64 /* Private macro -------------------------------------------------------------*/
mbed_official 235:685d5f11838f 65 /* Private variables ---------------------------------------------------------*/
mbed_official 235:685d5f11838f 66 /* Private function prototypes -----------------------------------------------*/
mbed_official 235:685d5f11838f 67 /* Private functions ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 68 /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
mbed_official 532:fe11edbda85c 69 * @{
mbed_official 235:685d5f11838f 70 */
mbed_official 235:685d5f11838f 71
mbed_official 532:fe11edbda85c 72 /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
mbed_official 235:685d5f11838f 73 * @brief Extended Peripheral Control functions
mbed_official 235:685d5f11838f 74 *
mbed_official 235:685d5f11838f 75 @verbatim
mbed_official 235:685d5f11838f 76 ===============================================================================
mbed_official 235:685d5f11838f 77 ##### Extended Peripheral Control functions #####
mbed_official 235:685d5f11838f 78 ===============================================================================
mbed_official 235:685d5f11838f 79 [..]
mbed_official 235:685d5f11838f 80 This subsection provides a set of functions allowing to control the RCC Clocks
mbed_official 235:685d5f11838f 81 frequencies.
mbed_official 235:685d5f11838f 82 [..]
mbed_official 235:685d5f11838f 83 (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
mbed_official 235:685d5f11838f 84 select the RTC clock source; in this case the Backup domain will be reset in
mbed_official 235:685d5f11838f 85 order to modify the RTC Clock source, as consequence RTC registers (including
mbed_official 235:685d5f11838f 86 the backup registers) and RCC_BDCR register are set to their reset values.
mbed_official 235:685d5f11838f 87
mbed_official 235:685d5f11838f 88 @endverbatim
mbed_official 235:685d5f11838f 89 * @{
mbed_official 235:685d5f11838f 90 */
mbed_official 532:fe11edbda85c 91 #if defined(STM32F446xx)
mbed_official 235:685d5f11838f 92 /**
mbed_official 235:685d5f11838f 93 * @brief Initializes the RCC extended peripherals clocks according to the specified
mbed_official 235:685d5f11838f 94 * parameters in the RCC_PeriphCLKInitTypeDef.
mbed_official 235:685d5f11838f 95 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 235:685d5f11838f 96 * contains the configuration information for the Extended Peripherals
mbed_official 235:685d5f11838f 97 * clocks(I2S, SAI, LTDC RTC and TIM).
mbed_official 235:685d5f11838f 98 *
mbed_official 235:685d5f11838f 99 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
mbed_official 235:685d5f11838f 100 * the RTC clock source; in this case the Backup domain will be reset in
mbed_official 235:685d5f11838f 101 * order to modify the RTC Clock source, as consequence RTC registers (including
mbed_official 235:685d5f11838f 102 * the backup registers) and RCC_BDCR register are set to their reset values.
mbed_official 235:685d5f11838f 103 *
mbed_official 235:685d5f11838f 104 * @retval HAL status
mbed_official 235:685d5f11838f 105 */
mbed_official 235:685d5f11838f 106 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 235:685d5f11838f 107 {
mbed_official 235:685d5f11838f 108 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 109 uint32_t tmpreg1 = 0;
mbed_official 532:fe11edbda85c 110 uint32_t plli2sp = 0;
mbed_official 532:fe11edbda85c 111 uint32_t plli2sq = 0;
mbed_official 532:fe11edbda85c 112 uint32_t plli2sr = 0;
mbed_official 532:fe11edbda85c 113 uint32_t pllsaip = 0;
mbed_official 532:fe11edbda85c 114 uint32_t pllsaiq = 0;
mbed_official 532:fe11edbda85c 115 uint32_t plli2sused = 0;
mbed_official 532:fe11edbda85c 116 uint32_t pllsaiused = 0;
mbed_official 532:fe11edbda85c 117
mbed_official 532:fe11edbda85c 118 /* Check the peripheral clock selection parameters */
mbed_official 532:fe11edbda85c 119 assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
mbed_official 532:fe11edbda85c 120
mbed_official 532:fe11edbda85c 121 /*----------------------------------- I2S APB1 configuration ----------------------------------*/
mbed_official 532:fe11edbda85c 122 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S_APB1) == (RCC_PERIPHCLK_I2S_APB1))
mbed_official 532:fe11edbda85c 123 {
mbed_official 532:fe11edbda85c 124 /* Check the parameters */
mbed_official 532:fe11edbda85c 125 assert_param(IS_RCC_I2SAPB1CLKSOURCE(PeriphClkInit->I2sApb1ClockSelection));
mbed_official 532:fe11edbda85c 126
mbed_official 532:fe11edbda85c 127 /* Configure I2S Clock source */
mbed_official 532:fe11edbda85c 128 __HAL_RCC_I2S_APB1_CONFIG(PeriphClkInit->I2sApb1ClockSelection);
mbed_official 532:fe11edbda85c 129 /* Enable the PLLI2S when it's used as clock source for I2S */
mbed_official 532:fe11edbda85c 130 if(PeriphClkInit->I2sApb1ClockSelection == RCC_I2SAPB1CLKSOURCE_PLLI2S)
mbed_official 532:fe11edbda85c 131 {
mbed_official 532:fe11edbda85c 132 plli2sused = 1;
mbed_official 532:fe11edbda85c 133 }
mbed_official 532:fe11edbda85c 134 }
mbed_official 532:fe11edbda85c 135
mbed_official 532:fe11edbda85c 136 /*----------------------------------- I2S APB2 configuration -----------------------------------*/
mbed_official 532:fe11edbda85c 137 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S_APB2) == (RCC_PERIPHCLK_I2S_APB2))
mbed_official 532:fe11edbda85c 138 {
mbed_official 532:fe11edbda85c 139 /* Check the parameters */
mbed_official 532:fe11edbda85c 140 assert_param(IS_RCC_I2SAPB2CLKSOURCE(PeriphClkInit->I2sApb2ClockSelection));
mbed_official 532:fe11edbda85c 141
mbed_official 532:fe11edbda85c 142 /* Configure I2S Clock source */
mbed_official 532:fe11edbda85c 143 __HAL_RCC_I2S_APB2_CONFIG(PeriphClkInit->I2sApb2ClockSelection);
mbed_official 532:fe11edbda85c 144 /* Enable the PLLI2S when it's used as clock source for I2S */
mbed_official 532:fe11edbda85c 145 if(PeriphClkInit->I2sApb2ClockSelection == RCC_I2SAPB2CLKSOURCE_PLLI2S)
mbed_official 532:fe11edbda85c 146 {
mbed_official 532:fe11edbda85c 147 plli2sused = 1;
mbed_official 532:fe11edbda85c 148 }
mbed_official 532:fe11edbda85c 149 }
mbed_official 532:fe11edbda85c 150
mbed_official 532:fe11edbda85c 151 /*------------------------------------ SAI1 configuration --------------------------------------*/
mbed_official 532:fe11edbda85c 152 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == (RCC_PERIPHCLK_SAI1))
mbed_official 532:fe11edbda85c 153 {
mbed_official 532:fe11edbda85c 154 /* Check the parameters */
mbed_official 532:fe11edbda85c 155 assert_param(IS_RCC_SAI1CLKSOURCE(PeriphClkInit->Sai1ClockSelection));
mbed_official 532:fe11edbda85c 156
mbed_official 532:fe11edbda85c 157 /* Configure SAI1 Clock source */
mbed_official 532:fe11edbda85c 158 __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
mbed_official 532:fe11edbda85c 159 /* Enable the PLLI2S when it's used as clock source for SAI */
mbed_official 532:fe11edbda85c 160 if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)
mbed_official 532:fe11edbda85c 161 {
mbed_official 532:fe11edbda85c 162 plli2sused = 1;
mbed_official 532:fe11edbda85c 163 }
mbed_official 532:fe11edbda85c 164 /* Enable the PLLSAI when it's used as clock source for SAI */
mbed_official 532:fe11edbda85c 165 if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)
mbed_official 532:fe11edbda85c 166 {
mbed_official 532:fe11edbda85c 167 pllsaiused = 1;
mbed_official 532:fe11edbda85c 168 }
mbed_official 532:fe11edbda85c 169 }
mbed_official 532:fe11edbda85c 170
mbed_official 532:fe11edbda85c 171 /*------------------------------------ SAI2 configuration --------------------------------------*/
mbed_official 532:fe11edbda85c 172 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == (RCC_PERIPHCLK_SAI2))
mbed_official 532:fe11edbda85c 173 {
mbed_official 532:fe11edbda85c 174 /* Check the parameters */
mbed_official 532:fe11edbda85c 175 assert_param(IS_RCC_SAI2CLKSOURCE(PeriphClkInit->Sai2ClockSelection));
mbed_official 532:fe11edbda85c 176
mbed_official 532:fe11edbda85c 177 /* Configure SAI2 Clock source */
mbed_official 532:fe11edbda85c 178 __HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection);
mbed_official 532:fe11edbda85c 179
mbed_official 532:fe11edbda85c 180 /* Enable the PLLI2S when it's used as clock source for SAI */
mbed_official 532:fe11edbda85c 181 if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)
mbed_official 532:fe11edbda85c 182 {
mbed_official 532:fe11edbda85c 183 plli2sused = 1;
mbed_official 532:fe11edbda85c 184 }
mbed_official 532:fe11edbda85c 185 /* Enable the PLLSAI when it's used as clock source for SAI */
mbed_official 532:fe11edbda85c 186 if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)
mbed_official 532:fe11edbda85c 187 {
mbed_official 532:fe11edbda85c 188 pllsaiused = 1;
mbed_official 532:fe11edbda85c 189 }
mbed_official 532:fe11edbda85c 190 }
mbed_official 532:fe11edbda85c 191
mbed_official 532:fe11edbda85c 192 /*------------------------------------ RTC configuration --------------------------------------*/
mbed_official 532:fe11edbda85c 193 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
mbed_official 613:bc40b8d2aec4 194 {
mbed_official 532:fe11edbda85c 195 /* Enable Power Clock*/
mbed_official 532:fe11edbda85c 196 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 532:fe11edbda85c 197
mbed_official 532:fe11edbda85c 198 /* Enable write access to Backup domain */
mbed_official 532:fe11edbda85c 199 PWR->CR |= PWR_CR_DBP;
mbed_official 532:fe11edbda85c 200
mbed_official 532:fe11edbda85c 201 /* Get tick */
mbed_official 532:fe11edbda85c 202 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 203
mbed_official 532:fe11edbda85c 204 while((PWR->CR & PWR_CR_DBP) == RESET)
mbed_official 532:fe11edbda85c 205 {
mbed_official 532:fe11edbda85c 206 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 207 {
mbed_official 532:fe11edbda85c 208 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 209 }
mbed_official 532:fe11edbda85c 210 }
mbed_official 532:fe11edbda85c 211 /* Reset the Backup domain only if the RTC Clock source selction is modified */
mbed_official 532:fe11edbda85c 212 if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))
mbed_official 613:bc40b8d2aec4 213 {
mbed_official 532:fe11edbda85c 214 /* Store the content of BDCR register before the reset of Backup Domain */
mbed_official 532:fe11edbda85c 215 tmpreg1 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
mbed_official 532:fe11edbda85c 216 /* RTC Clock selection can be changed only if the Backup Domain is reset */
mbed_official 532:fe11edbda85c 217 __HAL_RCC_BACKUPRESET_FORCE();
mbed_official 532:fe11edbda85c 218 __HAL_RCC_BACKUPRESET_RELEASE();
mbed_official 532:fe11edbda85c 219 /* Restore the Content of BDCR register */
mbed_official 532:fe11edbda85c 220 RCC->BDCR = tmpreg1;
mbed_official 613:bc40b8d2aec4 221
mbed_official 613:bc40b8d2aec4 222 /* Wait for LSERDY if LSE was enabled */
mbed_official 613:bc40b8d2aec4 223 if(HAL_IS_BIT_SET(tmpreg1, RCC_BDCR_LSERDY))
mbed_official 613:bc40b8d2aec4 224 {
mbed_official 613:bc40b8d2aec4 225 /* Get tick */
mbed_official 613:bc40b8d2aec4 226 tickstart = HAL_GetTick();
mbed_official 613:bc40b8d2aec4 227
mbed_official 613:bc40b8d2aec4 228 /* Wait till LSE is ready */
mbed_official 613:bc40b8d2aec4 229 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
mbed_official 613:bc40b8d2aec4 230 {
mbed_official 613:bc40b8d2aec4 231 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 613:bc40b8d2aec4 232 {
mbed_official 613:bc40b8d2aec4 233 return HAL_TIMEOUT;
mbed_official 613:bc40b8d2aec4 234 }
mbed_official 613:bc40b8d2aec4 235 }
mbed_official 613:bc40b8d2aec4 236 }
mbed_official 613:bc40b8d2aec4 237 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
mbed_official 532:fe11edbda85c 238 }
mbed_official 532:fe11edbda85c 239 }
mbed_official 532:fe11edbda85c 240
mbed_official 532:fe11edbda85c 241 /*------------------------------------ TIM configuration --------------------------------------*/
mbed_official 532:fe11edbda85c 242 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM))
mbed_official 532:fe11edbda85c 243 {
mbed_official 532:fe11edbda85c 244 /* Configure Timer Prescaler */
mbed_official 532:fe11edbda85c 245 __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
mbed_official 532:fe11edbda85c 246 }
mbed_official 532:fe11edbda85c 247
mbed_official 532:fe11edbda85c 248 /*------------------------------------- FMPI2C1 Configuration ----------------------------------*/
mbed_official 532:fe11edbda85c 249 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_FMPI2C1) == RCC_PERIPHCLK_FMPI2C1)
mbed_official 532:fe11edbda85c 250 {
mbed_official 532:fe11edbda85c 251 /* Check the parameters */
mbed_official 532:fe11edbda85c 252 assert_param(IS_RCC_FMPI2C1CLKSOURCE(PeriphClkInit->Fmpi2c1ClockSelection));
mbed_official 532:fe11edbda85c 253
mbed_official 532:fe11edbda85c 254 /* Configure the FMPI2C1 clock source */
mbed_official 532:fe11edbda85c 255 __HAL_RCC_FMPI2C1_CONFIG(PeriphClkInit->Fmpi2c1ClockSelection);
mbed_official 532:fe11edbda85c 256 }
mbed_official 532:fe11edbda85c 257
mbed_official 532:fe11edbda85c 258 /*--------------------------------------- CEC Configuration -----------------------------------*/
mbed_official 532:fe11edbda85c 259 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC)
mbed_official 532:fe11edbda85c 260 {
mbed_official 532:fe11edbda85c 261 /* Check the parameters */
mbed_official 532:fe11edbda85c 262 assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection));
mbed_official 532:fe11edbda85c 263
mbed_official 532:fe11edbda85c 264 /* Configure the CEC clock source */
mbed_official 532:fe11edbda85c 265 __HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection);
mbed_official 532:fe11edbda85c 266 }
mbed_official 532:fe11edbda85c 267
mbed_official 532:fe11edbda85c 268 /*-------------------------------------- CK48 Configuration -----------------------------------*/
mbed_official 532:fe11edbda85c 269 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CK48) == RCC_PERIPHCLK_CK48)
mbed_official 532:fe11edbda85c 270 {
mbed_official 532:fe11edbda85c 271 /* Check the parameters */
mbed_official 532:fe11edbda85c 272 assert_param(IS_RCC_CK48CLKSOURCE(PeriphClkInit->Clk48ClockSelection));
mbed_official 532:fe11edbda85c 273
mbed_official 532:fe11edbda85c 274 /* Configure the SDIO clock source */
mbed_official 532:fe11edbda85c 275 __HAL_RCC_CLK48_CONFIG(PeriphClkInit->Clk48ClockSelection);
mbed_official 532:fe11edbda85c 276
mbed_official 532:fe11edbda85c 277 /* Enable the PLLSAI when it's used as clock source for CK48 */
mbed_official 532:fe11edbda85c 278 if(PeriphClkInit->Clk48ClockSelection == RCC_CK48CLKSOURCE_PLLSAIP)
mbed_official 532:fe11edbda85c 279 {
mbed_official 532:fe11edbda85c 280 pllsaiused = 1;
mbed_official 532:fe11edbda85c 281 }
mbed_official 532:fe11edbda85c 282 }
mbed_official 532:fe11edbda85c 283
mbed_official 532:fe11edbda85c 284 /*------------------------------------- SDIO Configuration ------------------------------------*/
mbed_official 532:fe11edbda85c 285 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDIO) == RCC_PERIPHCLK_SDIO)
mbed_official 532:fe11edbda85c 286 {
mbed_official 532:fe11edbda85c 287 /* Check the parameters */
mbed_official 532:fe11edbda85c 288 assert_param(IS_RCC_SDIOCLKSOURCE(PeriphClkInit->SdioClockSelection));
mbed_official 532:fe11edbda85c 289
mbed_official 532:fe11edbda85c 290 /* Configure the SDIO clock source */
mbed_official 532:fe11edbda85c 291 __HAL_RCC_SDIO_CONFIG(PeriphClkInit->SdioClockSelection);
mbed_official 532:fe11edbda85c 292 }
mbed_official 532:fe11edbda85c 293
mbed_official 532:fe11edbda85c 294 /*------------------------------------- SPDIFRX Configuration --------------*/
mbed_official 532:fe11edbda85c 295 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
mbed_official 532:fe11edbda85c 296 {
mbed_official 532:fe11edbda85c 297 /* Check the parameters */
mbed_official 532:fe11edbda85c 298 assert_param(IS_RCC_SPDIFRXCLKSOURCE(PeriphClkInit->SpdifClockSelection));
mbed_official 532:fe11edbda85c 299
mbed_official 532:fe11edbda85c 300 /* Configure the SPDIFRX clock source */
mbed_official 532:fe11edbda85c 301 __HAL_RCC_SPDIFRX_CONFIG(PeriphClkInit->SpdifClockSelection);
mbed_official 532:fe11edbda85c 302 /* Enable the PLLI2S when it's used as clock source for SPDIFRX */
mbed_official 532:fe11edbda85c 303 if(PeriphClkInit->SpdifClockSelection == RCC_SPDIFRXCLKSOURCE_PLLI2SP)
mbed_official 532:fe11edbda85c 304 {
mbed_official 532:fe11edbda85c 305 plli2sused = 1;
mbed_official 532:fe11edbda85c 306 }
mbed_official 532:fe11edbda85c 307 }
mbed_official 532:fe11edbda85c 308
mbed_official 532:fe11edbda85c 309 /*-------------------------------------- PLLI2S Configuration --------------*/
mbed_official 532:fe11edbda85c 310 /* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2, I2S on APB1,
mbed_official 532:fe11edbda85c 311 I2S on APB2 or SPDIFRX */
mbed_official 532:fe11edbda85c 312 if((plli2sused == 1) || (PeriphClkInit->PeriphClockSelection == RCC_PERIPHCLK_PLLI2S))
mbed_official 532:fe11edbda85c 313 {
mbed_official 532:fe11edbda85c 314 /* Disable the PLLI2S */
mbed_official 532:fe11edbda85c 315 __HAL_RCC_PLLI2S_DISABLE();
mbed_official 532:fe11edbda85c 316 /* Get tick */
mbed_official 532:fe11edbda85c 317 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 318 /* Wait till PLLI2S is disabled */
mbed_official 532:fe11edbda85c 319 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
mbed_official 532:fe11edbda85c 320 {
mbed_official 532:fe11edbda85c 321 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 322 {
mbed_official 532:fe11edbda85c 323 /* return in case of Timeout detected */
mbed_official 532:fe11edbda85c 324 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 325 }
mbed_official 532:fe11edbda85c 326 }
mbed_official 532:fe11edbda85c 327
mbed_official 532:fe11edbda85c 328 /* check for common PLLI2S Parameters */
mbed_official 532:fe11edbda85c 329 assert_param(IS_RCC_PLLI2SM_VALUE(PeriphClkInit->PLLI2S.PLLI2SM));
mbed_official 532:fe11edbda85c 330 assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
mbed_official 532:fe11edbda85c 331
mbed_official 532:fe11edbda85c 332 /*----------------- In Case of PLLI2S is selected as source clock for I2S -------------------*/
mbed_official 532:fe11edbda85c 333 if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S_APB1) == RCC_PERIPHCLK_I2S_APB1) && (PeriphClkInit->I2sApb1ClockSelection == RCC_I2SAPB1CLKSOURCE_PLLI2S)) ||
mbed_official 532:fe11edbda85c 334 ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S_APB2) == RCC_PERIPHCLK_I2S_APB2) && (PeriphClkInit->I2sApb2ClockSelection == RCC_I2SAPB2CLKSOURCE_PLLI2S)))
mbed_official 532:fe11edbda85c 335 {
mbed_official 532:fe11edbda85c 336 /* check for Parameters */
mbed_official 532:fe11edbda85c 337 assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
mbed_official 532:fe11edbda85c 338
mbed_official 532:fe11edbda85c 339 /* Read PLLI2SP/PLLI2SQ value from PLLI2SCFGR register (this value is not needed for I2S configuration) */
mbed_official 532:fe11edbda85c 340 plli2sp = ((((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)) + 1) << 1);
mbed_official 532:fe11edbda85c 341 plli2sq = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
mbed_official 532:fe11edbda85c 342 /* Configure the PLLI2S division factors */
mbed_official 532:fe11edbda85c 343 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLI2SM) */
mbed_official 532:fe11edbda85c 344 /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
mbed_official 532:fe11edbda85c 345 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SM, PeriphClkInit->PLLI2S.PLLI2SN , plli2sp, plli2sq, PeriphClkInit->PLLI2S.PLLI2SR);
mbed_official 532:fe11edbda85c 346 }
mbed_official 532:fe11edbda85c 347
mbed_official 532:fe11edbda85c 348 /*----------------- In Case of PLLI2S is selected as source clock for SAI -------------------*/
mbed_official 532:fe11edbda85c 349 if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)) ||
mbed_official 532:fe11edbda85c 350 ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)))
mbed_official 532:fe11edbda85c 351 {
mbed_official 532:fe11edbda85c 352 /* Check for PLLI2S Parameters */
mbed_official 532:fe11edbda85c 353 assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
mbed_official 532:fe11edbda85c 354 /* Check for PLLI2S/DIVQ parameters */
mbed_official 532:fe11edbda85c 355 assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ));
mbed_official 532:fe11edbda85c 356
mbed_official 532:fe11edbda85c 357 /* Read PLLI2SP/PLLI2SR value from PLLI2SCFGR register (this value is not needed for SAI configuration) */
mbed_official 532:fe11edbda85c 358 plli2sp = ((((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)) + 1) << 1);
mbed_official 532:fe11edbda85c 359 plli2sr = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 532:fe11edbda85c 360 /* Configure the PLLI2S division factors */
mbed_official 532:fe11edbda85c 361 /* PLLI2S_VCO Input = PLL_SOURCE/PLLI2SM */
mbed_official 532:fe11edbda85c 362 /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
mbed_official 532:fe11edbda85c 363 /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
mbed_official 532:fe11edbda85c 364 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SM, PeriphClkInit->PLLI2S.PLLI2SN , plli2sp, PeriphClkInit->PLLI2S.PLLI2SQ, plli2sr);
mbed_official 532:fe11edbda85c 365
mbed_official 532:fe11edbda85c 366 /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
mbed_official 532:fe11edbda85c 367 __HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ);
mbed_official 532:fe11edbda85c 368 }
mbed_official 532:fe11edbda85c 369
mbed_official 532:fe11edbda85c 370 /*----------------- In Case of PLLI2S is selected as source clock for SPDIFRX -------------------*/
mbed_official 532:fe11edbda85c 371 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX) && (PeriphClkInit->SpdifClockSelection == RCC_SPDIFRXCLKSOURCE_PLLI2SP))
mbed_official 532:fe11edbda85c 372 {
mbed_official 532:fe11edbda85c 373 /* check for Parameters */
mbed_official 532:fe11edbda85c 374 assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
mbed_official 532:fe11edbda85c 375 /* Read PLLI2SR value from PLLI2SCFGR register (this value is not need for SAI configuration) */
mbed_official 532:fe11edbda85c 376 plli2sq = ((((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)) + 1) << 1);
mbed_official 532:fe11edbda85c 377 plli2sr = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 532:fe11edbda85c 378 /* Configure the PLLI2S division factors */
mbed_official 532:fe11edbda85c 379 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLI2SM) */
mbed_official 532:fe11edbda85c 380 /* SPDIFRXCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */
mbed_official 532:fe11edbda85c 381 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SM, PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, plli2sq, plli2sr);
mbed_official 532:fe11edbda85c 382 }
mbed_official 532:fe11edbda85c 383
mbed_official 532:fe11edbda85c 384 /*----------------- In Case of PLLI2S is just selected -----------------*/
mbed_official 532:fe11edbda85c 385 if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S)
mbed_official 532:fe11edbda85c 386 {
mbed_official 532:fe11edbda85c 387 /* Check for Parameters */
mbed_official 532:fe11edbda85c 388 assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
mbed_official 532:fe11edbda85c 389 assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
mbed_official 613:bc40b8d2aec4 390 assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
mbed_official 532:fe11edbda85c 391
mbed_official 532:fe11edbda85c 392 /* Configure the PLLI2S division factors */
mbed_official 532:fe11edbda85c 393 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLI2SM) */
mbed_official 532:fe11edbda85c 394 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SM, PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, PeriphClkInit->PLLI2S.PLLI2SQ, PeriphClkInit->PLLI2S.PLLI2SR);
mbed_official 532:fe11edbda85c 395 }
mbed_official 532:fe11edbda85c 396
mbed_official 532:fe11edbda85c 397 /* Enable the PLLI2S */
mbed_official 532:fe11edbda85c 398 __HAL_RCC_PLLI2S_ENABLE();
mbed_official 532:fe11edbda85c 399 /* Get tick */
mbed_official 532:fe11edbda85c 400 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 401 /* Wait till PLLI2S is ready */
mbed_official 532:fe11edbda85c 402 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
mbed_official 532:fe11edbda85c 403 {
mbed_official 532:fe11edbda85c 404 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 405 {
mbed_official 532:fe11edbda85c 406 /* return in case of Timeout detected */
mbed_official 532:fe11edbda85c 407 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 408 }
mbed_official 532:fe11edbda85c 409 }
mbed_official 532:fe11edbda85c 410 }
mbed_official 532:fe11edbda85c 411 /*-------------------------------------- PLLSAI Configuration ---------------------------------*/
mbed_official 532:fe11edbda85c 412 /* PLLSAI is configured when a peripheral will use it as source clock : SAI1, SAI2, CK48 or SDIO */
mbed_official 532:fe11edbda85c 413 if(pllsaiused == 1)
mbed_official 532:fe11edbda85c 414 {
mbed_official 532:fe11edbda85c 415 /* Disable PLLSAI Clock */
mbed_official 532:fe11edbda85c 416 __HAL_RCC_PLLSAI_DISABLE();
mbed_official 532:fe11edbda85c 417 /* Get tick */
mbed_official 532:fe11edbda85c 418 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 419 /* Wait till PLLSAI is disabled */
mbed_official 532:fe11edbda85c 420 while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
mbed_official 532:fe11edbda85c 421 {
mbed_official 532:fe11edbda85c 422 if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 423 {
mbed_official 532:fe11edbda85c 424 /* return in case of Timeout detected */
mbed_official 532:fe11edbda85c 425 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 426 }
mbed_official 532:fe11edbda85c 427 }
mbed_official 532:fe11edbda85c 428
mbed_official 532:fe11edbda85c 429 /* Check the PLLSAI division factors */
mbed_official 532:fe11edbda85c 430 assert_param(IS_RCC_PLLSAIM_VALUE(PeriphClkInit->PLLSAI.PLLSAIM));
mbed_official 532:fe11edbda85c 431 assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN));
mbed_official 532:fe11edbda85c 432
mbed_official 532:fe11edbda85c 433 /*----------------- In Case of PLLSAI is selected as source clock for SAI -------------------*/
mbed_official 532:fe11edbda85c 434 if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)) ||
mbed_official 532:fe11edbda85c 435 ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)))
mbed_official 532:fe11edbda85c 436 {
mbed_official 532:fe11edbda85c 437 /* check for PLLSAIQ Parameter */
mbed_official 532:fe11edbda85c 438 assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ));
mbed_official 532:fe11edbda85c 439 /* check for PLLSAI/DIVQ Parameter */
mbed_official 532:fe11edbda85c 440 assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ));
mbed_official 532:fe11edbda85c 441
mbed_official 532:fe11edbda85c 442 /* Read PLLSAIP value from PLLSAICFGR register (this value is not needed for SAI configuration) */
mbed_official 532:fe11edbda85c 443 pllsaip = ((((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP)) + 1) << 1);
mbed_official 532:fe11edbda85c 444 /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
mbed_official 532:fe11edbda85c 445 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
mbed_official 532:fe11edbda85c 446 /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
mbed_official 532:fe11edbda85c 447 __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIM, PeriphClkInit->PLLSAI.PLLSAIN , pllsaip, PeriphClkInit->PLLSAI.PLLSAIQ, 0);
mbed_official 532:fe11edbda85c 448
mbed_official 532:fe11edbda85c 449 /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
mbed_official 532:fe11edbda85c 450 __HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ);
mbed_official 532:fe11edbda85c 451 }
mbed_official 532:fe11edbda85c 452
mbed_official 532:fe11edbda85c 453 /*----------------- In Case of PLLSAI is selected as source clock for CK48 -------------------*/
mbed_official 532:fe11edbda85c 454 /* In Case of PLLI2S is selected as source clock for CK48 */
mbed_official 532:fe11edbda85c 455 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CK48) == RCC_PERIPHCLK_CK48) && (PeriphClkInit->Clk48ClockSelection == RCC_CK48CLKSOURCE_PLLSAIP))
mbed_official 532:fe11edbda85c 456 {
mbed_official 532:fe11edbda85c 457 /* check for Parameters */
mbed_official 532:fe11edbda85c 458 assert_param(IS_RCC_PLLSAIP_VALUE(PeriphClkInit->PLLSAI.PLLSAIP));
mbed_official 532:fe11edbda85c 459 /* Read PLLSAIQ value from PLLI2SCFGR register (this value is not need for SAI configuration) */
mbed_official 532:fe11edbda85c 460 pllsaiq = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
mbed_official 532:fe11edbda85c 461 /* Configure the PLLSAI division factors */
mbed_official 532:fe11edbda85c 462 /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) × (PLLI2SN/PLLSAIM) */
mbed_official 532:fe11edbda85c 463 /* 48CLK = f(PLLSAI clock output) = f(VCO clock) / PLLSAIP */
mbed_official 532:fe11edbda85c 464 __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIM, PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIP, pllsaiq, 0);
mbed_official 532:fe11edbda85c 465 }
mbed_official 532:fe11edbda85c 466
mbed_official 532:fe11edbda85c 467 /* Enable PLLSAI Clock */
mbed_official 532:fe11edbda85c 468 __HAL_RCC_PLLSAI_ENABLE();
mbed_official 532:fe11edbda85c 469 /* Get tick */
mbed_official 532:fe11edbda85c 470 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 471 /* Wait till PLLSAI is ready */
mbed_official 532:fe11edbda85c 472 while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
mbed_official 532:fe11edbda85c 473 {
mbed_official 532:fe11edbda85c 474 if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 475 {
mbed_official 532:fe11edbda85c 476 /* return in case of Timeout detected */
mbed_official 532:fe11edbda85c 477 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 478 }
mbed_official 532:fe11edbda85c 479 }
mbed_official 532:fe11edbda85c 480 }
mbed_official 532:fe11edbda85c 481 return HAL_OK;
mbed_official 532:fe11edbda85c 482 }
mbed_official 532:fe11edbda85c 483
mbed_official 532:fe11edbda85c 484 /**
mbed_official 532:fe11edbda85c 485 * @brief Get the RCC_PeriphCLKInitTypeDef according to the internal
mbed_official 532:fe11edbda85c 486 * RCC configuration registers.
mbed_official 532:fe11edbda85c 487 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 532:fe11edbda85c 488 * will be configured.
mbed_official 532:fe11edbda85c 489 * @retval None
mbed_official 532:fe11edbda85c 490 */
mbed_official 532:fe11edbda85c 491 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 532:fe11edbda85c 492 {
mbed_official 532:fe11edbda85c 493 uint32_t tempreg;
mbed_official 532:fe11edbda85c 494
mbed_official 532:fe11edbda85c 495 /* Set all possible values for the extended clock type parameter------------*/
mbed_official 532:fe11edbda85c 496 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_I2S_APB2 |\
mbed_official 532:fe11edbda85c 497 RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\
mbed_official 532:fe11edbda85c 498 RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\
mbed_official 532:fe11edbda85c 499 RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_FMPI2C1 |\
mbed_official 532:fe11edbda85c 500 RCC_PERIPHCLK_CK48 | RCC_PERIPHCLK_SDIO |\
mbed_official 532:fe11edbda85c 501 RCC_PERIPHCLK_SPDIFRX;
mbed_official 532:fe11edbda85c 502
mbed_official 532:fe11edbda85c 503 /* Get the PLLI2S Clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 504 PeriphClkInit->PLLI2S.PLLI2SM = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SM));
mbed_official 532:fe11edbda85c 505 PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN));
mbed_official 532:fe11edbda85c 506 PeriphClkInit->PLLI2S.PLLI2SP = (uint32_t)((((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)) + 1) << 1);
mbed_official 532:fe11edbda85c 507 PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
mbed_official 532:fe11edbda85c 508 PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 532:fe11edbda85c 509 /* Get the PLLSAI Clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 510 PeriphClkInit->PLLSAI.PLLSAIM = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIM) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIM));
mbed_official 532:fe11edbda85c 511 PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIN));
mbed_official 532:fe11edbda85c 512 PeriphClkInit->PLLSAI.PLLSAIP = (uint32_t)((((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP)) + 1) << 1);
mbed_official 532:fe11edbda85c 513 PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
mbed_official 532:fe11edbda85c 514 /* Get the PLLSAI/PLLI2S division factors -------------------------------------------*/
mbed_official 532:fe11edbda85c 515 PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) >> POSITION_VAL(RCC_DCKCFGR_PLLI2SDIVQ));
mbed_official 532:fe11edbda85c 516 PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> POSITION_VAL(RCC_DCKCFGR_PLLSAIDIVQ));
mbed_official 532:fe11edbda85c 517
mbed_official 532:fe11edbda85c 518 /* Get the SAI1 clock configuration ----------------------------------------------*/
mbed_official 532:fe11edbda85c 519 PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
mbed_official 532:fe11edbda85c 520
mbed_official 532:fe11edbda85c 521 /* Get the SAI2 clock configuration ----------------------------------------------*/
mbed_official 532:fe11edbda85c 522 PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE();
mbed_official 532:fe11edbda85c 523
mbed_official 532:fe11edbda85c 524 /* Get the I2S APB1 clock configuration ------------------------------------------*/
mbed_official 532:fe11edbda85c 525 PeriphClkInit->I2sApb1ClockSelection = __HAL_RCC_GET_I2S_APB1_SOURCE();
mbed_official 532:fe11edbda85c 526
mbed_official 532:fe11edbda85c 527 /* Get the I2S APB2 clock configuration ------------------------------------------*/
mbed_official 532:fe11edbda85c 528 PeriphClkInit->I2sApb2ClockSelection = __HAL_RCC_GET_I2S_APB2_SOURCE();
mbed_official 532:fe11edbda85c 529
mbed_official 532:fe11edbda85c 530 /* Get the RTC Clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 531 tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
mbed_official 532:fe11edbda85c 532 PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
mbed_official 532:fe11edbda85c 533
mbed_official 532:fe11edbda85c 534 /* Get the CEC clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 535 PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE();
mbed_official 532:fe11edbda85c 536
mbed_official 532:fe11edbda85c 537 /* Get the FMPI2C1 clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 538 PeriphClkInit->Fmpi2c1ClockSelection = __HAL_RCC_GET_FMPI2C1_SOURCE();
mbed_official 532:fe11edbda85c 539
mbed_official 532:fe11edbda85c 540 /* Get the CK48 clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 541 PeriphClkInit->Clk48ClockSelection = __HAL_RCC_GET_CLK48_SOURCE();
mbed_official 532:fe11edbda85c 542
mbed_official 532:fe11edbda85c 543 /* Get the SDIO clock configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 544 PeriphClkInit->SdioClockSelection = __HAL_RCC_GET_SDIO_SOURCE();
mbed_official 532:fe11edbda85c 545
mbed_official 532:fe11edbda85c 546 /* Get the SPDIFRX clock configuration ----------------------------------------------*/
mbed_official 532:fe11edbda85c 547 PeriphClkInit->SpdifClockSelection = __HAL_RCC_GET_SPDIFRX_SOURCE();
mbed_official 532:fe11edbda85c 548
mbed_official 532:fe11edbda85c 549 /* Get the TIM Prescaler configuration --------------------------------------------*/
mbed_official 532:fe11edbda85c 550 if ((RCC->DCKCFGR & RCC_DCKCFGR_TIMPRE) == RESET)
mbed_official 532:fe11edbda85c 551 {
mbed_official 532:fe11edbda85c 552 PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
mbed_official 532:fe11edbda85c 553 }
mbed_official 532:fe11edbda85c 554 else
mbed_official 532:fe11edbda85c 555 {
mbed_official 532:fe11edbda85c 556 PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
mbed_official 532:fe11edbda85c 557 }
mbed_official 532:fe11edbda85c 558 }
mbed_official 532:fe11edbda85c 559
mbed_official 532:fe11edbda85c 560 /**
mbed_official 532:fe11edbda85c 561 * @brief Return the peripheral clock frequency for a given peripheral(SAI..)
mbed_official 532:fe11edbda85c 562 * @note Return 0 if peripheral clock identifier not managed by this API
mbed_official 532:fe11edbda85c 563 * @param PeriphClk: Peripheral clock identifier
mbed_official 532:fe11edbda85c 564 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 565 * @arg RCC_PERIPHCLK_SAI1: SAI1 peripheral clock
mbed_official 532:fe11edbda85c 566 * @arg RCC_PERIPHCLK_SAI2: SAI2 peripheral clock
mbed_official 532:fe11edbda85c 567 * @retval Frequency in KHz
mbed_official 532:fe11edbda85c 568 */
mbed_official 532:fe11edbda85c 569 uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
mbed_official 532:fe11edbda85c 570 {
mbed_official 532:fe11edbda85c 571 uint32_t tmpreg1 = 0;
mbed_official 532:fe11edbda85c 572 /* This variable used to store the SAI clock frequency (value in Hz) */
mbed_official 532:fe11edbda85c 573 uint32_t frequency = 0;
mbed_official 532:fe11edbda85c 574 /* This variable used to store the VCO Input (value in Hz) */
mbed_official 532:fe11edbda85c 575 uint32_t vcoinput = 0;
mbed_official 532:fe11edbda85c 576 /* This variable used to store the SAI clock source */
mbed_official 532:fe11edbda85c 577 uint32_t saiclocksource = 0;
mbed_official 532:fe11edbda85c 578 if ((PeriphClk == RCC_PERIPHCLK_SAI1) || (PeriphClk == RCC_PERIPHCLK_SAI2))
mbed_official 532:fe11edbda85c 579 {
mbed_official 532:fe11edbda85c 580 saiclocksource = RCC->DCKCFGR;
mbed_official 532:fe11edbda85c 581 saiclocksource &= (RCC_DCKCFGR_SAI1SRC | RCC_DCKCFGR_SAI2SRC);
mbed_official 532:fe11edbda85c 582 switch (saiclocksource)
mbed_official 532:fe11edbda85c 583 {
mbed_official 532:fe11edbda85c 584 case 0: /* PLLSAI is the clock source for SAI*/
mbed_official 532:fe11edbda85c 585 {
mbed_official 532:fe11edbda85c 586 /* Configure the PLLSAI division factor */
mbed_official 532:fe11edbda85c 587 /* PLLSAI_VCO Input = PLL_SOURCE/PLLSAIM */
mbed_official 532:fe11edbda85c 588 if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 589 {
mbed_official 532:fe11edbda85c 590 /* In Case the PLL Source is HSI (Internal Clock) */
mbed_official 532:fe11edbda85c 591 vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIM));
mbed_official 532:fe11edbda85c 592 }
mbed_official 532:fe11edbda85c 593 else
mbed_official 532:fe11edbda85c 594 {
mbed_official 532:fe11edbda85c 595 /* In Case the PLL Source is HSE (External Clock) */
mbed_official 532:fe11edbda85c 596 vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIM)));
mbed_official 532:fe11edbda85c 597 }
mbed_official 532:fe11edbda85c 598 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
mbed_official 532:fe11edbda85c 599 /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
mbed_official 532:fe11edbda85c 600 tmpreg1 = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24;
mbed_official 532:fe11edbda85c 601 frequency = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg1);
mbed_official 532:fe11edbda85c 602
mbed_official 532:fe11edbda85c 603 /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
mbed_official 532:fe11edbda85c 604 tmpreg1 = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8) + 1);
mbed_official 532:fe11edbda85c 605 frequency = frequency/(tmpreg1);
mbed_official 532:fe11edbda85c 606 break;
mbed_official 532:fe11edbda85c 607 }
mbed_official 532:fe11edbda85c 608 case RCC_DCKCFGR_SAI1SRC_0: /* PLLI2S is the clock source for SAI*/
mbed_official 532:fe11edbda85c 609 case RCC_DCKCFGR_SAI2SRC_0: /* PLLI2S is the clock source for SAI*/
mbed_official 532:fe11edbda85c 610 {
mbed_official 532:fe11edbda85c 611 /* Configure the PLLI2S division factor */
mbed_official 532:fe11edbda85c 612 /* PLLI2S_VCO Input = PLL_SOURCE/PLLI2SM */
mbed_official 532:fe11edbda85c 613 if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 614 {
mbed_official 532:fe11edbda85c 615 /* In Case the PLL Source is HSI (Internal Clock) */
mbed_official 532:fe11edbda85c 616 vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM));
mbed_official 532:fe11edbda85c 617 }
mbed_official 532:fe11edbda85c 618 else
mbed_official 532:fe11edbda85c 619 {
mbed_official 532:fe11edbda85c 620 /* In Case the PLL Source is HSE (External Clock) */
mbed_official 532:fe11edbda85c 621 vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM)));
mbed_official 532:fe11edbda85c 622 }
mbed_official 532:fe11edbda85c 623
mbed_official 532:fe11edbda85c 624 /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
mbed_official 532:fe11edbda85c 625 /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
mbed_official 532:fe11edbda85c 626 tmpreg1 = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24;
mbed_official 532:fe11edbda85c 627 frequency = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg1);
mbed_official 532:fe11edbda85c 628
mbed_official 532:fe11edbda85c 629 /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
mbed_official 532:fe11edbda85c 630 tmpreg1 = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1);
mbed_official 532:fe11edbda85c 631 frequency = frequency/(tmpreg1);
mbed_official 532:fe11edbda85c 632 break;
mbed_official 532:fe11edbda85c 633 }
mbed_official 532:fe11edbda85c 634 case RCC_DCKCFGR_SAI1SRC_1: /* PLLR is the clock source for SAI*/
mbed_official 532:fe11edbda85c 635 case RCC_DCKCFGR_SAI2SRC_1: /* PLLR is the clock source for SAI*/
mbed_official 532:fe11edbda85c 636 {
mbed_official 532:fe11edbda85c 637 /* Configure the PLLI2S division factor */
mbed_official 532:fe11edbda85c 638 /* PLL_VCO Input = PLL_SOURCE/PLLM */
mbed_official 532:fe11edbda85c 639 if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 640 {
mbed_official 532:fe11edbda85c 641 /* In Case the PLL Source is HSI (Internal Clock) */
mbed_official 532:fe11edbda85c 642 vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
mbed_official 532:fe11edbda85c 643 }
mbed_official 532:fe11edbda85c 644 else
mbed_official 532:fe11edbda85c 645 {
mbed_official 532:fe11edbda85c 646 /* In Case the PLL Source is HSE (External Clock) */
mbed_official 532:fe11edbda85c 647 vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
mbed_official 532:fe11edbda85c 648 }
mbed_official 532:fe11edbda85c 649
mbed_official 532:fe11edbda85c 650 /* PLL_VCO Output = PLL_VCO Input * PLLN */
mbed_official 532:fe11edbda85c 651 /* SAI_CLK_x = PLL_VCO Output/PLLR */
mbed_official 532:fe11edbda85c 652 tmpreg1 = (RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28;
mbed_official 532:fe11edbda85c 653 frequency = (vcoinput * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6))/(tmpreg1);
mbed_official 532:fe11edbda85c 654 break;
mbed_official 532:fe11edbda85c 655 }
mbed_official 532:fe11edbda85c 656 case RCC_DCKCFGR_SAI1SRC: /* External clock is the clock source for SAI*/
mbed_official 532:fe11edbda85c 657 {
mbed_official 532:fe11edbda85c 658 frequency = EXTERNAL_CLOCK_VALUE;
mbed_official 532:fe11edbda85c 659 break;
mbed_official 532:fe11edbda85c 660 }
mbed_official 532:fe11edbda85c 661 case RCC_DCKCFGR_SAI2SRC: /* PLLSRC(HSE or HSI) is the clock source for SAI*/
mbed_official 532:fe11edbda85c 662 {
mbed_official 532:fe11edbda85c 663 if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 664 {
mbed_official 532:fe11edbda85c 665 /* In Case the PLL Source is HSI (Internal Clock) */
mbed_official 532:fe11edbda85c 666 frequency = (uint32_t)(HSI_VALUE);
mbed_official 532:fe11edbda85c 667 }
mbed_official 532:fe11edbda85c 668 else
mbed_official 532:fe11edbda85c 669 {
mbed_official 532:fe11edbda85c 670 /* In Case the PLL Source is HSE (External Clock) */
mbed_official 532:fe11edbda85c 671 frequency = (uint32_t)(HSE_VALUE);
mbed_official 532:fe11edbda85c 672 }
mbed_official 532:fe11edbda85c 673 break;
mbed_official 532:fe11edbda85c 674 }
mbed_official 532:fe11edbda85c 675 default :
mbed_official 532:fe11edbda85c 676 {
mbed_official 532:fe11edbda85c 677 break;
mbed_official 532:fe11edbda85c 678 }
mbed_official 532:fe11edbda85c 679 }
mbed_official 532:fe11edbda85c 680 }
mbed_official 532:fe11edbda85c 681 return frequency;
mbed_official 532:fe11edbda85c 682 }
mbed_official 532:fe11edbda85c 683
mbed_official 532:fe11edbda85c 684 #endif /* STM32F446xx */
mbed_official 532:fe11edbda85c 685
mbed_official 532:fe11edbda85c 686 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
mbed_official 532:fe11edbda85c 687 /**
mbed_official 532:fe11edbda85c 688 * @brief Initializes the RCC extended peripherals clocks according to the specified
mbed_official 532:fe11edbda85c 689 * parameters in the RCC_PeriphCLKInitTypeDef.
mbed_official 532:fe11edbda85c 690 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 532:fe11edbda85c 691 * contains the configuration information for the Extended Peripherals
mbed_official 532:fe11edbda85c 692 * clocks(I2S, SAI, LTDC RTC and TIM).
mbed_official 532:fe11edbda85c 693 *
mbed_official 532:fe11edbda85c 694 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
mbed_official 532:fe11edbda85c 695 * the RTC clock source; in this case the Backup domain will be reset in
mbed_official 532:fe11edbda85c 696 * order to modify the RTC Clock source, as consequence RTC registers (including
mbed_official 532:fe11edbda85c 697 * the backup registers) and RCC_BDCR register are set to their reset values.
mbed_official 532:fe11edbda85c 698 *
mbed_official 532:fe11edbda85c 699 * @retval HAL status
mbed_official 532:fe11edbda85c 700 */
mbed_official 532:fe11edbda85c 701 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 532:fe11edbda85c 702 {
mbed_official 532:fe11edbda85c 703 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 704 uint32_t tmpreg1 = 0;
mbed_official 235:685d5f11838f 705
mbed_official 235:685d5f11838f 706 /* Check the parameters */
mbed_official 235:685d5f11838f 707 assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
mbed_official 235:685d5f11838f 708
mbed_official 235:685d5f11838f 709 /*----------------------- SAI/I2S Configuration (PLLI2S) -------------------------*/
mbed_official 235:685d5f11838f 710
mbed_official 235:685d5f11838f 711 /*----------------------- Common configuration SAI/I2S ---------------------------*/
mbed_official 235:685d5f11838f 712 /* In Case of SAI or I2S Clock Configuration through PLLI2S, PLLI2SN division
mbed_official 235:685d5f11838f 713 factor is common parameters for both peripherals */
mbed_official 235:685d5f11838f 714 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) ||
mbed_official 235:685d5f11838f 715 (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI_PLLI2S) == RCC_PERIPHCLK_SAI_PLLI2S))
mbed_official 235:685d5f11838f 716 {
mbed_official 235:685d5f11838f 717 /* check for Parameters */
mbed_official 235:685d5f11838f 718 assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
mbed_official 235:685d5f11838f 719
mbed_official 235:685d5f11838f 720 /* Disable the PLLI2S */
mbed_official 235:685d5f11838f 721 __HAL_RCC_PLLI2S_DISABLE();
mbed_official 235:685d5f11838f 722 /* Get tick */
mbed_official 235:685d5f11838f 723 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 724 /* Wait till PLLI2S is disabled */
mbed_official 235:685d5f11838f 725 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
mbed_official 235:685d5f11838f 726 {
mbed_official 235:685d5f11838f 727 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 728 {
mbed_official 235:685d5f11838f 729 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 730 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 731 }
mbed_official 235:685d5f11838f 732 }
mbed_official 235:685d5f11838f 733
mbed_official 235:685d5f11838f 734 /*---------------------------- I2S configuration -------------------------------*/
mbed_official 235:685d5f11838f 735 /* In Case of I2S Clock Configuration through PLLI2S, PLLI2SR must be added
mbed_official 235:685d5f11838f 736 only for I2S configuration */
mbed_official 235:685d5f11838f 737 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S))
mbed_official 235:685d5f11838f 738 {
mbed_official 235:685d5f11838f 739 /* check for Parameters */
mbed_official 235:685d5f11838f 740 assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
mbed_official 235:685d5f11838f 741 /* Configure the PLLI2S division factors */
mbed_official 235:685d5f11838f 742 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM) */
mbed_official 235:685d5f11838f 743 /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
mbed_official 235:685d5f11838f 744 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SR);
mbed_official 235:685d5f11838f 745 }
mbed_official 235:685d5f11838f 746
mbed_official 235:685d5f11838f 747 /*---------------------------- SAI configuration -------------------------------*/
mbed_official 235:685d5f11838f 748 /* In Case of SAI Clock Configuration through PLLI2S, PLLI2SQ and PLLI2S_DIVQ must
mbed_official 235:685d5f11838f 749 be added only for SAI configuration */
mbed_official 235:685d5f11838f 750 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI_PLLI2S) == (RCC_PERIPHCLK_SAI_PLLI2S))
mbed_official 235:685d5f11838f 751 {
mbed_official 235:685d5f11838f 752 /* Check the PLLI2S division factors */
mbed_official 235:685d5f11838f 753 assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
mbed_official 235:685d5f11838f 754 assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ));
mbed_official 235:685d5f11838f 755
mbed_official 235:685d5f11838f 756 /* Read PLLI2SR value from PLLI2SCFGR register (this value is not need for SAI configuration) */
mbed_official 532:fe11edbda85c 757 tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 235:685d5f11838f 758 /* Configure the PLLI2S division factors */
mbed_official 235:685d5f11838f 759 /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
mbed_official 235:685d5f11838f 760 /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
mbed_official 235:685d5f11838f 761 /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
mbed_official 532:fe11edbda85c 762 __HAL_RCC_PLLI2S_SAICLK_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SQ , tmpreg1);
mbed_official 235:685d5f11838f 763 /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
mbed_official 235:685d5f11838f 764 __HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ);
mbed_official 235:685d5f11838f 765 }
mbed_official 235:685d5f11838f 766
mbed_official 235:685d5f11838f 767 /* Enable the PLLI2S */
mbed_official 235:685d5f11838f 768 __HAL_RCC_PLLI2S_ENABLE();
mbed_official 235:685d5f11838f 769 /* Get tick */
mbed_official 235:685d5f11838f 770 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 771 /* Wait till PLLI2S is ready */
mbed_official 235:685d5f11838f 772 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
mbed_official 235:685d5f11838f 773 {
mbed_official 235:685d5f11838f 774 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 775 {
mbed_official 235:685d5f11838f 776 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 777 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 778 }
mbed_official 235:685d5f11838f 779 }
mbed_official 235:685d5f11838f 780 }
mbed_official 235:685d5f11838f 781
mbed_official 235:685d5f11838f 782 /*----------------------- SAI/LTDC Configuration (PLLSAI) ------------------*/
mbed_official 235:685d5f11838f 783
mbed_official 235:685d5f11838f 784 /*----------------------- Common configuration SAI/LTDC --------------------*/
mbed_official 235:685d5f11838f 785 /* In Case of SAI or LTDC Clock Configuration through PLLSAI, PLLSAIN division
mbed_official 235:685d5f11838f 786 factor is common parameters for both peripherals */
mbed_official 235:685d5f11838f 787 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI_PLLSAI) == RCC_PERIPHCLK_SAI_PLLSAI) ||
mbed_official 235:685d5f11838f 788 (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC))
mbed_official 235:685d5f11838f 789 {
mbed_official 235:685d5f11838f 790 /* Check the PLLSAI division factors */
mbed_official 235:685d5f11838f 791 assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN));
mbed_official 235:685d5f11838f 792
mbed_official 235:685d5f11838f 793 /* Disable PLLSAI Clock */
mbed_official 235:685d5f11838f 794 __HAL_RCC_PLLSAI_DISABLE();
mbed_official 235:685d5f11838f 795 /* Get tick */
mbed_official 235:685d5f11838f 796 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 797 /* Wait till PLLSAI is disabled */
mbed_official 235:685d5f11838f 798 while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
mbed_official 235:685d5f11838f 799 {
mbed_official 235:685d5f11838f 800 if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 801 {
mbed_official 235:685d5f11838f 802 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 803 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 804 }
mbed_official 235:685d5f11838f 805 }
mbed_official 235:685d5f11838f 806
mbed_official 235:685d5f11838f 807 /*---------------------------- SAI configuration -------------------------*/
mbed_official 235:685d5f11838f 808 /* In Case of SAI Clock Configuration through PLLSAI, PLLSAIQ and PLLSAI_DIVQ must
mbed_official 235:685d5f11838f 809 be added only for SAI configuration */
mbed_official 235:685d5f11838f 810 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI_PLLSAI) == (RCC_PERIPHCLK_SAI_PLLSAI))
mbed_official 235:685d5f11838f 811 {
mbed_official 235:685d5f11838f 812 assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ));
mbed_official 235:685d5f11838f 813 assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ));
mbed_official 235:685d5f11838f 814
mbed_official 235:685d5f11838f 815 /* Read PLLSAIR value from PLLSAICFGR register (this value is not need for SAI configuration) */
mbed_official 532:fe11edbda85c 816 tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR));
mbed_official 235:685d5f11838f 817 /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
mbed_official 235:685d5f11838f 818 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
mbed_official 235:685d5f11838f 819 /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
mbed_official 532:fe11edbda85c 820 __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIQ, tmpreg1);
mbed_official 235:685d5f11838f 821 /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
mbed_official 235:685d5f11838f 822 __HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ);
mbed_official 235:685d5f11838f 823 }
mbed_official 235:685d5f11838f 824
mbed_official 235:685d5f11838f 825 /*---------------------------- LTDC configuration ------------------------*/
mbed_official 235:685d5f11838f 826 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == (RCC_PERIPHCLK_LTDC))
mbed_official 235:685d5f11838f 827 {
mbed_official 235:685d5f11838f 828 assert_param(IS_RCC_PLLSAIR_VALUE(PeriphClkInit->PLLSAI.PLLSAIR));
mbed_official 235:685d5f11838f 829 assert_param(IS_RCC_PLLSAI_DIVR_VALUE(PeriphClkInit->PLLSAIDivR));
mbed_official 235:685d5f11838f 830
mbed_official 235:685d5f11838f 831 /* Read PLLSAIR value from PLLSAICFGR register (this value is not need for SAI configuration) */
mbed_official 532:fe11edbda85c 832 tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
mbed_official 235:685d5f11838f 833 /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
mbed_official 235:685d5f11838f 834 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
mbed_official 235:685d5f11838f 835 /* LTDC_CLK(first level) = PLLSAI_VCO Output/PLLSAIR */
mbed_official 532:fe11edbda85c 836 __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg1, PeriphClkInit->PLLSAI.PLLSAIR);
mbed_official 235:685d5f11838f 837 /* LTDC_CLK = LTDC_CLK(first level)/PLLSAIDIVR */
mbed_official 235:685d5f11838f 838 __HAL_RCC_PLLSAI_PLLSAICLKDIVR_CONFIG(PeriphClkInit->PLLSAIDivR);
mbed_official 235:685d5f11838f 839 }
mbed_official 235:685d5f11838f 840 /* Enable PLLSAI Clock */
mbed_official 235:685d5f11838f 841 __HAL_RCC_PLLSAI_ENABLE();
mbed_official 235:685d5f11838f 842 /* Get tick */
mbed_official 235:685d5f11838f 843 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 844 /* Wait till PLLSAI is ready */
mbed_official 235:685d5f11838f 845 while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
mbed_official 235:685d5f11838f 846 {
mbed_official 235:685d5f11838f 847 if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 848 {
mbed_official 235:685d5f11838f 849 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 850 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 851 }
mbed_official 235:685d5f11838f 852 }
mbed_official 235:685d5f11838f 853 }
mbed_official 235:685d5f11838f 854
mbed_official 235:685d5f11838f 855
mbed_official 235:685d5f11838f 856 /*---------------------------- RTC configuration ---------------------------*/
mbed_official 235:685d5f11838f 857 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
mbed_official 613:bc40b8d2aec4 858 {
mbed_official 235:685d5f11838f 859 /* Enable Power Clock*/
mbed_official 532:fe11edbda85c 860 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 235:685d5f11838f 861
mbed_official 235:685d5f11838f 862 /* Enable write access to Backup domain */
mbed_official 235:685d5f11838f 863 PWR->CR |= PWR_CR_DBP;
mbed_official 235:685d5f11838f 864
mbed_official 235:685d5f11838f 865 /* Get tick */
mbed_official 235:685d5f11838f 866 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 867
mbed_official 235:685d5f11838f 868 while((PWR->CR & PWR_CR_DBP) == RESET)
mbed_official 235:685d5f11838f 869 {
mbed_official 532:fe11edbda85c 870 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 871 {
mbed_official 235:685d5f11838f 872 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 873 }
mbed_official 235:685d5f11838f 874 }
mbed_official 532:fe11edbda85c 875 /* Reset the Backup domain only if the RTC Clock source selection is modified */
mbed_official 235:685d5f11838f 876 if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))
mbed_official 613:bc40b8d2aec4 877 {
mbed_official 235:685d5f11838f 878 /* Store the content of BDCR register before the reset of Backup Domain */
mbed_official 532:fe11edbda85c 879 tmpreg1 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
mbed_official 235:685d5f11838f 880 /* RTC Clock selection can be changed only if the Backup Domain is reset */
mbed_official 235:685d5f11838f 881 __HAL_RCC_BACKUPRESET_FORCE();
mbed_official 235:685d5f11838f 882 __HAL_RCC_BACKUPRESET_RELEASE();
mbed_official 235:685d5f11838f 883 /* Restore the Content of BDCR register */
mbed_official 532:fe11edbda85c 884 RCC->BDCR = tmpreg1;
mbed_official 613:bc40b8d2aec4 885 /* Wait for LSERDY if LSE was enabled */
mbed_official 613:bc40b8d2aec4 886 if(HAL_IS_BIT_SET(tmpreg1, RCC_BDCR_LSERDY))
mbed_official 613:bc40b8d2aec4 887 {
mbed_official 613:bc40b8d2aec4 888 /* Get tick */
mbed_official 613:bc40b8d2aec4 889 tickstart = HAL_GetTick();
mbed_official 613:bc40b8d2aec4 890
mbed_official 613:bc40b8d2aec4 891 /* Wait till LSE is ready */
mbed_official 613:bc40b8d2aec4 892 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
mbed_official 613:bc40b8d2aec4 893 {
mbed_official 613:bc40b8d2aec4 894 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 613:bc40b8d2aec4 895 {
mbed_official 613:bc40b8d2aec4 896 return HAL_TIMEOUT;
mbed_official 613:bc40b8d2aec4 897 }
mbed_official 613:bc40b8d2aec4 898 }
mbed_official 613:bc40b8d2aec4 899 }
mbed_official 613:bc40b8d2aec4 900 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
mbed_official 235:685d5f11838f 901 }
mbed_official 235:685d5f11838f 902 }
mbed_official 235:685d5f11838f 903
mbed_official 235:685d5f11838f 904 /*---------------------------- TIM configuration ---------------------------*/
mbed_official 235:685d5f11838f 905 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM))
mbed_official 235:685d5f11838f 906 {
mbed_official 235:685d5f11838f 907 __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
mbed_official 235:685d5f11838f 908 }
mbed_official 235:685d5f11838f 909 return HAL_OK;
mbed_official 235:685d5f11838f 910 }
mbed_official 235:685d5f11838f 911
mbed_official 235:685d5f11838f 912 /**
mbed_official 235:685d5f11838f 913 * @brief Configures the RCC_OscInitStruct according to the internal
mbed_official 235:685d5f11838f 914 * RCC configuration registers.
mbed_official 235:685d5f11838f 915 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 235:685d5f11838f 916 * will be configured.
mbed_official 235:685d5f11838f 917 * @retval None
mbed_official 235:685d5f11838f 918 */
mbed_official 235:685d5f11838f 919 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 235:685d5f11838f 920 {
mbed_official 235:685d5f11838f 921 uint32_t tempreg;
mbed_official 235:685d5f11838f 922
mbed_official 235:685d5f11838f 923 /* Set all possible values for the extended clock type parameter------------*/
mbed_official 235:685d5f11838f 924 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_SAI_PLLSAI | RCC_PERIPHCLK_SAI_PLLI2S | RCC_PERIPHCLK_LTDC | RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC;
mbed_official 235:685d5f11838f 925
mbed_official 235:685d5f11838f 926 /* Get the PLLI2S Clock configuration -----------------------------------------------*/
mbed_official 235:685d5f11838f 927 PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN));
mbed_official 235:685d5f11838f 928 PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 235:685d5f11838f 929 PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
mbed_official 235:685d5f11838f 930 /* Get the PLLSAI Clock configuration -----------------------------------------------*/
mbed_official 235:685d5f11838f 931 PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIN));
mbed_official 235:685d5f11838f 932 PeriphClkInit->PLLSAI.PLLSAIR = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR));
mbed_official 235:685d5f11838f 933 PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
mbed_official 235:685d5f11838f 934 /* Get the PLLSAI/PLLI2S division factors -----------------------------------------------*/
mbed_official 235:685d5f11838f 935 PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) >> POSITION_VAL(RCC_DCKCFGR_PLLI2SDIVQ));
mbed_official 235:685d5f11838f 936 PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> POSITION_VAL(RCC_DCKCFGR_PLLSAIDIVQ));
mbed_official 235:685d5f11838f 937 PeriphClkInit->PLLSAIDivR = (uint32_t)(RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVR);
mbed_official 235:685d5f11838f 938 /* Get the RTC Clock configuration -----------------------------------------------*/
mbed_official 235:685d5f11838f 939 tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
mbed_official 235:685d5f11838f 940 PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
mbed_official 235:685d5f11838f 941
mbed_official 235:685d5f11838f 942 if ((RCC->DCKCFGR & RCC_DCKCFGR_TIMPRE) == RESET)
mbed_official 235:685d5f11838f 943 {
mbed_official 235:685d5f11838f 944 PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
mbed_official 235:685d5f11838f 945 }
mbed_official 235:685d5f11838f 946 else
mbed_official 235:685d5f11838f 947 {
mbed_official 235:685d5f11838f 948 PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
mbed_official 235:685d5f11838f 949 }
mbed_official 235:685d5f11838f 950 }
mbed_official 532:fe11edbda85c 951
mbed_official 235:685d5f11838f 952 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
mbed_official 235:685d5f11838f 953
mbed_official 235:685d5f11838f 954 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx) ||\
mbed_official 235:685d5f11838f 955 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
mbed_official 235:685d5f11838f 956 /**
mbed_official 235:685d5f11838f 957 * @brief Initializes the RCC extended peripherals clocks according to the specified parameters in the
mbed_official 235:685d5f11838f 958 * RCC_PeriphCLKInitTypeDef.
mbed_official 235:685d5f11838f 959 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 235:685d5f11838f 960 * contains the configuration information for the Extended Peripherals clocks(I2S and RTC clocks).
mbed_official 235:685d5f11838f 961 *
mbed_official 235:685d5f11838f 962 * @note A caution to be taken when HAL_RCCEx_PeriphCLKConfig() is used to select RTC clock selection, in this case
mbed_official 235:685d5f11838f 963 * the Reset of Backup domain will be applied in order to modify the RTC Clock source as consequence all backup
mbed_official 235:685d5f11838f 964 * domain (RTC and RCC_BDCR register expect BKPSRAM) will be reset
mbed_official 235:685d5f11838f 965 *
mbed_official 235:685d5f11838f 966 * @retval HAL status
mbed_official 235:685d5f11838f 967 */
mbed_official 235:685d5f11838f 968 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 235:685d5f11838f 969 {
mbed_official 235:685d5f11838f 970 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 971 uint32_t tmpreg1 = 0;
mbed_official 235:685d5f11838f 972
mbed_official 235:685d5f11838f 973 /* Check the parameters */
mbed_official 235:685d5f11838f 974 assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
mbed_official 235:685d5f11838f 975
mbed_official 235:685d5f11838f 976 /*---------------------------- I2S configuration ---------------------------*/
mbed_official 235:685d5f11838f 977 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S))
mbed_official 235:685d5f11838f 978 {
mbed_official 235:685d5f11838f 979 /* check for Parameters */
mbed_official 235:685d5f11838f 980 assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
mbed_official 235:685d5f11838f 981 assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
mbed_official 235:685d5f11838f 982 #if defined(STM32F411xE)
mbed_official 235:685d5f11838f 983 assert_param(IS_RCC_PLLI2SM_VALUE(PeriphClkInit->PLLI2S.PLLI2SM));
mbed_official 235:685d5f11838f 984 #endif /* STM32F411xE */
mbed_official 235:685d5f11838f 985 /* Disable the PLLI2S */
mbed_official 235:685d5f11838f 986 __HAL_RCC_PLLI2S_DISABLE();
mbed_official 235:685d5f11838f 987 /* Get tick */
mbed_official 235:685d5f11838f 988 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 989 /* Wait till PLLI2S is disabled */
mbed_official 235:685d5f11838f 990 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
mbed_official 235:685d5f11838f 991 {
mbed_official 235:685d5f11838f 992 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 993 {
mbed_official 235:685d5f11838f 994 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 995 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 996 }
mbed_official 235:685d5f11838f 997 }
mbed_official 235:685d5f11838f 998
mbed_official 235:685d5f11838f 999 #if defined(STM32F411xE)
mbed_official 235:685d5f11838f 1000 /* Configure the PLLI2S division factors */
mbed_official 235:685d5f11838f 1001 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLI2SM) */
mbed_official 235:685d5f11838f 1002 /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
mbed_official 235:685d5f11838f 1003 __HAL_RCC_PLLI2S_I2SCLK_CONFIG(PeriphClkInit->PLLI2S.PLLI2SM, PeriphClkInit->PLLI2S.PLLI2SN, PeriphClkInit->PLLI2S.PLLI2SR);
mbed_official 235:685d5f11838f 1004 #else
mbed_official 235:685d5f11838f 1005 /* Configure the PLLI2S division factors */
mbed_official 235:685d5f11838f 1006 /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM) */
mbed_official 235:685d5f11838f 1007 /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
mbed_official 235:685d5f11838f 1008 __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SR);
mbed_official 235:685d5f11838f 1009 #endif /* STM32F411xE */
mbed_official 235:685d5f11838f 1010
mbed_official 235:685d5f11838f 1011 /* Enable the PLLI2S */
mbed_official 235:685d5f11838f 1012 __HAL_RCC_PLLI2S_ENABLE();
mbed_official 235:685d5f11838f 1013 /* Get tick */
mbed_official 235:685d5f11838f 1014 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1015 /* Wait till PLLI2S is ready */
mbed_official 235:685d5f11838f 1016 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
mbed_official 235:685d5f11838f 1017 {
mbed_official 235:685d5f11838f 1018 if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1019 {
mbed_official 235:685d5f11838f 1020 /* return in case of Timeout detected */
mbed_official 235:685d5f11838f 1021 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1022 }
mbed_official 235:685d5f11838f 1023 }
mbed_official 235:685d5f11838f 1024 }
mbed_official 235:685d5f11838f 1025
mbed_official 235:685d5f11838f 1026 /*---------------------------- RTC configuration ---------------------------*/
mbed_official 235:685d5f11838f 1027 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
mbed_official 613:bc40b8d2aec4 1028 {
mbed_official 235:685d5f11838f 1029 /* Enable Power Clock*/
mbed_official 532:fe11edbda85c 1030 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 235:685d5f11838f 1031
mbed_official 235:685d5f11838f 1032 /* Enable write access to Backup domain */
mbed_official 235:685d5f11838f 1033 PWR->CR |= PWR_CR_DBP;
mbed_official 613:bc40b8d2aec4 1034
mbed_official 235:685d5f11838f 1035 /* Get tick */
mbed_official 235:685d5f11838f 1036 tickstart = HAL_GetTick();
mbed_official 613:bc40b8d2aec4 1037
mbed_official 235:685d5f11838f 1038 while((PWR->CR & PWR_CR_DBP) == RESET)
mbed_official 235:685d5f11838f 1039 {
mbed_official 532:fe11edbda85c 1040 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1041 {
mbed_official 235:685d5f11838f 1042 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1043 }
mbed_official 235:685d5f11838f 1044 }
mbed_official 532:fe11edbda85c 1045 /* Reset the Backup domain only if the RTC Clock source selection is modified */
mbed_official 235:685d5f11838f 1046 if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))
mbed_official 613:bc40b8d2aec4 1047 {
mbed_official 235:685d5f11838f 1048 /* Store the content of BDCR register before the reset of Backup Domain */
mbed_official 532:fe11edbda85c 1049 tmpreg1 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
mbed_official 235:685d5f11838f 1050 /* RTC Clock selection can be changed only if the Backup Domain is reset */
mbed_official 235:685d5f11838f 1051 __HAL_RCC_BACKUPRESET_FORCE();
mbed_official 235:685d5f11838f 1052 __HAL_RCC_BACKUPRESET_RELEASE();
mbed_official 235:685d5f11838f 1053 /* Restore the Content of BDCR register */
mbed_official 532:fe11edbda85c 1054 RCC->BDCR = tmpreg1;
mbed_official 613:bc40b8d2aec4 1055 /* Wait for LSERDY if LSE was enabled */
mbed_official 613:bc40b8d2aec4 1056 if(HAL_IS_BIT_SET(tmpreg1, RCC_BDCR_LSERDY))
mbed_official 613:bc40b8d2aec4 1057 {
mbed_official 613:bc40b8d2aec4 1058 /* Get tick */
mbed_official 613:bc40b8d2aec4 1059 tickstart = HAL_GetTick();
mbed_official 613:bc40b8d2aec4 1060
mbed_official 613:bc40b8d2aec4 1061 /* Wait till LSE is ready */
mbed_official 613:bc40b8d2aec4 1062 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
mbed_official 613:bc40b8d2aec4 1063 {
mbed_official 613:bc40b8d2aec4 1064 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 613:bc40b8d2aec4 1065 {
mbed_official 613:bc40b8d2aec4 1066 return HAL_TIMEOUT;
mbed_official 613:bc40b8d2aec4 1067 }
mbed_official 613:bc40b8d2aec4 1068 }
mbed_official 613:bc40b8d2aec4 1069 }
mbed_official 613:bc40b8d2aec4 1070 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
mbed_official 235:685d5f11838f 1071 }
mbed_official 235:685d5f11838f 1072 }
mbed_official 235:685d5f11838f 1073
mbed_official 235:685d5f11838f 1074 return HAL_OK;
mbed_official 235:685d5f11838f 1075 }
mbed_official 235:685d5f11838f 1076
mbed_official 235:685d5f11838f 1077 /**
mbed_official 235:685d5f11838f 1078 * @brief Configures the RCC_OscInitStruct according to the internal
mbed_official 235:685d5f11838f 1079 * RCC configuration registers.
mbed_official 235:685d5f11838f 1080 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 235:685d5f11838f 1081 * will be configured.
mbed_official 235:685d5f11838f 1082 * @retval None
mbed_official 235:685d5f11838f 1083 */
mbed_official 235:685d5f11838f 1084 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 235:685d5f11838f 1085 {
mbed_official 235:685d5f11838f 1086 uint32_t tempreg;
mbed_official 235:685d5f11838f 1087
mbed_official 235:685d5f11838f 1088 /* Set all possible values for the extended clock type parameter------------*/
mbed_official 235:685d5f11838f 1089 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_RTC;
mbed_official 235:685d5f11838f 1090
mbed_official 235:685d5f11838f 1091 /* Get the PLLI2S Clock configuration -----------------------------------------------*/
mbed_official 235:685d5f11838f 1092 PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN));
mbed_official 235:685d5f11838f 1093 PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
mbed_official 235:685d5f11838f 1094 #if defined(STM32F411xE)
mbed_official 235:685d5f11838f 1095 PeriphClkInit->PLLI2S.PLLI2SM = (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM);
mbed_official 235:685d5f11838f 1096 #endif /* STM32F411xE */
mbed_official 235:685d5f11838f 1097 /* Get the RTC Clock configuration -----------------------------------------------*/
mbed_official 235:685d5f11838f 1098 tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
mbed_official 235:685d5f11838f 1099 PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
mbed_official 235:685d5f11838f 1100
mbed_official 235:685d5f11838f 1101 }
mbed_official 235:685d5f11838f 1102 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE */
mbed_official 235:685d5f11838f 1103
mbed_official 532:fe11edbda85c 1104 #if defined(STM32F411xE) || defined(STM32F446xx)
mbed_official 235:685d5f11838f 1105 /**
mbed_official 235:685d5f11838f 1106 * @brief Select LSE mode
mbed_official 235:685d5f11838f 1107 *
mbed_official 235:685d5f11838f 1108 * @note This mode is only available for STM32F411xx devices.
mbed_official 235:685d5f11838f 1109 *
mbed_official 235:685d5f11838f 1110 * @param Mode: specifies the LSE mode.
mbed_official 235:685d5f11838f 1111 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 1112 * @arg RCC_LSE_LOWPOWER_MODE: LSE oscillator in low power mode selection
mbed_official 235:685d5f11838f 1113 * @arg RCC_LSE_HIGHDRIVE_MODE: LSE oscillator in High Drive mode selection
mbed_official 235:685d5f11838f 1114 * @retval None
mbed_official 235:685d5f11838f 1115 */
mbed_official 235:685d5f11838f 1116 void HAL_RCCEx_SelectLSEMode(uint8_t Mode)
mbed_official 235:685d5f11838f 1117 {
mbed_official 235:685d5f11838f 1118 /* Check the parameters */
mbed_official 235:685d5f11838f 1119 assert_param(IS_RCC_LSE_MODE(Mode));
mbed_official 235:685d5f11838f 1120 if(Mode == RCC_LSE_HIGHDRIVE_MODE)
mbed_official 235:685d5f11838f 1121 {
mbed_official 235:685d5f11838f 1122 SET_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
mbed_official 235:685d5f11838f 1123 }
mbed_official 235:685d5f11838f 1124 else
mbed_official 235:685d5f11838f 1125 {
mbed_official 235:685d5f11838f 1126 CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
mbed_official 235:685d5f11838f 1127 }
mbed_official 235:685d5f11838f 1128 }
mbed_official 235:685d5f11838f 1129
mbed_official 532:fe11edbda85c 1130 #endif /* STM32F411xE || STM32F446xx */
mbed_official 532:fe11edbda85c 1131
mbed_official 532:fe11edbda85c 1132 #if defined(STM32F446xx)
mbed_official 532:fe11edbda85c 1133 /**
mbed_official 532:fe11edbda85c 1134 * @brief Initializes the RCC Oscillators according to the specified parameters in the
mbed_official 532:fe11edbda85c 1135 * RCC_OscInitTypeDef.
mbed_official 532:fe11edbda85c 1136 * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
mbed_official 532:fe11edbda85c 1137 * contains the configuration information for the RCC Oscillators.
mbed_official 532:fe11edbda85c 1138 * @note The PLL is not disabled when used as system clock.
mbed_official 532:fe11edbda85c 1139 * @note This function add the PLL/PLLR factor management during PLL configuration this feature is only available in STM32F446xx devices
mbed_official 532:fe11edbda85c 1140 * @retval HAL status
mbed_official 532:fe11edbda85c 1141 */
mbed_official 532:fe11edbda85c 1142 HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
mbed_official 532:fe11edbda85c 1143 {
mbed_official 532:fe11edbda85c 1144 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 1145
mbed_official 532:fe11edbda85c 1146 /* Check the parameters */
mbed_official 532:fe11edbda85c 1147 assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
mbed_official 532:fe11edbda85c 1148 /*------------------------------- HSE Configuration ------------------------*/
mbed_official 532:fe11edbda85c 1149 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
mbed_official 532:fe11edbda85c 1150 {
mbed_official 532:fe11edbda85c 1151 /* Check the parameters */
mbed_official 532:fe11edbda85c 1152 assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
mbed_official 532:fe11edbda85c 1153 /* When the HSE is used as system clock or clock source for PLL in these cases HSE will not disabled */
mbed_official 532:fe11edbda85c 1154 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSE) ||\
mbed_official 532:fe11edbda85c 1155 ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE)) ||\
mbed_official 532:fe11edbda85c 1156 ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLLR) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE)))
mbed_official 532:fe11edbda85c 1157 {
mbed_official 532:fe11edbda85c 1158 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
mbed_official 532:fe11edbda85c 1159 {
mbed_official 532:fe11edbda85c 1160 return HAL_ERROR;
mbed_official 532:fe11edbda85c 1161 }
mbed_official 532:fe11edbda85c 1162 }
mbed_official 532:fe11edbda85c 1163 else
mbed_official 532:fe11edbda85c 1164 {
mbed_official 532:fe11edbda85c 1165 /* Reset HSEON and HSEBYP bits before configuring the HSE --------------*/
mbed_official 532:fe11edbda85c 1166 __HAL_RCC_HSE_CONFIG(RCC_HSE_OFF);
mbed_official 532:fe11edbda85c 1167
mbed_official 532:fe11edbda85c 1168 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1169 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1170
mbed_official 532:fe11edbda85c 1171 /* Wait till HSE is disabled */
mbed_official 532:fe11edbda85c 1172 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
mbed_official 532:fe11edbda85c 1173 {
mbed_official 532:fe11edbda85c 1174 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1175 {
mbed_official 532:fe11edbda85c 1176 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1177 }
mbed_official 532:fe11edbda85c 1178 }
mbed_official 532:fe11edbda85c 1179
mbed_official 532:fe11edbda85c 1180 /* Set the new HSE configuration ---------------------------------------*/
mbed_official 532:fe11edbda85c 1181 __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
mbed_official 532:fe11edbda85c 1182
mbed_official 532:fe11edbda85c 1183 /* Check the HSE State */
mbed_official 532:fe11edbda85c 1184 if((RCC_OscInitStruct->HSEState) != RCC_HSE_OFF)
mbed_official 532:fe11edbda85c 1185 {
mbed_official 532:fe11edbda85c 1186 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1187 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1188
mbed_official 532:fe11edbda85c 1189 /* Wait till HSE is ready */
mbed_official 532:fe11edbda85c 1190 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
mbed_official 532:fe11edbda85c 1191 {
mbed_official 532:fe11edbda85c 1192 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1193 {
mbed_official 532:fe11edbda85c 1194 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1195 }
mbed_official 532:fe11edbda85c 1196 }
mbed_official 532:fe11edbda85c 1197 }
mbed_official 532:fe11edbda85c 1198 else
mbed_official 532:fe11edbda85c 1199 {
mbed_official 532:fe11edbda85c 1200 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1201 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1202
mbed_official 532:fe11edbda85c 1203 /* Wait till HSE is bypassed or disabled */
mbed_official 532:fe11edbda85c 1204 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
mbed_official 532:fe11edbda85c 1205 {
mbed_official 532:fe11edbda85c 1206 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1207 {
mbed_official 532:fe11edbda85c 1208 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1209 }
mbed_official 532:fe11edbda85c 1210 }
mbed_official 532:fe11edbda85c 1211 }
mbed_official 532:fe11edbda85c 1212 }
mbed_official 532:fe11edbda85c 1213 }
mbed_official 532:fe11edbda85c 1214 /*----------------------------- HSI Configuration --------------------------*/
mbed_official 532:fe11edbda85c 1215 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
mbed_official 532:fe11edbda85c 1216 {
mbed_official 532:fe11edbda85c 1217 /* Check the parameters */
mbed_official 532:fe11edbda85c 1218 assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
mbed_official 532:fe11edbda85c 1219 assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
mbed_official 532:fe11edbda85c 1220
mbed_official 532:fe11edbda85c 1221 /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
mbed_official 532:fe11edbda85c 1222 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSI) ||\
mbed_official 532:fe11edbda85c 1223 ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI)) ||\
mbed_official 532:fe11edbda85c 1224 ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLLR) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI)))
mbed_official 532:fe11edbda85c 1225 {
mbed_official 532:fe11edbda85c 1226 /* When HSI is used as system clock it will not disabled */
mbed_official 532:fe11edbda85c 1227 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
mbed_official 532:fe11edbda85c 1228 {
mbed_official 532:fe11edbda85c 1229 return HAL_ERROR;
mbed_official 532:fe11edbda85c 1230 }
mbed_official 532:fe11edbda85c 1231 /* Otherwise, just the calibration is allowed */
mbed_official 532:fe11edbda85c 1232 else
mbed_official 532:fe11edbda85c 1233 {
mbed_official 532:fe11edbda85c 1234 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
mbed_official 532:fe11edbda85c 1235 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
mbed_official 532:fe11edbda85c 1236 }
mbed_official 532:fe11edbda85c 1237 }
mbed_official 532:fe11edbda85c 1238 else
mbed_official 532:fe11edbda85c 1239 {
mbed_official 532:fe11edbda85c 1240 /* Check the HSI State */
mbed_official 532:fe11edbda85c 1241 if((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF)
mbed_official 532:fe11edbda85c 1242 {
mbed_official 532:fe11edbda85c 1243 /* Enable the Internal High Speed oscillator (HSI). */
mbed_official 532:fe11edbda85c 1244 __HAL_RCC_HSI_ENABLE();
mbed_official 532:fe11edbda85c 1245
mbed_official 532:fe11edbda85c 1246 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1247 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1248
mbed_official 532:fe11edbda85c 1249 /* Wait till HSI is ready */
mbed_official 532:fe11edbda85c 1250 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
mbed_official 532:fe11edbda85c 1251 {
mbed_official 532:fe11edbda85c 1252 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1253 {
mbed_official 532:fe11edbda85c 1254 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1255 }
mbed_official 532:fe11edbda85c 1256 }
mbed_official 532:fe11edbda85c 1257
mbed_official 532:fe11edbda85c 1258 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
mbed_official 532:fe11edbda85c 1259 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
mbed_official 532:fe11edbda85c 1260 }
mbed_official 532:fe11edbda85c 1261 else
mbed_official 532:fe11edbda85c 1262 {
mbed_official 532:fe11edbda85c 1263 /* Disable the Internal High Speed oscillator (HSI). */
mbed_official 532:fe11edbda85c 1264 __HAL_RCC_HSI_DISABLE();
mbed_official 532:fe11edbda85c 1265
mbed_official 532:fe11edbda85c 1266 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1267 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1268
mbed_official 532:fe11edbda85c 1269 /* Wait till HSI is ready */
mbed_official 532:fe11edbda85c 1270 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
mbed_official 532:fe11edbda85c 1271 {
mbed_official 532:fe11edbda85c 1272 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1273 {
mbed_official 532:fe11edbda85c 1274 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1275 }
mbed_official 532:fe11edbda85c 1276 }
mbed_official 532:fe11edbda85c 1277 }
mbed_official 532:fe11edbda85c 1278 }
mbed_official 532:fe11edbda85c 1279 }
mbed_official 532:fe11edbda85c 1280 /*------------------------------ LSI Configuration -------------------------*/
mbed_official 532:fe11edbda85c 1281 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
mbed_official 532:fe11edbda85c 1282 {
mbed_official 532:fe11edbda85c 1283 /* Check the parameters */
mbed_official 532:fe11edbda85c 1284 assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
mbed_official 532:fe11edbda85c 1285
mbed_official 532:fe11edbda85c 1286 /* Check the LSI State */
mbed_official 532:fe11edbda85c 1287 if((RCC_OscInitStruct->LSIState)!= RCC_LSI_OFF)
mbed_official 532:fe11edbda85c 1288 {
mbed_official 532:fe11edbda85c 1289 /* Enable the Internal Low Speed oscillator (LSI). */
mbed_official 532:fe11edbda85c 1290 __HAL_RCC_LSI_ENABLE();
mbed_official 532:fe11edbda85c 1291
mbed_official 532:fe11edbda85c 1292 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1293 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1294
mbed_official 532:fe11edbda85c 1295 /* Wait till LSI is ready */
mbed_official 532:fe11edbda85c 1296 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET)
mbed_official 532:fe11edbda85c 1297 {
mbed_official 532:fe11edbda85c 1298 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1299 {
mbed_official 532:fe11edbda85c 1300 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1301 }
mbed_official 532:fe11edbda85c 1302 }
mbed_official 532:fe11edbda85c 1303 }
mbed_official 532:fe11edbda85c 1304 else
mbed_official 532:fe11edbda85c 1305 {
mbed_official 532:fe11edbda85c 1306 /* Disable the Internal Low Speed oscillator (LSI). */
mbed_official 532:fe11edbda85c 1307 __HAL_RCC_LSI_DISABLE();
mbed_official 532:fe11edbda85c 1308
mbed_official 532:fe11edbda85c 1309 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1310 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1311
mbed_official 532:fe11edbda85c 1312 /* Wait till LSI is ready */
mbed_official 532:fe11edbda85c 1313 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET)
mbed_official 532:fe11edbda85c 1314 {
mbed_official 532:fe11edbda85c 1315 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1316 {
mbed_official 532:fe11edbda85c 1317 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1318 }
mbed_official 532:fe11edbda85c 1319 }
mbed_official 532:fe11edbda85c 1320 }
mbed_official 532:fe11edbda85c 1321 }
mbed_official 532:fe11edbda85c 1322 /*------------------------------ LSE Configuration -------------------------*/
mbed_official 532:fe11edbda85c 1323 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
mbed_official 532:fe11edbda85c 1324 {
mbed_official 532:fe11edbda85c 1325 /* Check the parameters */
mbed_official 532:fe11edbda85c 1326 assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
mbed_official 532:fe11edbda85c 1327
mbed_official 532:fe11edbda85c 1328 /* Enable Power Clock*/
mbed_official 532:fe11edbda85c 1329 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 532:fe11edbda85c 1330
mbed_official 532:fe11edbda85c 1331 /* Enable write access to Backup domain */
mbed_official 532:fe11edbda85c 1332 PWR->CR |= PWR_CR_DBP;
mbed_official 532:fe11edbda85c 1333
mbed_official 532:fe11edbda85c 1334 /* Wait for Backup domain Write protection disable */
mbed_official 532:fe11edbda85c 1335 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1336
mbed_official 532:fe11edbda85c 1337 while((PWR->CR & PWR_CR_DBP) == RESET)
mbed_official 532:fe11edbda85c 1338 {
mbed_official 532:fe11edbda85c 1339 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1340 {
mbed_official 532:fe11edbda85c 1341 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1342 }
mbed_official 532:fe11edbda85c 1343 }
mbed_official 532:fe11edbda85c 1344
mbed_official 532:fe11edbda85c 1345 /* Reset LSEON and LSEBYP bits before configuring the LSE ----------------*/
mbed_official 532:fe11edbda85c 1346 __HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
mbed_official 532:fe11edbda85c 1347
mbed_official 532:fe11edbda85c 1348 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1349 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1350
mbed_official 532:fe11edbda85c 1351 /* Wait till LSE is ready */
mbed_official 532:fe11edbda85c 1352 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
mbed_official 532:fe11edbda85c 1353 {
mbed_official 532:fe11edbda85c 1354 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1355 {
mbed_official 532:fe11edbda85c 1356 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1357 }
mbed_official 532:fe11edbda85c 1358 }
mbed_official 532:fe11edbda85c 1359
mbed_official 532:fe11edbda85c 1360 /* Set the new LSE configuration -----------------------------------------*/
mbed_official 532:fe11edbda85c 1361 __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
mbed_official 532:fe11edbda85c 1362 /* Check the LSE State */
mbed_official 532:fe11edbda85c 1363 if((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
mbed_official 532:fe11edbda85c 1364 {
mbed_official 532:fe11edbda85c 1365 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1366 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1367
mbed_official 532:fe11edbda85c 1368 /* Wait till LSE is ready */
mbed_official 532:fe11edbda85c 1369 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
mbed_official 532:fe11edbda85c 1370 {
mbed_official 532:fe11edbda85c 1371 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1372 {
mbed_official 532:fe11edbda85c 1373 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1374 }
mbed_official 532:fe11edbda85c 1375 }
mbed_official 532:fe11edbda85c 1376 }
mbed_official 532:fe11edbda85c 1377 else
mbed_official 532:fe11edbda85c 1378 {
mbed_official 532:fe11edbda85c 1379 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1380 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1381
mbed_official 532:fe11edbda85c 1382 /* Wait till LSE is ready */
mbed_official 532:fe11edbda85c 1383 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
mbed_official 532:fe11edbda85c 1384 {
mbed_official 532:fe11edbda85c 1385 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1386 {
mbed_official 532:fe11edbda85c 1387 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1388 }
mbed_official 532:fe11edbda85c 1389 }
mbed_official 532:fe11edbda85c 1390 }
mbed_official 532:fe11edbda85c 1391 }
mbed_official 532:fe11edbda85c 1392 /*-------------------------------- PLL Configuration -----------------------*/
mbed_official 532:fe11edbda85c 1393 /* Check the parameters */
mbed_official 532:fe11edbda85c 1394 assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
mbed_official 532:fe11edbda85c 1395 if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
mbed_official 532:fe11edbda85c 1396 {
mbed_official 532:fe11edbda85c 1397 /* Check if the PLL is used as system clock or not */
mbed_official 532:fe11edbda85c 1398 if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
mbed_official 532:fe11edbda85c 1399 {
mbed_official 532:fe11edbda85c 1400 if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
mbed_official 532:fe11edbda85c 1401 {
mbed_official 532:fe11edbda85c 1402 /* Check the parameters */
mbed_official 532:fe11edbda85c 1403 assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
mbed_official 532:fe11edbda85c 1404 assert_param(IS_RCC_PLLM_VALUE(RCC_OscInitStruct->PLL.PLLM));
mbed_official 532:fe11edbda85c 1405 assert_param(IS_RCC_PLLN_VALUE(RCC_OscInitStruct->PLL.PLLN));
mbed_official 532:fe11edbda85c 1406 assert_param(IS_RCC_PLLP_VALUE(RCC_OscInitStruct->PLL.PLLP));
mbed_official 532:fe11edbda85c 1407 assert_param(IS_RCC_PLLQ_VALUE(RCC_OscInitStruct->PLL.PLLQ));
mbed_official 532:fe11edbda85c 1408 assert_param(IS_RCC_PLLR_VALUE(RCC_OscInitStruct->PLL.PLLR));
mbed_official 532:fe11edbda85c 1409
mbed_official 532:fe11edbda85c 1410 /* Disable the main PLL. */
mbed_official 532:fe11edbda85c 1411 __HAL_RCC_PLL_DISABLE();
mbed_official 532:fe11edbda85c 1412
mbed_official 532:fe11edbda85c 1413 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1414 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1415
mbed_official 532:fe11edbda85c 1416 /* Wait till PLL is ready */
mbed_official 532:fe11edbda85c 1417 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
mbed_official 532:fe11edbda85c 1418 {
mbed_official 532:fe11edbda85c 1419 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1420 {
mbed_official 532:fe11edbda85c 1421 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1422 }
mbed_official 532:fe11edbda85c 1423 }
mbed_official 532:fe11edbda85c 1424
mbed_official 532:fe11edbda85c 1425 /* Configure the main PLL clock source, multiplication and division factors. */
mbed_official 532:fe11edbda85c 1426 __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
mbed_official 532:fe11edbda85c 1427 RCC_OscInitStruct->PLL.PLLM,
mbed_official 532:fe11edbda85c 1428 RCC_OscInitStruct->PLL.PLLN,
mbed_official 532:fe11edbda85c 1429 RCC_OscInitStruct->PLL.PLLP,
mbed_official 532:fe11edbda85c 1430 RCC_OscInitStruct->PLL.PLLQ,
mbed_official 532:fe11edbda85c 1431 RCC_OscInitStruct->PLL.PLLR);
mbed_official 532:fe11edbda85c 1432
mbed_official 532:fe11edbda85c 1433 /* Enable the main PLL. */
mbed_official 532:fe11edbda85c 1434 __HAL_RCC_PLL_ENABLE();
mbed_official 532:fe11edbda85c 1435
mbed_official 532:fe11edbda85c 1436 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1437 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1438
mbed_official 532:fe11edbda85c 1439 /* Wait till PLL is ready */
mbed_official 532:fe11edbda85c 1440 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
mbed_official 532:fe11edbda85c 1441 {
mbed_official 532:fe11edbda85c 1442 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1443 {
mbed_official 532:fe11edbda85c 1444 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1445 }
mbed_official 532:fe11edbda85c 1446 }
mbed_official 532:fe11edbda85c 1447 }
mbed_official 532:fe11edbda85c 1448 else
mbed_official 532:fe11edbda85c 1449 {
mbed_official 532:fe11edbda85c 1450 /* Disable the main PLL. */
mbed_official 532:fe11edbda85c 1451 __HAL_RCC_PLL_DISABLE();
mbed_official 532:fe11edbda85c 1452
mbed_official 532:fe11edbda85c 1453 /* Get Start Tick*/
mbed_official 532:fe11edbda85c 1454 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 1455
mbed_official 532:fe11edbda85c 1456 /* Wait till PLL is ready */
mbed_official 532:fe11edbda85c 1457 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
mbed_official 532:fe11edbda85c 1458 {
mbed_official 532:fe11edbda85c 1459 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
mbed_official 532:fe11edbda85c 1460 {
mbed_official 532:fe11edbda85c 1461 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 1462 }
mbed_official 532:fe11edbda85c 1463 }
mbed_official 532:fe11edbda85c 1464 }
mbed_official 532:fe11edbda85c 1465 }
mbed_official 532:fe11edbda85c 1466 else
mbed_official 532:fe11edbda85c 1467 {
mbed_official 532:fe11edbda85c 1468 return HAL_ERROR;
mbed_official 532:fe11edbda85c 1469 }
mbed_official 532:fe11edbda85c 1470 }
mbed_official 532:fe11edbda85c 1471 return HAL_OK;
mbed_official 532:fe11edbda85c 1472 }
mbed_official 532:fe11edbda85c 1473
mbed_official 532:fe11edbda85c 1474 /**
mbed_official 532:fe11edbda85c 1475 * @brief Configures the RCC_OscInitStruct according to the internal
mbed_official 532:fe11edbda85c 1476 * RCC configuration registers.
mbed_official 532:fe11edbda85c 1477 * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that will be configured.
mbed_official 532:fe11edbda85c 1478 *
mbed_official 532:fe11edbda85c 1479 * @note This function is only available in case of STM32F446xx devices.
mbed_official 532:fe11edbda85c 1480 * @note This function add the PLL/PLLR factor management
mbed_official 532:fe11edbda85c 1481 * @retval None
mbed_official 532:fe11edbda85c 1482 */
mbed_official 532:fe11edbda85c 1483 void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
mbed_official 532:fe11edbda85c 1484 {
mbed_official 532:fe11edbda85c 1485 /* Set all possible values for the Oscillator type parameter ---------------*/
mbed_official 532:fe11edbda85c 1486 RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
mbed_official 532:fe11edbda85c 1487
mbed_official 532:fe11edbda85c 1488 /* Get the HSE configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 1489 if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
mbed_official 532:fe11edbda85c 1490 {
mbed_official 532:fe11edbda85c 1491 RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
mbed_official 532:fe11edbda85c 1492 }
mbed_official 532:fe11edbda85c 1493 else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
mbed_official 532:fe11edbda85c 1494 {
mbed_official 532:fe11edbda85c 1495 RCC_OscInitStruct->HSEState = RCC_HSE_ON;
mbed_official 532:fe11edbda85c 1496 }
mbed_official 532:fe11edbda85c 1497 else
mbed_official 532:fe11edbda85c 1498 {
mbed_official 532:fe11edbda85c 1499 RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
mbed_official 532:fe11edbda85c 1500 }
mbed_official 532:fe11edbda85c 1501
mbed_official 532:fe11edbda85c 1502 /* Get the HSI configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 1503 if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
mbed_official 532:fe11edbda85c 1504 {
mbed_official 532:fe11edbda85c 1505 RCC_OscInitStruct->HSIState = RCC_HSI_ON;
mbed_official 532:fe11edbda85c 1506 }
mbed_official 532:fe11edbda85c 1507 else
mbed_official 532:fe11edbda85c 1508 {
mbed_official 532:fe11edbda85c 1509 RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
mbed_official 532:fe11edbda85c 1510 }
mbed_official 532:fe11edbda85c 1511
mbed_official 532:fe11edbda85c 1512 RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR &RCC_CR_HSITRIM) >> POSITION_VAL(RCC_CR_HSITRIM));
mbed_official 532:fe11edbda85c 1513
mbed_official 532:fe11edbda85c 1514 /* Get the LSE configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 1515 if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
mbed_official 532:fe11edbda85c 1516 {
mbed_official 532:fe11edbda85c 1517 RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
mbed_official 532:fe11edbda85c 1518 }
mbed_official 532:fe11edbda85c 1519 else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
mbed_official 532:fe11edbda85c 1520 {
mbed_official 532:fe11edbda85c 1521 RCC_OscInitStruct->LSEState = RCC_LSE_ON;
mbed_official 532:fe11edbda85c 1522 }
mbed_official 532:fe11edbda85c 1523 else
mbed_official 532:fe11edbda85c 1524 {
mbed_official 532:fe11edbda85c 1525 RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
mbed_official 532:fe11edbda85c 1526 }
mbed_official 532:fe11edbda85c 1527
mbed_official 532:fe11edbda85c 1528 /* Get the LSI configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 1529 if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
mbed_official 532:fe11edbda85c 1530 {
mbed_official 532:fe11edbda85c 1531 RCC_OscInitStruct->LSIState = RCC_LSI_ON;
mbed_official 532:fe11edbda85c 1532 }
mbed_official 532:fe11edbda85c 1533 else
mbed_official 532:fe11edbda85c 1534 {
mbed_official 532:fe11edbda85c 1535 RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
mbed_official 532:fe11edbda85c 1536 }
mbed_official 532:fe11edbda85c 1537
mbed_official 532:fe11edbda85c 1538 /* Get the PLL configuration -----------------------------------------------*/
mbed_official 532:fe11edbda85c 1539 if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
mbed_official 532:fe11edbda85c 1540 {
mbed_official 532:fe11edbda85c 1541 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
mbed_official 532:fe11edbda85c 1542 }
mbed_official 532:fe11edbda85c 1543 else
mbed_official 532:fe11edbda85c 1544 {
mbed_official 532:fe11edbda85c 1545 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
mbed_official 532:fe11edbda85c 1546 }
mbed_official 532:fe11edbda85c 1547 RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
mbed_official 532:fe11edbda85c 1548 RCC_OscInitStruct->PLL.PLLM = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
mbed_official 532:fe11edbda85c 1549 RCC_OscInitStruct->PLL.PLLN = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN));
mbed_official 532:fe11edbda85c 1550 RCC_OscInitStruct->PLL.PLLP = (uint32_t)((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) + RCC_PLLCFGR_PLLP_0) << 1) >> POSITION_VAL(RCC_PLLCFGR_PLLP));
mbed_official 532:fe11edbda85c 1551 RCC_OscInitStruct->PLL.PLLQ = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLQ) >> POSITION_VAL(RCC_PLLCFGR_PLLQ));
mbed_official 532:fe11edbda85c 1552 RCC_OscInitStruct->PLL.PLLR = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> POSITION_VAL(RCC_PLLCFGR_PLLR));
mbed_official 532:fe11edbda85c 1553 }
mbed_official 532:fe11edbda85c 1554
mbed_official 532:fe11edbda85c 1555 /**
mbed_official 532:fe11edbda85c 1556 * @brief Returns the SYSCLK frequency
mbed_official 532:fe11edbda85c 1557 *
mbed_official 532:fe11edbda85c 1558 * @note This function is only available in case of STM32F446xx devices.
mbed_official 532:fe11edbda85c 1559 * @note This function add the PLL/PLLR System clock source
mbed_official 532:fe11edbda85c 1560 *
mbed_official 532:fe11edbda85c 1561 * @note The system frequency computed by this function is not the real
mbed_official 532:fe11edbda85c 1562 * frequency in the chip. It is calculated based on the predefined
mbed_official 532:fe11edbda85c 1563 * constant and the selected clock source:
mbed_official 532:fe11edbda85c 1564 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
mbed_official 532:fe11edbda85c 1565 * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
mbed_official 532:fe11edbda85c 1566 * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(**)
mbed_official 532:fe11edbda85c 1567 * or HSI_VALUE(*) multiplied/divided by the PLL factors.
mbed_official 532:fe11edbda85c 1568 * @note (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
mbed_official 532:fe11edbda85c 1569 * 16 MHz) but the real value may vary depending on the variations
mbed_official 532:fe11edbda85c 1570 * in voltage and temperature.
mbed_official 532:fe11edbda85c 1571 * @note (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
mbed_official 532:fe11edbda85c 1572 * 25 MHz), user has to ensure that HSE_VALUE is same as the real
mbed_official 532:fe11edbda85c 1573 * frequency of the crystal used. Otherwise, this function may
mbed_official 532:fe11edbda85c 1574 * have wrong result.
mbed_official 532:fe11edbda85c 1575 *
mbed_official 532:fe11edbda85c 1576 * @note The result of this function could be not correct when using fractional
mbed_official 532:fe11edbda85c 1577 * value for HSE crystal.
mbed_official 532:fe11edbda85c 1578 *
mbed_official 532:fe11edbda85c 1579 * @note This function can be used by the user application to compute the
mbed_official 532:fe11edbda85c 1580 * baudrate for the communication peripherals or configure other parameters.
mbed_official 532:fe11edbda85c 1581 *
mbed_official 532:fe11edbda85c 1582 * @note Each time SYSCLK changes, this function must be called to update the
mbed_official 532:fe11edbda85c 1583 * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect.
mbed_official 532:fe11edbda85c 1584 *
mbed_official 532:fe11edbda85c 1585 *
mbed_official 532:fe11edbda85c 1586 * @retval SYSCLK frequency
mbed_official 532:fe11edbda85c 1587 */
mbed_official 532:fe11edbda85c 1588 uint32_t HAL_RCC_GetSysClockFreq(void)
mbed_official 532:fe11edbda85c 1589 {
mbed_official 532:fe11edbda85c 1590 uint32_t pllm = 0;
mbed_official 532:fe11edbda85c 1591 uint32_t pllvco = 0;
mbed_official 532:fe11edbda85c 1592 uint32_t pllp = 0;
mbed_official 532:fe11edbda85c 1593 uint32_t pllr = 0;
mbed_official 532:fe11edbda85c 1594 uint32_t sysclockfreq = 0;
mbed_official 532:fe11edbda85c 1595
mbed_official 532:fe11edbda85c 1596 /* Get SYSCLK source -------------------------------------------------------*/
mbed_official 532:fe11edbda85c 1597 switch (RCC->CFGR & RCC_CFGR_SWS)
mbed_official 532:fe11edbda85c 1598 {
mbed_official 532:fe11edbda85c 1599 case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
mbed_official 532:fe11edbda85c 1600 {
mbed_official 532:fe11edbda85c 1601 sysclockfreq = HSI_VALUE;
mbed_official 532:fe11edbda85c 1602 break;
mbed_official 532:fe11edbda85c 1603 }
mbed_official 532:fe11edbda85c 1604 case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
mbed_official 532:fe11edbda85c 1605 {
mbed_official 532:fe11edbda85c 1606 sysclockfreq = HSE_VALUE;
mbed_official 532:fe11edbda85c 1607 break;
mbed_official 532:fe11edbda85c 1608 }
mbed_official 532:fe11edbda85c 1609 case RCC_CFGR_SWS_PLL: /* PLL/PLLP used as system clock source */
mbed_official 532:fe11edbda85c 1610 {
mbed_official 532:fe11edbda85c 1611 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
mbed_official 532:fe11edbda85c 1612 SYSCLK = PLL_VCO / PLLP */
mbed_official 532:fe11edbda85c 1613 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
mbed_official 532:fe11edbda85c 1614 if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 1615 {
mbed_official 532:fe11edbda85c 1616 /* HSE used as PLL clock source */
mbed_official 532:fe11edbda85c 1617 pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
mbed_official 532:fe11edbda85c 1618 }
mbed_official 532:fe11edbda85c 1619 else
mbed_official 532:fe11edbda85c 1620 {
mbed_official 532:fe11edbda85c 1621 /* HSI used as PLL clock source */
mbed_official 532:fe11edbda85c 1622 pllvco = ((HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
mbed_official 532:fe11edbda85c 1623 }
mbed_official 532:fe11edbda85c 1624 pllp = ((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> POSITION_VAL(RCC_PLLCFGR_PLLP)) + 1 ) *2);
mbed_official 532:fe11edbda85c 1625
mbed_official 532:fe11edbda85c 1626 sysclockfreq = pllvco/pllp;
mbed_official 532:fe11edbda85c 1627 break;
mbed_official 532:fe11edbda85c 1628 }
mbed_official 532:fe11edbda85c 1629 case RCC_CFGR_SWS_PLLR: /* PLL/PLLR used as system clock source */
mbed_official 532:fe11edbda85c 1630 {
mbed_official 532:fe11edbda85c 1631 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
mbed_official 532:fe11edbda85c 1632 SYSCLK = PLL_VCO / PLLR */
mbed_official 532:fe11edbda85c 1633 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
mbed_official 532:fe11edbda85c 1634 if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
mbed_official 532:fe11edbda85c 1635 {
mbed_official 532:fe11edbda85c 1636 /* HSE used as PLL clock source */
mbed_official 532:fe11edbda85c 1637 pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
mbed_official 532:fe11edbda85c 1638 }
mbed_official 532:fe11edbda85c 1639 else
mbed_official 532:fe11edbda85c 1640 {
mbed_official 532:fe11edbda85c 1641 /* HSI used as PLL clock source */
mbed_official 532:fe11edbda85c 1642 pllvco = ((HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
mbed_official 532:fe11edbda85c 1643 }
mbed_official 532:fe11edbda85c 1644 pllr = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> POSITION_VAL(RCC_PLLCFGR_PLLR));
mbed_official 532:fe11edbda85c 1645
mbed_official 532:fe11edbda85c 1646 sysclockfreq = pllvco/pllr;
mbed_official 532:fe11edbda85c 1647 break;
mbed_official 532:fe11edbda85c 1648 }
mbed_official 532:fe11edbda85c 1649 default:
mbed_official 532:fe11edbda85c 1650 {
mbed_official 532:fe11edbda85c 1651 sysclockfreq = HSI_VALUE;
mbed_official 532:fe11edbda85c 1652 break;
mbed_official 532:fe11edbda85c 1653 }
mbed_official 532:fe11edbda85c 1654 }
mbed_official 532:fe11edbda85c 1655 return sysclockfreq;
mbed_official 532:fe11edbda85c 1656 }
mbed_official 532:fe11edbda85c 1657 #endif /* STM32F446xx */
mbed_official 235:685d5f11838f 1658
mbed_official 235:685d5f11838f 1659 /**
mbed_official 235:685d5f11838f 1660 * @}
mbed_official 235:685d5f11838f 1661 */
mbed_official 235:685d5f11838f 1662
mbed_official 235:685d5f11838f 1663 /**
mbed_official 235:685d5f11838f 1664 * @}
mbed_official 235:685d5f11838f 1665 */
mbed_official 235:685d5f11838f 1666
mbed_official 235:685d5f11838f 1667 #endif /* HAL_RCC_MODULE_ENABLED */
mbed_official 235:685d5f11838f 1668 /**
mbed_official 235:685d5f11838f 1669 * @}
mbed_official 235:685d5f11838f 1670 */
mbed_official 235:685d5f11838f 1671
mbed_official 235:685d5f11838f 1672 /**
mbed_official 235:685d5f11838f 1673 * @}
mbed_official 235:685d5f11838f 1674 */
mbed_official 235:685d5f11838f 1675
mbed_official 235:685d5f11838f 1676 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/