mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F334C8/stm32f3xx_hal_rcc_ex.c@381:5460fc57b6e4, 2014-11-03 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Nov 03 10:30:07 2014 +0000
- Revision:
- 381:5460fc57b6e4
Synchronized with git revision 02478cd1f27fc7b9643486472635eb515b2bca81
Full URL: https://github.com/mbedmicro/mbed/commit/02478cd1f27fc7b9643486472635eb515b2bca81/
Target: LPC1549 - Fix serial interrupt issues (issue report #616)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 381:5460fc57b6e4 | 1 | /** |
mbed_official | 381:5460fc57b6e4 | 2 | ****************************************************************************** |
mbed_official | 381:5460fc57b6e4 | 3 | * @file stm32f3xx_hal_rcc_ex.c |
mbed_official | 381:5460fc57b6e4 | 4 | * @author MCD Application Team |
mbed_official | 381:5460fc57b6e4 | 5 | * @version V1.1.0 |
mbed_official | 381:5460fc57b6e4 | 6 | * @date 12-Sept-2014 |
mbed_official | 381:5460fc57b6e4 | 7 | * @brief Extended RCC HAL module driver |
mbed_official | 381:5460fc57b6e4 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 381:5460fc57b6e4 | 9 | * functionalities RCC Extended peripheral: |
mbed_official | 381:5460fc57b6e4 | 10 | * + Extended Clock Source configuration functions |
mbed_official | 381:5460fc57b6e4 | 11 | * |
mbed_official | 381:5460fc57b6e4 | 12 | ****************************************************************************** |
mbed_official | 381:5460fc57b6e4 | 13 | * @attention |
mbed_official | 381:5460fc57b6e4 | 14 | * |
mbed_official | 381:5460fc57b6e4 | 15 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 381:5460fc57b6e4 | 16 | * |
mbed_official | 381:5460fc57b6e4 | 17 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 381:5460fc57b6e4 | 18 | * are permitted provided that the following conditions are met: |
mbed_official | 381:5460fc57b6e4 | 19 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 381:5460fc57b6e4 | 20 | * this list of conditions and the following disclaimer. |
mbed_official | 381:5460fc57b6e4 | 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 381:5460fc57b6e4 | 22 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 381:5460fc57b6e4 | 23 | * and/or other materials provided with the distribution. |
mbed_official | 381:5460fc57b6e4 | 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 381:5460fc57b6e4 | 25 | * may be used to endorse or promote products derived from this software |
mbed_official | 381:5460fc57b6e4 | 26 | * without specific prior written permission. |
mbed_official | 381:5460fc57b6e4 | 27 | * |
mbed_official | 381:5460fc57b6e4 | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 381:5460fc57b6e4 | 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 381:5460fc57b6e4 | 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 381:5460fc57b6e4 | 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 381:5460fc57b6e4 | 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 381:5460fc57b6e4 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 381:5460fc57b6e4 | 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 381:5460fc57b6e4 | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 381:5460fc57b6e4 | 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 381:5460fc57b6e4 | 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 381:5460fc57b6e4 | 38 | * |
mbed_official | 381:5460fc57b6e4 | 39 | ****************************************************************************** |
mbed_official | 381:5460fc57b6e4 | 40 | */ |
mbed_official | 381:5460fc57b6e4 | 41 | |
mbed_official | 381:5460fc57b6e4 | 42 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 43 | #include "stm32f3xx_hal.h" |
mbed_official | 381:5460fc57b6e4 | 44 | |
mbed_official | 381:5460fc57b6e4 | 45 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 381:5460fc57b6e4 | 46 | * @{ |
mbed_official | 381:5460fc57b6e4 | 47 | */ |
mbed_official | 381:5460fc57b6e4 | 48 | |
mbed_official | 381:5460fc57b6e4 | 49 | /** @defgroup RCCEx RCC Extended HAL module driver |
mbed_official | 381:5460fc57b6e4 | 50 | * @brief RCC Extended HAL module driver. |
mbed_official | 381:5460fc57b6e4 | 51 | * @{ |
mbed_official | 381:5460fc57b6e4 | 52 | */ |
mbed_official | 381:5460fc57b6e4 | 53 | |
mbed_official | 381:5460fc57b6e4 | 54 | #ifdef HAL_RCC_MODULE_ENABLED |
mbed_official | 381:5460fc57b6e4 | 55 | |
mbed_official | 381:5460fc57b6e4 | 56 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 57 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 58 | /** @defgroup RCCEx_Private_Define RCC Extended Private Define |
mbed_official | 381:5460fc57b6e4 | 59 | * @{ |
mbed_official | 381:5460fc57b6e4 | 60 | */ |
mbed_official | 381:5460fc57b6e4 | 61 | #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT |
mbed_official | 381:5460fc57b6e4 | 62 | #define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ |
mbed_official | 381:5460fc57b6e4 | 63 | #define LSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ |
mbed_official | 381:5460fc57b6e4 | 64 | #define PLL_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ |
mbed_official | 381:5460fc57b6e4 | 65 | #define CLOCKSWITCH_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */ |
mbed_official | 381:5460fc57b6e4 | 66 | /** |
mbed_official | 381:5460fc57b6e4 | 67 | * @} |
mbed_official | 381:5460fc57b6e4 | 68 | */ |
mbed_official | 381:5460fc57b6e4 | 69 | |
mbed_official | 381:5460fc57b6e4 | 70 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 71 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 72 | /** @defgroup RCCEx_Private_Variables RCC Extented Private Variables |
mbed_official | 381:5460fc57b6e4 | 73 | * @{ |
mbed_official | 381:5460fc57b6e4 | 74 | */ |
mbed_official | 381:5460fc57b6e4 | 75 | const uint8_t PLLMULFactorTable[16] = { 2, 3, 4, 5, 6, 7, 8, 9, |
mbed_official | 381:5460fc57b6e4 | 76 | 10, 11, 12, 13, 14, 15, 16, 16}; |
mbed_official | 381:5460fc57b6e4 | 77 | const uint8_t PredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, |
mbed_official | 381:5460fc57b6e4 | 78 | 9,10, 11, 12, 13, 14, 15, 16}; |
mbed_official | 381:5460fc57b6e4 | 79 | /** |
mbed_official | 381:5460fc57b6e4 | 80 | * @} |
mbed_official | 381:5460fc57b6e4 | 81 | */ |
mbed_official | 381:5460fc57b6e4 | 82 | |
mbed_official | 381:5460fc57b6e4 | 83 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 84 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 85 | |
mbed_official | 381:5460fc57b6e4 | 86 | /** @defgroup RCCEx_Exported_Functions RCC Extended Exported Functions |
mbed_official | 381:5460fc57b6e4 | 87 | * @{ |
mbed_official | 381:5460fc57b6e4 | 88 | */ |
mbed_official | 381:5460fc57b6e4 | 89 | |
mbed_official | 381:5460fc57b6e4 | 90 | /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions |
mbed_official | 381:5460fc57b6e4 | 91 | * @brief Extended Peripheral Control functions |
mbed_official | 381:5460fc57b6e4 | 92 | * |
mbed_official | 381:5460fc57b6e4 | 93 | @verbatim |
mbed_official | 381:5460fc57b6e4 | 94 | =============================================================================== |
mbed_official | 381:5460fc57b6e4 | 95 | ##### Extended Peripheral Control functions ##### |
mbed_official | 381:5460fc57b6e4 | 96 | =============================================================================== |
mbed_official | 381:5460fc57b6e4 | 97 | [..] |
mbed_official | 381:5460fc57b6e4 | 98 | This subsection provides a set of functions allowing to control the RCC Clocks |
mbed_official | 381:5460fc57b6e4 | 99 | frequencies. |
mbed_official | 381:5460fc57b6e4 | 100 | [..] |
mbed_official | 381:5460fc57b6e4 | 101 | (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to |
mbed_official | 381:5460fc57b6e4 | 102 | select the RTC clock source; in this case the Backup domain will be reset in |
mbed_official | 381:5460fc57b6e4 | 103 | order to modify the RTC Clock source, as consequence RTC registers (including |
mbed_official | 381:5460fc57b6e4 | 104 | the backup registers) and RCC_BDCR register are set to their reset values. |
mbed_official | 381:5460fc57b6e4 | 105 | |
mbed_official | 381:5460fc57b6e4 | 106 | @endverbatim |
mbed_official | 381:5460fc57b6e4 | 107 | * @{ |
mbed_official | 381:5460fc57b6e4 | 108 | */ |
mbed_official | 381:5460fc57b6e4 | 109 | |
mbed_official | 381:5460fc57b6e4 | 110 | /** |
mbed_official | 381:5460fc57b6e4 | 111 | * @brief Initializes the RCC extended peripherals clocks according to the specified |
mbed_official | 381:5460fc57b6e4 | 112 | * parameters in the RCC_PeriphCLKInitTypeDef. |
mbed_official | 381:5460fc57b6e4 | 113 | * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that |
mbed_official | 381:5460fc57b6e4 | 114 | * contains the configuration information for the Extended Peripherals clocks |
mbed_official | 381:5460fc57b6e4 | 115 | * (ADC, CEC, I2C, I2S, SDADC, HRTIM, TIM, USART, RTC and USB). |
mbed_official | 381:5460fc57b6e4 | 116 | * |
mbed_official | 381:5460fc57b6e4 | 117 | * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select |
mbed_official | 381:5460fc57b6e4 | 118 | * the RTC clock source; in this case the Backup domain will be reset in |
mbed_official | 381:5460fc57b6e4 | 119 | * order to modify the RTC Clock source, as consequence RTC registers (including |
mbed_official | 381:5460fc57b6e4 | 120 | * the backup registers) and RCC_BDCR register are set to their reset values. |
mbed_official | 381:5460fc57b6e4 | 121 | * |
mbed_official | 381:5460fc57b6e4 | 122 | * @retval HAL status |
mbed_official | 381:5460fc57b6e4 | 123 | */ |
mbed_official | 381:5460fc57b6e4 | 124 | HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) |
mbed_official | 381:5460fc57b6e4 | 125 | { |
mbed_official | 381:5460fc57b6e4 | 126 | uint32_t tickstart = 0; |
mbed_official | 381:5460fc57b6e4 | 127 | uint32_t tmpreg = 0; |
mbed_official | 381:5460fc57b6e4 | 128 | |
mbed_official | 381:5460fc57b6e4 | 129 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 130 | assert_param(IS_RCC_PERIPHCLK(PeriphClkInit->PeriphClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 131 | |
mbed_official | 381:5460fc57b6e4 | 132 | |
mbed_official | 381:5460fc57b6e4 | 133 | /*---------------------------- RTC configuration -------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 134 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC)) |
mbed_official | 381:5460fc57b6e4 | 135 | { |
mbed_official | 381:5460fc57b6e4 | 136 | /* Enable Power Clock*/ |
mbed_official | 381:5460fc57b6e4 | 137 | __PWR_CLK_ENABLE(); |
mbed_official | 381:5460fc57b6e4 | 138 | |
mbed_official | 381:5460fc57b6e4 | 139 | /* Enable write access to Backup domain */ |
mbed_official | 381:5460fc57b6e4 | 140 | SET_BIT(PWR->CR, PWR_CR_DBP); |
mbed_official | 381:5460fc57b6e4 | 141 | |
mbed_official | 381:5460fc57b6e4 | 142 | /* Wait for Backup domain Write protection disable */ |
mbed_official | 381:5460fc57b6e4 | 143 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 144 | |
mbed_official | 381:5460fc57b6e4 | 145 | while((PWR->CR & PWR_CR_DBP) == RESET) |
mbed_official | 381:5460fc57b6e4 | 146 | { |
mbed_official | 381:5460fc57b6e4 | 147 | if((HAL_GetTick()-tickstart) > DBP_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 148 | { |
mbed_official | 381:5460fc57b6e4 | 149 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 150 | } |
mbed_official | 381:5460fc57b6e4 | 151 | } |
mbed_official | 381:5460fc57b6e4 | 152 | |
mbed_official | 381:5460fc57b6e4 | 153 | /* Reset the Backup domain only if the RTC Clock source selction is modified */ |
mbed_official | 381:5460fc57b6e4 | 154 | if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)) |
mbed_official | 381:5460fc57b6e4 | 155 | { |
mbed_official | 381:5460fc57b6e4 | 156 | /* Store the content of BDCR register before the reset of Backup Domain */ |
mbed_official | 381:5460fc57b6e4 | 157 | tmpreg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL)); |
mbed_official | 381:5460fc57b6e4 | 158 | /* RTC Clock selection can be changed only if the Backup Domain is reset */ |
mbed_official | 381:5460fc57b6e4 | 159 | __HAL_RCC_BACKUPRESET_FORCE(); |
mbed_official | 381:5460fc57b6e4 | 160 | __HAL_RCC_BACKUPRESET_RELEASE(); |
mbed_official | 381:5460fc57b6e4 | 161 | /* Restore the Content of BDCR register */ |
mbed_official | 381:5460fc57b6e4 | 162 | RCC->BDCR = tmpreg; |
mbed_official | 381:5460fc57b6e4 | 163 | } |
mbed_official | 381:5460fc57b6e4 | 164 | |
mbed_official | 381:5460fc57b6e4 | 165 | /* If LSE is selected as RTC clock source, wait for LSE reactivation */ |
mbed_official | 381:5460fc57b6e4 | 166 | if(PeriphClkInit->RTCClockSelection == RCC_RTCCLKSOURCE_LSE) |
mbed_official | 381:5460fc57b6e4 | 167 | { |
mbed_official | 381:5460fc57b6e4 | 168 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 169 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 170 | |
mbed_official | 381:5460fc57b6e4 | 171 | /* Wait till LSE is ready */ |
mbed_official | 381:5460fc57b6e4 | 172 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 173 | { |
mbed_official | 381:5460fc57b6e4 | 174 | if((HAL_GetTick()-tickstart) > LSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 175 | { |
mbed_official | 381:5460fc57b6e4 | 176 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 177 | } |
mbed_official | 381:5460fc57b6e4 | 178 | } |
mbed_official | 381:5460fc57b6e4 | 179 | } |
mbed_official | 381:5460fc57b6e4 | 180 | __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection); |
mbed_official | 381:5460fc57b6e4 | 181 | } |
mbed_official | 381:5460fc57b6e4 | 182 | |
mbed_official | 381:5460fc57b6e4 | 183 | /*------------------------------- USART1 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 184 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) |
mbed_official | 381:5460fc57b6e4 | 185 | { |
mbed_official | 381:5460fc57b6e4 | 186 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 187 | assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 188 | |
mbed_official | 381:5460fc57b6e4 | 189 | /* Configure the USART1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 190 | __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 191 | } |
mbed_official | 381:5460fc57b6e4 | 192 | |
mbed_official | 381:5460fc57b6e4 | 193 | /*----------------------------- USART2 Configuration --------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 194 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) |
mbed_official | 381:5460fc57b6e4 | 195 | { |
mbed_official | 381:5460fc57b6e4 | 196 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 197 | assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 198 | |
mbed_official | 381:5460fc57b6e4 | 199 | /* Configure the USART2 clock source */ |
mbed_official | 381:5460fc57b6e4 | 200 | __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 201 | } |
mbed_official | 381:5460fc57b6e4 | 202 | |
mbed_official | 381:5460fc57b6e4 | 203 | /*------------------------------ USART3 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 204 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) |
mbed_official | 381:5460fc57b6e4 | 205 | { |
mbed_official | 381:5460fc57b6e4 | 206 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 207 | assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 208 | |
mbed_official | 381:5460fc57b6e4 | 209 | /* Configure the USART3 clock source */ |
mbed_official | 381:5460fc57b6e4 | 210 | __HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 211 | } |
mbed_official | 381:5460fc57b6e4 | 212 | |
mbed_official | 381:5460fc57b6e4 | 213 | /*------------------------------ I2C1 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 214 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) |
mbed_official | 381:5460fc57b6e4 | 215 | { |
mbed_official | 381:5460fc57b6e4 | 216 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 217 | assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 218 | |
mbed_official | 381:5460fc57b6e4 | 219 | /* Configure the I2C1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 220 | __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 221 | } |
mbed_official | 381:5460fc57b6e4 | 222 | |
mbed_official | 381:5460fc57b6e4 | 223 | #if defined(STM32F302xE) || defined(STM32F303xE) || \ |
mbed_official | 381:5460fc57b6e4 | 224 | defined(STM32F302xC) || defined(STM32F303xC) || \ |
mbed_official | 381:5460fc57b6e4 | 225 | defined(STM32F302x8) || \ |
mbed_official | 381:5460fc57b6e4 | 226 | defined(STM32F373xC) |
mbed_official | 381:5460fc57b6e4 | 227 | /*------------------------------ USB Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 228 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) |
mbed_official | 381:5460fc57b6e4 | 229 | { |
mbed_official | 381:5460fc57b6e4 | 230 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 231 | assert_param(IS_RCC_USBCLKSOURCE(PeriphClkInit->USBClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 232 | |
mbed_official | 381:5460fc57b6e4 | 233 | /* Configure the USB clock source */ |
mbed_official | 381:5460fc57b6e4 | 234 | __HAL_RCC_USB_CONFIG(PeriphClkInit->USBClockSelection); |
mbed_official | 381:5460fc57b6e4 | 235 | } |
mbed_official | 381:5460fc57b6e4 | 236 | |
mbed_official | 381:5460fc57b6e4 | 237 | #endif /* STM32F302xE || STM32F303xE || */ |
mbed_official | 381:5460fc57b6e4 | 238 | /* STM32F302xC || STM32F303xC || */ |
mbed_official | 381:5460fc57b6e4 | 239 | /* STM32F302x8 || */ |
mbed_official | 381:5460fc57b6e4 | 240 | /* STM32F373xC */ |
mbed_official | 381:5460fc57b6e4 | 241 | |
mbed_official | 381:5460fc57b6e4 | 242 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 243 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 244 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 245 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 246 | |
mbed_official | 381:5460fc57b6e4 | 247 | /*------------------------------ I2C2 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 248 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) |
mbed_official | 381:5460fc57b6e4 | 249 | { |
mbed_official | 381:5460fc57b6e4 | 250 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 251 | assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 252 | |
mbed_official | 381:5460fc57b6e4 | 253 | /* Configure the I2C2 clock source */ |
mbed_official | 381:5460fc57b6e4 | 254 | __HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 255 | } |
mbed_official | 381:5460fc57b6e4 | 256 | |
mbed_official | 381:5460fc57b6e4 | 257 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 258 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 259 | /* STM32F301x8 || STM32F302x8 || STM32F318xx || */ |
mbed_official | 381:5460fc57b6e4 | 260 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 261 | |
mbed_official | 381:5460fc57b6e4 | 262 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 263 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 264 | |
mbed_official | 381:5460fc57b6e4 | 265 | /*------------------------------ I2C3 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 266 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) |
mbed_official | 381:5460fc57b6e4 | 267 | { |
mbed_official | 381:5460fc57b6e4 | 268 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 269 | assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 270 | |
mbed_official | 381:5460fc57b6e4 | 271 | /* Configure the I2C3 clock source */ |
mbed_official | 381:5460fc57b6e4 | 272 | __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 273 | } |
mbed_official | 381:5460fc57b6e4 | 274 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 275 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 276 | |
mbed_official | 381:5460fc57b6e4 | 277 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 278 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 279 | |
mbed_official | 381:5460fc57b6e4 | 280 | /*------------------------------ UART4 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 281 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) |
mbed_official | 381:5460fc57b6e4 | 282 | { |
mbed_official | 381:5460fc57b6e4 | 283 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 284 | assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 285 | |
mbed_official | 381:5460fc57b6e4 | 286 | /* Configure the UART4 clock source */ |
mbed_official | 381:5460fc57b6e4 | 287 | __HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 288 | } |
mbed_official | 381:5460fc57b6e4 | 289 | |
mbed_official | 381:5460fc57b6e4 | 290 | /*------------------------------ UART5 Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 291 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5) |
mbed_official | 381:5460fc57b6e4 | 292 | { |
mbed_official | 381:5460fc57b6e4 | 293 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 294 | assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 295 | |
mbed_official | 381:5460fc57b6e4 | 296 | /* Configure the UART5 clock source */ |
mbed_official | 381:5460fc57b6e4 | 297 | __HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 298 | } |
mbed_official | 381:5460fc57b6e4 | 299 | |
mbed_official | 381:5460fc57b6e4 | 300 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 301 | /* STM32F302xC || STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 302 | |
mbed_official | 381:5460fc57b6e4 | 303 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 304 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 305 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 306 | /*------------------------------ I2S Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 307 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) |
mbed_official | 381:5460fc57b6e4 | 308 | { |
mbed_official | 381:5460fc57b6e4 | 309 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 310 | assert_param(IS_RCC_I2SCLKSOURCE(PeriphClkInit->I2sClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 311 | |
mbed_official | 381:5460fc57b6e4 | 312 | /* Configure the I2S clock source */ |
mbed_official | 381:5460fc57b6e4 | 313 | __HAL_RCC_I2S_CONFIG(PeriphClkInit->I2sClockSelection); |
mbed_official | 381:5460fc57b6e4 | 314 | } |
mbed_official | 381:5460fc57b6e4 | 315 | |
mbed_official | 381:5460fc57b6e4 | 316 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 317 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 318 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 319 | |
mbed_official | 381:5460fc57b6e4 | 320 | #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 321 | |
mbed_official | 381:5460fc57b6e4 | 322 | /*------------------------------ ADC1 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 323 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC1) == RCC_PERIPHCLK_ADC1) |
mbed_official | 381:5460fc57b6e4 | 324 | { |
mbed_official | 381:5460fc57b6e4 | 325 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 326 | assert_param(IS_RCC_ADC1PLLCLK_DIV(PeriphClkInit->Adc1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 327 | |
mbed_official | 381:5460fc57b6e4 | 328 | /* Configure the ADC1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 329 | __HAL_RCC_ADC1_CONFIG(PeriphClkInit->Adc1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 330 | } |
mbed_official | 381:5460fc57b6e4 | 331 | |
mbed_official | 381:5460fc57b6e4 | 332 | #endif /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 333 | |
mbed_official | 381:5460fc57b6e4 | 334 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 335 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 336 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) |
mbed_official | 381:5460fc57b6e4 | 337 | |
mbed_official | 381:5460fc57b6e4 | 338 | /*------------------------------ ADC1 & ADC2 clock Configuration -------------*/ |
mbed_official | 381:5460fc57b6e4 | 339 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC12) == RCC_PERIPHCLK_ADC12) |
mbed_official | 381:5460fc57b6e4 | 340 | { |
mbed_official | 381:5460fc57b6e4 | 341 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 342 | assert_param(IS_RCC_ADC12PLLCLK_DIV(PeriphClkInit->Adc12ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 343 | |
mbed_official | 381:5460fc57b6e4 | 344 | /* Configure the ADC12 clock source */ |
mbed_official | 381:5460fc57b6e4 | 345 | __HAL_RCC_ADC12_CONFIG(PeriphClkInit->Adc12ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 346 | } |
mbed_official | 381:5460fc57b6e4 | 347 | |
mbed_official | 381:5460fc57b6e4 | 348 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 349 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 350 | /* STM32F303x8 || STM32F334x8 || STM32F328xx */ |
mbed_official | 381:5460fc57b6e4 | 351 | |
mbed_official | 381:5460fc57b6e4 | 352 | #if defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 353 | defined(STM32F303xC) || defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 354 | |
mbed_official | 381:5460fc57b6e4 | 355 | /*------------------------------ ADC3 & ADC4 clock Configuration -------------*/ |
mbed_official | 381:5460fc57b6e4 | 356 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC34) == RCC_PERIPHCLK_ADC34) |
mbed_official | 381:5460fc57b6e4 | 357 | { |
mbed_official | 381:5460fc57b6e4 | 358 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 359 | assert_param(IS_RCC_ADC34PLLCLK_DIV(PeriphClkInit->Adc34ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 360 | |
mbed_official | 381:5460fc57b6e4 | 361 | /* Configure the ADC34 clock source */ |
mbed_official | 381:5460fc57b6e4 | 362 | __HAL_RCC_ADC34_CONFIG(PeriphClkInit->Adc34ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 363 | } |
mbed_official | 381:5460fc57b6e4 | 364 | |
mbed_official | 381:5460fc57b6e4 | 365 | #endif /* STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 366 | /* STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 367 | |
mbed_official | 381:5460fc57b6e4 | 368 | #if defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 369 | |
mbed_official | 381:5460fc57b6e4 | 370 | /*------------------------------ ADC1 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 371 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC1) == RCC_PERIPHCLK_ADC1) |
mbed_official | 381:5460fc57b6e4 | 372 | { |
mbed_official | 381:5460fc57b6e4 | 373 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 374 | assert_param(IS_RCC_ADC1PCLK2_DIV(PeriphClkInit->Adc1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 375 | |
mbed_official | 381:5460fc57b6e4 | 376 | /* Configure the ADC1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 377 | __HAL_RCC_ADC1_CONFIG(PeriphClkInit->Adc1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 378 | } |
mbed_official | 381:5460fc57b6e4 | 379 | |
mbed_official | 381:5460fc57b6e4 | 380 | #endif /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 381 | |
mbed_official | 381:5460fc57b6e4 | 382 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 383 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 384 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 385 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 386 | |
mbed_official | 381:5460fc57b6e4 | 387 | /*------------------------------ TIM1 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 388 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) |
mbed_official | 381:5460fc57b6e4 | 389 | { |
mbed_official | 381:5460fc57b6e4 | 390 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 391 | assert_param(IS_RCC_TIM1CLKSOURCE(PeriphClkInit->Tim1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 392 | |
mbed_official | 381:5460fc57b6e4 | 393 | /* Configure the TIM1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 394 | __HAL_RCC_TIM1_CONFIG(PeriphClkInit->Tim1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 395 | } |
mbed_official | 381:5460fc57b6e4 | 396 | |
mbed_official | 381:5460fc57b6e4 | 397 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 398 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 399 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 400 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 401 | |
mbed_official | 381:5460fc57b6e4 | 402 | #if defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 403 | defined(STM32F303xC) || defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 404 | |
mbed_official | 381:5460fc57b6e4 | 405 | /*------------------------------ TIM8 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 406 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM8) == RCC_PERIPHCLK_TIM8) |
mbed_official | 381:5460fc57b6e4 | 407 | { |
mbed_official | 381:5460fc57b6e4 | 408 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 409 | assert_param(IS_RCC_TIM8CLKSOURCE(PeriphClkInit->Tim8ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 410 | |
mbed_official | 381:5460fc57b6e4 | 411 | /* Configure the TIM8 clock source */ |
mbed_official | 381:5460fc57b6e4 | 412 | __HAL_RCC_TIM8_CONFIG(PeriphClkInit->Tim8ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 413 | } |
mbed_official | 381:5460fc57b6e4 | 414 | |
mbed_official | 381:5460fc57b6e4 | 415 | #endif /* STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 416 | /* STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 417 | |
mbed_official | 381:5460fc57b6e4 | 418 | #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 419 | |
mbed_official | 381:5460fc57b6e4 | 420 | /*------------------------------ TIM15 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 421 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15) |
mbed_official | 381:5460fc57b6e4 | 422 | { |
mbed_official | 381:5460fc57b6e4 | 423 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 424 | assert_param(IS_RCC_TIM15CLKSOURCE(PeriphClkInit->Tim15ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 425 | |
mbed_official | 381:5460fc57b6e4 | 426 | /* Configure the TIM15 clock source */ |
mbed_official | 381:5460fc57b6e4 | 427 | __HAL_RCC_TIM15_CONFIG(PeriphClkInit->Tim15ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 428 | } |
mbed_official | 381:5460fc57b6e4 | 429 | |
mbed_official | 381:5460fc57b6e4 | 430 | /*------------------------------ TIM16 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 431 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM16) == RCC_PERIPHCLK_TIM16) |
mbed_official | 381:5460fc57b6e4 | 432 | { |
mbed_official | 381:5460fc57b6e4 | 433 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 434 | assert_param(IS_RCC_TIM16CLKSOURCE(PeriphClkInit->Tim16ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 435 | |
mbed_official | 381:5460fc57b6e4 | 436 | /* Configure the TIM16 clock source */ |
mbed_official | 381:5460fc57b6e4 | 437 | __HAL_RCC_TIM16_CONFIG(PeriphClkInit->Tim16ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 438 | } |
mbed_official | 381:5460fc57b6e4 | 439 | |
mbed_official | 381:5460fc57b6e4 | 440 | /*------------------------------ TIM17 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 441 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM17) == RCC_PERIPHCLK_TIM17) |
mbed_official | 381:5460fc57b6e4 | 442 | { |
mbed_official | 381:5460fc57b6e4 | 443 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 444 | assert_param(IS_RCC_TIM17CLKSOURCE(PeriphClkInit->Tim17ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 445 | |
mbed_official | 381:5460fc57b6e4 | 446 | /* Configure the TIM17 clock source */ |
mbed_official | 381:5460fc57b6e4 | 447 | __HAL_RCC_TIM17_CONFIG(PeriphClkInit->Tim17ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 448 | } |
mbed_official | 381:5460fc57b6e4 | 449 | |
mbed_official | 381:5460fc57b6e4 | 450 | #endif /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 451 | |
mbed_official | 381:5460fc57b6e4 | 452 | #if defined(STM32F334x8) |
mbed_official | 381:5460fc57b6e4 | 453 | |
mbed_official | 381:5460fc57b6e4 | 454 | /*------------------------------ HRTIM1 clock Configuration ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 455 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_HRTIM1) == RCC_PERIPHCLK_HRTIM1) |
mbed_official | 381:5460fc57b6e4 | 456 | { |
mbed_official | 381:5460fc57b6e4 | 457 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 458 | assert_param(IS_RCC_HRTIM1CLKSOURCE(PeriphClkInit->Hrtim1ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 459 | |
mbed_official | 381:5460fc57b6e4 | 460 | /* Configure the HRTIM1 clock source */ |
mbed_official | 381:5460fc57b6e4 | 461 | __HAL_RCC_HRTIM1_CONFIG(PeriphClkInit->Hrtim1ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 462 | } |
mbed_official | 381:5460fc57b6e4 | 463 | |
mbed_official | 381:5460fc57b6e4 | 464 | #endif /* STM32F334x8 */ |
mbed_official | 381:5460fc57b6e4 | 465 | |
mbed_official | 381:5460fc57b6e4 | 466 | #if defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 467 | |
mbed_official | 381:5460fc57b6e4 | 468 | /*------------------------------ SDADC clock Configuration -------------------*/ |
mbed_official | 381:5460fc57b6e4 | 469 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDADC) == RCC_PERIPHCLK_SDADC) |
mbed_official | 381:5460fc57b6e4 | 470 | { |
mbed_official | 381:5460fc57b6e4 | 471 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 472 | assert_param(IS_RCC_SDADCSYSCLK_DIV(PeriphClkInit->SdadcClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 473 | |
mbed_official | 381:5460fc57b6e4 | 474 | /* Configure the SDADC clock prescaler */ |
mbed_official | 381:5460fc57b6e4 | 475 | __HAL_RCC_SDADC_CONFIG(PeriphClkInit->SdadcClockSelection); |
mbed_official | 381:5460fc57b6e4 | 476 | } |
mbed_official | 381:5460fc57b6e4 | 477 | |
mbed_official | 381:5460fc57b6e4 | 478 | /*------------------------------ CEC clock Configuration -------------------*/ |
mbed_official | 381:5460fc57b6e4 | 479 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) |
mbed_official | 381:5460fc57b6e4 | 480 | { |
mbed_official | 381:5460fc57b6e4 | 481 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 482 | assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 483 | |
mbed_official | 381:5460fc57b6e4 | 484 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 485 | __HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection); |
mbed_official | 381:5460fc57b6e4 | 486 | } |
mbed_official | 381:5460fc57b6e4 | 487 | |
mbed_official | 381:5460fc57b6e4 | 488 | #endif /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 489 | |
mbed_official | 381:5460fc57b6e4 | 490 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 491 | |
mbed_official | 381:5460fc57b6e4 | 492 | /*------------------------------ TIM2 clock Configuration -------------------*/ |
mbed_official | 381:5460fc57b6e4 | 493 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM2) == RCC_PERIPHCLK_TIM2) |
mbed_official | 381:5460fc57b6e4 | 494 | { |
mbed_official | 381:5460fc57b6e4 | 495 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 496 | assert_param(IS_RCC_TIM2CLKSOURCE(PeriphClkInit->Tim2ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 497 | |
mbed_official | 381:5460fc57b6e4 | 498 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 499 | __HAL_RCC_TIM2_CONFIG(PeriphClkInit->Tim2ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 500 | } |
mbed_official | 381:5460fc57b6e4 | 501 | |
mbed_official | 381:5460fc57b6e4 | 502 | /*------------------------------ TIM3 clock Configuration -------------------*/ |
mbed_official | 381:5460fc57b6e4 | 503 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM34) == RCC_PERIPHCLK_TIM34) |
mbed_official | 381:5460fc57b6e4 | 504 | { |
mbed_official | 381:5460fc57b6e4 | 505 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 506 | assert_param(IS_RCC_TIM3CLKSOURCE(PeriphClkInit->Tim34ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 507 | |
mbed_official | 381:5460fc57b6e4 | 508 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 509 | __HAL_RCC_TIM34_CONFIG(PeriphClkInit->Tim34ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 510 | } |
mbed_official | 381:5460fc57b6e4 | 511 | |
mbed_official | 381:5460fc57b6e4 | 512 | /*------------------------------ TIM15 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 513 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15) |
mbed_official | 381:5460fc57b6e4 | 514 | { |
mbed_official | 381:5460fc57b6e4 | 515 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 516 | assert_param(IS_RCC_TIM15CLKSOURCE(PeriphClkInit->Tim15ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 517 | |
mbed_official | 381:5460fc57b6e4 | 518 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 519 | __HAL_RCC_TIM15_CONFIG(PeriphClkInit->Tim15ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 520 | } |
mbed_official | 381:5460fc57b6e4 | 521 | |
mbed_official | 381:5460fc57b6e4 | 522 | /*------------------------------ TIM16 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 523 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM16) == RCC_PERIPHCLK_TIM16) |
mbed_official | 381:5460fc57b6e4 | 524 | { |
mbed_official | 381:5460fc57b6e4 | 525 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 526 | assert_param(IS_RCC_TIM16CLKSOURCE(PeriphClkInit->Tim16ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 527 | |
mbed_official | 381:5460fc57b6e4 | 528 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 529 | __HAL_RCC_TIM16_CONFIG(PeriphClkInit->Tim16ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 530 | } |
mbed_official | 381:5460fc57b6e4 | 531 | |
mbed_official | 381:5460fc57b6e4 | 532 | /*------------------------------ TIM17 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 533 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM17) == RCC_PERIPHCLK_TIM17) |
mbed_official | 381:5460fc57b6e4 | 534 | { |
mbed_official | 381:5460fc57b6e4 | 535 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 536 | assert_param(IS_RCC_TIM17CLKSOURCE(PeriphClkInit->Tim17ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 537 | |
mbed_official | 381:5460fc57b6e4 | 538 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 539 | __HAL_RCC_TIM17_CONFIG(PeriphClkInit->Tim17ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 540 | } |
mbed_official | 381:5460fc57b6e4 | 541 | |
mbed_official | 381:5460fc57b6e4 | 542 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 543 | |
mbed_official | 381:5460fc57b6e4 | 544 | #if defined(STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 545 | /*------------------------------ TIM20 clock Configuration ------------------*/ |
mbed_official | 381:5460fc57b6e4 | 546 | if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM20) == RCC_PERIPHCLK_TIM20) |
mbed_official | 381:5460fc57b6e4 | 547 | { |
mbed_official | 381:5460fc57b6e4 | 548 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 549 | assert_param(IS_RCC_TIM20CLKSOURCE(PeriphClkInit->Tim20ClockSelection)); |
mbed_official | 381:5460fc57b6e4 | 550 | |
mbed_official | 381:5460fc57b6e4 | 551 | /* Configure the CEC clock source */ |
mbed_official | 381:5460fc57b6e4 | 552 | __HAL_RCC_TIM20_CONFIG(PeriphClkInit->Tim20ClockSelection); |
mbed_official | 381:5460fc57b6e4 | 553 | } |
mbed_official | 381:5460fc57b6e4 | 554 | #endif /* STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 555 | |
mbed_official | 381:5460fc57b6e4 | 556 | |
mbed_official | 381:5460fc57b6e4 | 557 | return HAL_OK; |
mbed_official | 381:5460fc57b6e4 | 558 | } |
mbed_official | 381:5460fc57b6e4 | 559 | |
mbed_official | 381:5460fc57b6e4 | 560 | /** |
mbed_official | 381:5460fc57b6e4 | 561 | * @brief Get the RCC_ClkInitStruct according to the internal |
mbed_official | 381:5460fc57b6e4 | 562 | * RCC configuration registers. |
mbed_official | 381:5460fc57b6e4 | 563 | * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that |
mbed_official | 381:5460fc57b6e4 | 564 | * returns the configuration information for the Extended Peripherals clocks |
mbed_official | 381:5460fc57b6e4 | 565 | * (ADC, CEC, I2C, I2S, SDADC, HRTIM, TIM, USART, RTC and USB clocks). |
mbed_official | 381:5460fc57b6e4 | 566 | * @retval None |
mbed_official | 381:5460fc57b6e4 | 567 | */ |
mbed_official | 381:5460fc57b6e4 | 568 | void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) |
mbed_official | 381:5460fc57b6e4 | 569 | { |
mbed_official | 381:5460fc57b6e4 | 570 | /* Set all possible values for the extended clock type parameter------------*/ |
mbed_official | 381:5460fc57b6e4 | 571 | /* Common part first */ |
mbed_official | 381:5460fc57b6e4 | 572 | PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | \ |
mbed_official | 381:5460fc57b6e4 | 573 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC; |
mbed_official | 381:5460fc57b6e4 | 574 | |
mbed_official | 381:5460fc57b6e4 | 575 | /* Get the RTC configuration --------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 576 | PeriphClkInit->RTCClockSelection = __HAL_RCC_GET_RTC_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 577 | /* Get the USART1 clock configuration --------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 578 | PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 579 | /* Get the USART2 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 580 | PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 581 | /* Get the USART3 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 582 | PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 583 | /* Get the I2C1 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 584 | PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 585 | |
mbed_official | 381:5460fc57b6e4 | 586 | #if defined(STM32F302xE) || defined(STM32F303xE) || \ |
mbed_official | 381:5460fc57b6e4 | 587 | defined(STM32F302xC) || defined(STM32F303xC) || \ |
mbed_official | 381:5460fc57b6e4 | 588 | defined(STM32F302x8) || \ |
mbed_official | 381:5460fc57b6e4 | 589 | defined(STM32F373xC) |
mbed_official | 381:5460fc57b6e4 | 590 | |
mbed_official | 381:5460fc57b6e4 | 591 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB; |
mbed_official | 381:5460fc57b6e4 | 592 | /* Get the USB clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 593 | PeriphClkInit->USBClockSelection = __HAL_RCC_GET_USB_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 594 | |
mbed_official | 381:5460fc57b6e4 | 595 | #endif /* STM32F302xE || STM32F303xE || */ |
mbed_official | 381:5460fc57b6e4 | 596 | /* STM32F302xC || STM32F303xC || */ |
mbed_official | 381:5460fc57b6e4 | 597 | /* STM32F302x8 || */ |
mbed_official | 381:5460fc57b6e4 | 598 | /* STM32F373xC */ |
mbed_official | 381:5460fc57b6e4 | 599 | |
mbed_official | 381:5460fc57b6e4 | 600 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 601 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 602 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 603 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 604 | |
mbed_official | 381:5460fc57b6e4 | 605 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2C2; |
mbed_official | 381:5460fc57b6e4 | 606 | /* Get the I2C2 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 607 | PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 608 | |
mbed_official | 381:5460fc57b6e4 | 609 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 610 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 611 | /* STM32F301x8 || STM32F302x8 || STM32F318xx || */ |
mbed_official | 381:5460fc57b6e4 | 612 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 613 | |
mbed_official | 381:5460fc57b6e4 | 614 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 615 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 616 | |
mbed_official | 381:5460fc57b6e4 | 617 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2C3; |
mbed_official | 381:5460fc57b6e4 | 618 | /* Get the I2C3 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 619 | PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 620 | |
mbed_official | 381:5460fc57b6e4 | 621 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 622 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 623 | |
mbed_official | 381:5460fc57b6e4 | 624 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 625 | defined(STM32F302xC) || defined(STM32F303xC) ||defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 626 | |
mbed_official | 381:5460fc57b6e4 | 627 | PeriphClkInit->PeriphClockSelection |= (RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5); |
mbed_official | 381:5460fc57b6e4 | 628 | /* Get the UART4 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 629 | PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 630 | /* Get the UART5 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 631 | PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 632 | |
mbed_official | 381:5460fc57b6e4 | 633 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 634 | /* STM32F302xC || STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 635 | |
mbed_official | 381:5460fc57b6e4 | 636 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 637 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 638 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 639 | |
mbed_official | 381:5460fc57b6e4 | 640 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S; |
mbed_official | 381:5460fc57b6e4 | 641 | /* Get the I2S clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 642 | PeriphClkInit->I2sClockSelection = __HAL_RCC_GET_I2S_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 643 | |
mbed_official | 381:5460fc57b6e4 | 644 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 645 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 646 | /* STM32F301x8 || STM32F302x8 || STM32F318xx || */ |
mbed_official | 381:5460fc57b6e4 | 647 | |
mbed_official | 381:5460fc57b6e4 | 648 | #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 649 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 650 | |
mbed_official | 381:5460fc57b6e4 | 651 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_ADC1; |
mbed_official | 381:5460fc57b6e4 | 652 | /* Get the ADC1 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 653 | PeriphClkInit->Adc1ClockSelection = __HAL_RCC_GET_ADC1_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 654 | |
mbed_official | 381:5460fc57b6e4 | 655 | #endif /* STM32F301x8 || STM32F302x8 || STM32F318xx || */ |
mbed_official | 381:5460fc57b6e4 | 656 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 657 | |
mbed_official | 381:5460fc57b6e4 | 658 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 659 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 660 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) |
mbed_official | 381:5460fc57b6e4 | 661 | |
mbed_official | 381:5460fc57b6e4 | 662 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_ADC12; |
mbed_official | 381:5460fc57b6e4 | 663 | /* Get the ADC1 & ADC2 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 664 | PeriphClkInit->Adc12ClockSelection = __HAL_RCC_GET_ADC12_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 665 | |
mbed_official | 381:5460fc57b6e4 | 666 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 667 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 668 | /* STM32F303x8 || STM32F334x8 || STM32F328xx */ |
mbed_official | 381:5460fc57b6e4 | 669 | |
mbed_official | 381:5460fc57b6e4 | 670 | #if defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 671 | defined(STM32F303xC) || defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 672 | |
mbed_official | 381:5460fc57b6e4 | 673 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_ADC34; |
mbed_official | 381:5460fc57b6e4 | 674 | /* Get the ADC3 & ADC4 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 675 | PeriphClkInit->Adc34ClockSelection = __HAL_RCC_GET_ADC34_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 676 | |
mbed_official | 381:5460fc57b6e4 | 677 | #endif /* STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 678 | /* STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 679 | |
mbed_official | 381:5460fc57b6e4 | 680 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 681 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 682 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 683 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 684 | |
mbed_official | 381:5460fc57b6e4 | 685 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM1; |
mbed_official | 381:5460fc57b6e4 | 686 | /* Get the TIM1 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 687 | PeriphClkInit->Tim1ClockSelection = __HAL_RCC_GET_TIM1_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 688 | |
mbed_official | 381:5460fc57b6e4 | 689 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 690 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 691 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 692 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 693 | |
mbed_official | 381:5460fc57b6e4 | 694 | #if defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 381:5460fc57b6e4 | 695 | defined(STM32F303xC) || defined(STM32F358xx) |
mbed_official | 381:5460fc57b6e4 | 696 | |
mbed_official | 381:5460fc57b6e4 | 697 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM8; |
mbed_official | 381:5460fc57b6e4 | 698 | /* Get the TIM8 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 699 | PeriphClkInit->Tim8ClockSelection = __HAL_RCC_GET_TIM8_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 700 | |
mbed_official | 381:5460fc57b6e4 | 701 | #endif /* STM32F303xE || STM32F398xx || */ |
mbed_official | 381:5460fc57b6e4 | 702 | /* STM32F303xC || STM32F358xx */ |
mbed_official | 381:5460fc57b6e4 | 703 | |
mbed_official | 381:5460fc57b6e4 | 704 | #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) |
mbed_official | 381:5460fc57b6e4 | 705 | |
mbed_official | 381:5460fc57b6e4 | 706 | PeriphClkInit->PeriphClockSelection |= (RCC_PERIPHCLK_TIM15 | RCC_PERIPHCLK_TIM16 | RCC_PERIPHCLK_TIM17); |
mbed_official | 381:5460fc57b6e4 | 707 | /* Get the TIM15 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 708 | PeriphClkInit->Tim15ClockSelection = __HAL_RCC_GET_TIM15_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 709 | /* Get the TIM16 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 710 | PeriphClkInit->Tim16ClockSelection = __HAL_RCC_GET_TIM16_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 711 | /* Get the TIM17 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 712 | PeriphClkInit->Tim17ClockSelection = __HAL_RCC_GET_TIM17_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 713 | |
mbed_official | 381:5460fc57b6e4 | 714 | #endif /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 715 | |
mbed_official | 381:5460fc57b6e4 | 716 | #if defined(STM32F334x8) |
mbed_official | 381:5460fc57b6e4 | 717 | |
mbed_official | 381:5460fc57b6e4 | 718 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_HRTIM1; |
mbed_official | 381:5460fc57b6e4 | 719 | /* Get the HRTIM1 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 720 | PeriphClkInit->Hrtim1ClockSelection = __HAL_RCC_GET_HRTIM1_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 721 | |
mbed_official | 381:5460fc57b6e4 | 722 | #endif /* STM32F334x8 */ |
mbed_official | 381:5460fc57b6e4 | 723 | |
mbed_official | 381:5460fc57b6e4 | 724 | #if defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 725 | |
mbed_official | 381:5460fc57b6e4 | 726 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SDADC; |
mbed_official | 381:5460fc57b6e4 | 727 | /* Get the SDADC clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 728 | PeriphClkInit->SdadcClockSelection = __HAL_RCC_GET_SDADC_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 729 | |
mbed_official | 381:5460fc57b6e4 | 730 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_CEC; |
mbed_official | 381:5460fc57b6e4 | 731 | /* Get the CEC clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 732 | PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 733 | |
mbed_official | 381:5460fc57b6e4 | 734 | #endif /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 735 | |
mbed_official | 381:5460fc57b6e4 | 736 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 737 | |
mbed_official | 381:5460fc57b6e4 | 738 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM2; |
mbed_official | 381:5460fc57b6e4 | 739 | /* Get the TIM2 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 740 | PeriphClkInit->Tim2ClockSelection = __HAL_RCC_GET_TIM2_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 741 | |
mbed_official | 381:5460fc57b6e4 | 742 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM34; |
mbed_official | 381:5460fc57b6e4 | 743 | /* Get the TIM3 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 744 | PeriphClkInit->Tim34ClockSelection = __HAL_RCC_GET_TIM34_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 745 | |
mbed_official | 381:5460fc57b6e4 | 746 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM15; |
mbed_official | 381:5460fc57b6e4 | 747 | /* Get the TIM15 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 748 | PeriphClkInit->Tim15ClockSelection = __HAL_RCC_GET_TIM15_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 749 | |
mbed_official | 381:5460fc57b6e4 | 750 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM16; |
mbed_official | 381:5460fc57b6e4 | 751 | /* Get the TIM16 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 752 | PeriphClkInit->Tim16ClockSelection = __HAL_RCC_GET_TIM16_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 753 | |
mbed_official | 381:5460fc57b6e4 | 754 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM17; |
mbed_official | 381:5460fc57b6e4 | 755 | /* Get the TIM17 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 756 | PeriphClkInit->Tim17ClockSelection = __HAL_RCC_GET_TIM17_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 757 | |
mbed_official | 381:5460fc57b6e4 | 758 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 759 | |
mbed_official | 381:5460fc57b6e4 | 760 | #if defined (STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 761 | PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_TIM20; |
mbed_official | 381:5460fc57b6e4 | 762 | /* Get the TIM20 clock configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 763 | PeriphClkInit->Tim20ClockSelection = __HAL_RCC_GET_TIM20_SOURCE(); |
mbed_official | 381:5460fc57b6e4 | 764 | #endif /* STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 765 | } |
mbed_official | 381:5460fc57b6e4 | 766 | |
mbed_official | 381:5460fc57b6e4 | 767 | /** |
mbed_official | 381:5460fc57b6e4 | 768 | * @brief Initializes the RCC Oscillators according to the specified parameters in the |
mbed_official | 381:5460fc57b6e4 | 769 | * RCC_OscInitTypeDef. |
mbed_official | 381:5460fc57b6e4 | 770 | * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that |
mbed_official | 381:5460fc57b6e4 | 771 | * contains the configuration information for the RCC Oscillators. |
mbed_official | 381:5460fc57b6e4 | 772 | * @note The PLL is not disabled when used as system clock. |
mbed_official | 381:5460fc57b6e4 | 773 | * @retval HAL status |
mbed_official | 381:5460fc57b6e4 | 774 | */ |
mbed_official | 381:5460fc57b6e4 | 775 | HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) |
mbed_official | 381:5460fc57b6e4 | 776 | { |
mbed_official | 381:5460fc57b6e4 | 777 | uint32_t tickstart = 0; |
mbed_official | 381:5460fc57b6e4 | 778 | |
mbed_official | 381:5460fc57b6e4 | 779 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 780 | assert_param(RCC_OscInitStruct != HAL_NULL); |
mbed_official | 381:5460fc57b6e4 | 781 | assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType)); |
mbed_official | 381:5460fc57b6e4 | 782 | /*------------------------------- HSE Configuration ------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 783 | if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) |
mbed_official | 381:5460fc57b6e4 | 784 | { |
mbed_official | 381:5460fc57b6e4 | 785 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 786 | assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState)); |
mbed_official | 381:5460fc57b6e4 | 787 | /* When the HSE is used as system clock or clock source for PLL in these cases HSE will not disabled */ |
mbed_official | 381:5460fc57b6e4 | 788 | if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSE) || |
mbed_official | 381:5460fc57b6e4 | 789 | ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE))) |
mbed_official | 381:5460fc57b6e4 | 790 | { |
mbed_official | 381:5460fc57b6e4 | 791 | if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState != RCC_HSE_ON)) |
mbed_official | 381:5460fc57b6e4 | 792 | { |
mbed_official | 381:5460fc57b6e4 | 793 | return HAL_ERROR; |
mbed_official | 381:5460fc57b6e4 | 794 | } |
mbed_official | 381:5460fc57b6e4 | 795 | } |
mbed_official | 381:5460fc57b6e4 | 796 | else |
mbed_official | 381:5460fc57b6e4 | 797 | { |
mbed_official | 381:5460fc57b6e4 | 798 | /* Reset HSEON and HSEBYP bits before configuring the HSE --------------*/ |
mbed_official | 381:5460fc57b6e4 | 799 | __HAL_RCC_HSE_CONFIG(RCC_HSE_OFF); |
mbed_official | 381:5460fc57b6e4 | 800 | |
mbed_official | 381:5460fc57b6e4 | 801 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 802 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 803 | |
mbed_official | 381:5460fc57b6e4 | 804 | /* Wait till HSE is bypassed or disabled */ |
mbed_official | 381:5460fc57b6e4 | 805 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 806 | { |
mbed_official | 381:5460fc57b6e4 | 807 | if((HAL_GetTick()-tickstart) > HSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 808 | { |
mbed_official | 381:5460fc57b6e4 | 809 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 810 | } |
mbed_official | 381:5460fc57b6e4 | 811 | } |
mbed_official | 381:5460fc57b6e4 | 812 | |
mbed_official | 381:5460fc57b6e4 | 813 | /* Set the new HSE configuration ---------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 814 | __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState); |
mbed_official | 381:5460fc57b6e4 | 815 | |
mbed_official | 381:5460fc57b6e4 | 816 | #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 817 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 818 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 819 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 820 | /* Configure the HSE predivision factor --------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 821 | __HAL_RCC_HSE_PREDIV_CONFIG(RCC_OscInitStruct->HSEPredivValue); |
mbed_official | 381:5460fc57b6e4 | 822 | #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 823 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 824 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 825 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 826 | |
mbed_official | 381:5460fc57b6e4 | 827 | /* Check the HSE State */ |
mbed_official | 381:5460fc57b6e4 | 828 | if(RCC_OscInitStruct->HSEState == RCC_HSE_ON) |
mbed_official | 381:5460fc57b6e4 | 829 | { |
mbed_official | 381:5460fc57b6e4 | 830 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 831 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 832 | |
mbed_official | 381:5460fc57b6e4 | 833 | /* Wait till HSE is ready */ |
mbed_official | 381:5460fc57b6e4 | 834 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 835 | { |
mbed_official | 381:5460fc57b6e4 | 836 | if((HAL_GetTick()-tickstart) > HSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 837 | { |
mbed_official | 381:5460fc57b6e4 | 838 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 839 | } |
mbed_official | 381:5460fc57b6e4 | 840 | } |
mbed_official | 381:5460fc57b6e4 | 841 | } |
mbed_official | 381:5460fc57b6e4 | 842 | else |
mbed_official | 381:5460fc57b6e4 | 843 | { |
mbed_official | 381:5460fc57b6e4 | 844 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 845 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 846 | |
mbed_official | 381:5460fc57b6e4 | 847 | /* Wait till HSE is bypassed or disabled */ |
mbed_official | 381:5460fc57b6e4 | 848 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 849 | { |
mbed_official | 381:5460fc57b6e4 | 850 | if((HAL_GetTick()-tickstart) > HSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 851 | { |
mbed_official | 381:5460fc57b6e4 | 852 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 853 | } |
mbed_official | 381:5460fc57b6e4 | 854 | } |
mbed_official | 381:5460fc57b6e4 | 855 | } |
mbed_official | 381:5460fc57b6e4 | 856 | } |
mbed_official | 381:5460fc57b6e4 | 857 | } |
mbed_official | 381:5460fc57b6e4 | 858 | /*----------------------------- HSI Configuration --------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 859 | if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) |
mbed_official | 381:5460fc57b6e4 | 860 | { |
mbed_official | 381:5460fc57b6e4 | 861 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 862 | assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState)); |
mbed_official | 381:5460fc57b6e4 | 863 | assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue)); |
mbed_official | 381:5460fc57b6e4 | 864 | |
mbed_official | 381:5460fc57b6e4 | 865 | /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */ |
mbed_official | 381:5460fc57b6e4 | 866 | if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSI) || |
mbed_official | 381:5460fc57b6e4 | 867 | ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI))) |
mbed_official | 381:5460fc57b6e4 | 868 | { |
mbed_official | 381:5460fc57b6e4 | 869 | /* When the HSI is used as system clock it is not allowed to be disabled */ |
mbed_official | 381:5460fc57b6e4 | 870 | if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON)) |
mbed_official | 381:5460fc57b6e4 | 871 | { |
mbed_official | 381:5460fc57b6e4 | 872 | return HAL_ERROR; |
mbed_official | 381:5460fc57b6e4 | 873 | } |
mbed_official | 381:5460fc57b6e4 | 874 | /* Otherwise, just the calibration is allowed */ |
mbed_official | 381:5460fc57b6e4 | 875 | else |
mbed_official | 381:5460fc57b6e4 | 876 | { |
mbed_official | 381:5460fc57b6e4 | 877 | /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/ |
mbed_official | 381:5460fc57b6e4 | 878 | __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue); |
mbed_official | 381:5460fc57b6e4 | 879 | } |
mbed_official | 381:5460fc57b6e4 | 880 | } |
mbed_official | 381:5460fc57b6e4 | 881 | else |
mbed_official | 381:5460fc57b6e4 | 882 | { |
mbed_official | 381:5460fc57b6e4 | 883 | /* Check the HSI State */ |
mbed_official | 381:5460fc57b6e4 | 884 | if(RCC_OscInitStruct->HSIState != RCC_HSI_OFF) |
mbed_official | 381:5460fc57b6e4 | 885 | { |
mbed_official | 381:5460fc57b6e4 | 886 | /* Enable the Internal High Speed oscillator (HSI). */ |
mbed_official | 381:5460fc57b6e4 | 887 | __HAL_RCC_HSI_ENABLE(); |
mbed_official | 381:5460fc57b6e4 | 888 | |
mbed_official | 381:5460fc57b6e4 | 889 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 890 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 891 | |
mbed_official | 381:5460fc57b6e4 | 892 | /* Wait till HSI is ready */ |
mbed_official | 381:5460fc57b6e4 | 893 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 894 | { |
mbed_official | 381:5460fc57b6e4 | 895 | if((HAL_GetTick()-tickstart) > HSI_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 896 | { |
mbed_official | 381:5460fc57b6e4 | 897 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 898 | } |
mbed_official | 381:5460fc57b6e4 | 899 | } |
mbed_official | 381:5460fc57b6e4 | 900 | |
mbed_official | 381:5460fc57b6e4 | 901 | /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/ |
mbed_official | 381:5460fc57b6e4 | 902 | __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue); |
mbed_official | 381:5460fc57b6e4 | 903 | } |
mbed_official | 381:5460fc57b6e4 | 904 | else |
mbed_official | 381:5460fc57b6e4 | 905 | { |
mbed_official | 381:5460fc57b6e4 | 906 | /* Disable the Internal High Speed oscillator (HSI). */ |
mbed_official | 381:5460fc57b6e4 | 907 | __HAL_RCC_HSI_DISABLE(); |
mbed_official | 381:5460fc57b6e4 | 908 | |
mbed_official | 381:5460fc57b6e4 | 909 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 910 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 911 | |
mbed_official | 381:5460fc57b6e4 | 912 | /* Wait till HSI is ready */ |
mbed_official | 381:5460fc57b6e4 | 913 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 914 | { |
mbed_official | 381:5460fc57b6e4 | 915 | if((HAL_GetTick()-tickstart) > HSI_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 916 | { |
mbed_official | 381:5460fc57b6e4 | 917 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 918 | } |
mbed_official | 381:5460fc57b6e4 | 919 | } |
mbed_official | 381:5460fc57b6e4 | 920 | } |
mbed_official | 381:5460fc57b6e4 | 921 | } |
mbed_official | 381:5460fc57b6e4 | 922 | } |
mbed_official | 381:5460fc57b6e4 | 923 | /*------------------------------ LSI Configuration -------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 924 | if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) |
mbed_official | 381:5460fc57b6e4 | 925 | { |
mbed_official | 381:5460fc57b6e4 | 926 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 927 | assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState)); |
mbed_official | 381:5460fc57b6e4 | 928 | |
mbed_official | 381:5460fc57b6e4 | 929 | /* Check the LSI State */ |
mbed_official | 381:5460fc57b6e4 | 930 | if(RCC_OscInitStruct->LSIState != RCC_LSI_OFF) |
mbed_official | 381:5460fc57b6e4 | 931 | { |
mbed_official | 381:5460fc57b6e4 | 932 | /* Enable the Internal Low Speed oscillator (LSI). */ |
mbed_official | 381:5460fc57b6e4 | 933 | __HAL_RCC_LSI_ENABLE(); |
mbed_official | 381:5460fc57b6e4 | 934 | |
mbed_official | 381:5460fc57b6e4 | 935 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 936 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 937 | |
mbed_official | 381:5460fc57b6e4 | 938 | /* Wait till LSI is ready */ |
mbed_official | 381:5460fc57b6e4 | 939 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 940 | { |
mbed_official | 381:5460fc57b6e4 | 941 | if((HAL_GetTick()-tickstart) > LSI_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 942 | { |
mbed_official | 381:5460fc57b6e4 | 943 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 944 | } |
mbed_official | 381:5460fc57b6e4 | 945 | } |
mbed_official | 381:5460fc57b6e4 | 946 | } |
mbed_official | 381:5460fc57b6e4 | 947 | else |
mbed_official | 381:5460fc57b6e4 | 948 | { |
mbed_official | 381:5460fc57b6e4 | 949 | /* Disable the Internal Low Speed oscillator (LSI). */ |
mbed_official | 381:5460fc57b6e4 | 950 | __HAL_RCC_LSI_DISABLE(); |
mbed_official | 381:5460fc57b6e4 | 951 | |
mbed_official | 381:5460fc57b6e4 | 952 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 953 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 954 | |
mbed_official | 381:5460fc57b6e4 | 955 | /* Wait till LSI is ready */ |
mbed_official | 381:5460fc57b6e4 | 956 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 957 | { |
mbed_official | 381:5460fc57b6e4 | 958 | if((HAL_GetTick()-tickstart) > LSI_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 959 | { |
mbed_official | 381:5460fc57b6e4 | 960 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 961 | } |
mbed_official | 381:5460fc57b6e4 | 962 | } |
mbed_official | 381:5460fc57b6e4 | 963 | } |
mbed_official | 381:5460fc57b6e4 | 964 | } |
mbed_official | 381:5460fc57b6e4 | 965 | /*------------------------------ LSE Configuration -------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 966 | if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) |
mbed_official | 381:5460fc57b6e4 | 967 | { |
mbed_official | 381:5460fc57b6e4 | 968 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 969 | assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState)); |
mbed_official | 381:5460fc57b6e4 | 970 | |
mbed_official | 381:5460fc57b6e4 | 971 | /* Enable Power Clock*/ |
mbed_official | 381:5460fc57b6e4 | 972 | __PWR_CLK_ENABLE(); |
mbed_official | 381:5460fc57b6e4 | 973 | |
mbed_official | 381:5460fc57b6e4 | 974 | /* Enable write access to Backup domain */ |
mbed_official | 381:5460fc57b6e4 | 975 | SET_BIT(PWR->CR, PWR_CR_DBP); |
mbed_official | 381:5460fc57b6e4 | 976 | |
mbed_official | 381:5460fc57b6e4 | 977 | /* Wait for Backup domain Write protection disable */ |
mbed_official | 381:5460fc57b6e4 | 978 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 979 | |
mbed_official | 381:5460fc57b6e4 | 980 | while((PWR->CR & PWR_CR_DBP) == RESET) |
mbed_official | 381:5460fc57b6e4 | 981 | { |
mbed_official | 381:5460fc57b6e4 | 982 | if((HAL_GetTick()-tickstart) > DBP_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 983 | { |
mbed_official | 381:5460fc57b6e4 | 984 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 985 | } |
mbed_official | 381:5460fc57b6e4 | 986 | } |
mbed_official | 381:5460fc57b6e4 | 987 | |
mbed_official | 381:5460fc57b6e4 | 988 | /* Reset LSEON and LSEBYP bits before configuring the LSE ----------------*/ |
mbed_official | 381:5460fc57b6e4 | 989 | __HAL_RCC_LSE_CONFIG(RCC_LSE_OFF); |
mbed_official | 381:5460fc57b6e4 | 990 | |
mbed_official | 381:5460fc57b6e4 | 991 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 992 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 993 | |
mbed_official | 381:5460fc57b6e4 | 994 | /* Wait till LSE is ready */ |
mbed_official | 381:5460fc57b6e4 | 995 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 996 | { |
mbed_official | 381:5460fc57b6e4 | 997 | if((HAL_GetTick()-tickstart) > LSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 998 | { |
mbed_official | 381:5460fc57b6e4 | 999 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1000 | } |
mbed_official | 381:5460fc57b6e4 | 1001 | } |
mbed_official | 381:5460fc57b6e4 | 1002 | |
mbed_official | 381:5460fc57b6e4 | 1003 | /* Set the new LSE configuration -----------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1004 | __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState); |
mbed_official | 381:5460fc57b6e4 | 1005 | /* Check the LSE State */ |
mbed_official | 381:5460fc57b6e4 | 1006 | if(RCC_OscInitStruct->LSEState == RCC_LSE_ON) |
mbed_official | 381:5460fc57b6e4 | 1007 | { |
mbed_official | 381:5460fc57b6e4 | 1008 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 1009 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 1010 | |
mbed_official | 381:5460fc57b6e4 | 1011 | /* Wait till LSE is ready */ |
mbed_official | 381:5460fc57b6e4 | 1012 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 1013 | { |
mbed_official | 381:5460fc57b6e4 | 1014 | if((HAL_GetTick()-tickstart) > LSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 1015 | { |
mbed_official | 381:5460fc57b6e4 | 1016 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1017 | } |
mbed_official | 381:5460fc57b6e4 | 1018 | } |
mbed_official | 381:5460fc57b6e4 | 1019 | } |
mbed_official | 381:5460fc57b6e4 | 1020 | else |
mbed_official | 381:5460fc57b6e4 | 1021 | { |
mbed_official | 381:5460fc57b6e4 | 1022 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 1023 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 1024 | |
mbed_official | 381:5460fc57b6e4 | 1025 | /* Wait till LSE is ready */ |
mbed_official | 381:5460fc57b6e4 | 1026 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 1027 | { |
mbed_official | 381:5460fc57b6e4 | 1028 | if((HAL_GetTick()-tickstart) > LSE_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 1029 | { |
mbed_official | 381:5460fc57b6e4 | 1030 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1031 | } |
mbed_official | 381:5460fc57b6e4 | 1032 | } |
mbed_official | 381:5460fc57b6e4 | 1033 | } |
mbed_official | 381:5460fc57b6e4 | 1034 | } |
mbed_official | 381:5460fc57b6e4 | 1035 | /*-------------------------------- PLL Configuration -----------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1036 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 1037 | assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState)); |
mbed_official | 381:5460fc57b6e4 | 1038 | if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE) |
mbed_official | 381:5460fc57b6e4 | 1039 | { |
mbed_official | 381:5460fc57b6e4 | 1040 | /* Check if the PLL is used as system clock or not */ |
mbed_official | 381:5460fc57b6e4 | 1041 | if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) |
mbed_official | 381:5460fc57b6e4 | 1042 | { |
mbed_official | 381:5460fc57b6e4 | 1043 | if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON) |
mbed_official | 381:5460fc57b6e4 | 1044 | { |
mbed_official | 381:5460fc57b6e4 | 1045 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 1046 | assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource)); |
mbed_official | 381:5460fc57b6e4 | 1047 | assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL)); |
mbed_official | 381:5460fc57b6e4 | 1048 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 1049 | assert_param(IS_RCC_PREDIV(RCC_OscInitStruct->PLL.PREDIV)); |
mbed_official | 381:5460fc57b6e4 | 1050 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 1051 | |
mbed_official | 381:5460fc57b6e4 | 1052 | /* Disable the main PLL. */ |
mbed_official | 381:5460fc57b6e4 | 1053 | __HAL_RCC_PLL_DISABLE(); |
mbed_official | 381:5460fc57b6e4 | 1054 | |
mbed_official | 381:5460fc57b6e4 | 1055 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 1056 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 1057 | |
mbed_official | 381:5460fc57b6e4 | 1058 | /* Wait till PLL is ready */ |
mbed_official | 381:5460fc57b6e4 | 1059 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 1060 | { |
mbed_official | 381:5460fc57b6e4 | 1061 | if((HAL_GetTick()-tickstart) > PLL_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 1062 | { |
mbed_official | 381:5460fc57b6e4 | 1063 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1064 | } |
mbed_official | 381:5460fc57b6e4 | 1065 | } |
mbed_official | 381:5460fc57b6e4 | 1066 | #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1067 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1068 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1069 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 1070 | /* Configure the main PLL clock source and multiplication factor. */ |
mbed_official | 381:5460fc57b6e4 | 1071 | __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource, |
mbed_official | 381:5460fc57b6e4 | 1072 | RCC_OscInitStruct->PLL.PLLMUL); |
mbed_official | 381:5460fc57b6e4 | 1073 | #else |
mbed_official | 381:5460fc57b6e4 | 1074 | /* Configure the main PLL clock source, predivider and multiplication factor. */ |
mbed_official | 381:5460fc57b6e4 | 1075 | __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource, |
mbed_official | 381:5460fc57b6e4 | 1076 | RCC_OscInitStruct->PLL.PREDIV, |
mbed_official | 381:5460fc57b6e4 | 1077 | RCC_OscInitStruct->PLL.PLLMUL); |
mbed_official | 381:5460fc57b6e4 | 1078 | #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 1079 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 1080 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 1081 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 1082 | |
mbed_official | 381:5460fc57b6e4 | 1083 | /* Enable the main PLL. */ |
mbed_official | 381:5460fc57b6e4 | 1084 | __HAL_RCC_PLL_ENABLE(); |
mbed_official | 381:5460fc57b6e4 | 1085 | |
mbed_official | 381:5460fc57b6e4 | 1086 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 1087 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 1088 | |
mbed_official | 381:5460fc57b6e4 | 1089 | /* Wait till PLL is ready */ |
mbed_official | 381:5460fc57b6e4 | 1090 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) |
mbed_official | 381:5460fc57b6e4 | 1091 | { |
mbed_official | 381:5460fc57b6e4 | 1092 | if((HAL_GetTick()-tickstart) > PLL_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 1093 | { |
mbed_official | 381:5460fc57b6e4 | 1094 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1095 | } |
mbed_official | 381:5460fc57b6e4 | 1096 | } |
mbed_official | 381:5460fc57b6e4 | 1097 | } |
mbed_official | 381:5460fc57b6e4 | 1098 | else |
mbed_official | 381:5460fc57b6e4 | 1099 | { |
mbed_official | 381:5460fc57b6e4 | 1100 | /* Disable the main PLL. */ |
mbed_official | 381:5460fc57b6e4 | 1101 | __HAL_RCC_PLL_DISABLE(); |
mbed_official | 381:5460fc57b6e4 | 1102 | /* Get timeout */ |
mbed_official | 381:5460fc57b6e4 | 1103 | tickstart = HAL_GetTick(); |
mbed_official | 381:5460fc57b6e4 | 1104 | |
mbed_official | 381:5460fc57b6e4 | 1105 | /* Wait till PLL is ready */ |
mbed_official | 381:5460fc57b6e4 | 1106 | while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) |
mbed_official | 381:5460fc57b6e4 | 1107 | { |
mbed_official | 381:5460fc57b6e4 | 1108 | if((HAL_GetTick()-tickstart) > PLL_TIMEOUT_VALUE) |
mbed_official | 381:5460fc57b6e4 | 1109 | { |
mbed_official | 381:5460fc57b6e4 | 1110 | return HAL_TIMEOUT; |
mbed_official | 381:5460fc57b6e4 | 1111 | } |
mbed_official | 381:5460fc57b6e4 | 1112 | } |
mbed_official | 381:5460fc57b6e4 | 1113 | } |
mbed_official | 381:5460fc57b6e4 | 1114 | } |
mbed_official | 381:5460fc57b6e4 | 1115 | else |
mbed_official | 381:5460fc57b6e4 | 1116 | { |
mbed_official | 381:5460fc57b6e4 | 1117 | return HAL_ERROR; |
mbed_official | 381:5460fc57b6e4 | 1118 | } |
mbed_official | 381:5460fc57b6e4 | 1119 | } |
mbed_official | 381:5460fc57b6e4 | 1120 | return HAL_OK; |
mbed_official | 381:5460fc57b6e4 | 1121 | } |
mbed_official | 381:5460fc57b6e4 | 1122 | |
mbed_official | 381:5460fc57b6e4 | 1123 | /** |
mbed_official | 381:5460fc57b6e4 | 1124 | * @brief Configures the RCC_OscInitStruct according to the internal |
mbed_official | 381:5460fc57b6e4 | 1125 | * RCC configuration registers. |
mbed_official | 381:5460fc57b6e4 | 1126 | * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that |
mbed_official | 381:5460fc57b6e4 | 1127 | * will be configured. |
mbed_official | 381:5460fc57b6e4 | 1128 | * @retval None |
mbed_official | 381:5460fc57b6e4 | 1129 | */ |
mbed_official | 381:5460fc57b6e4 | 1130 | void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) |
mbed_official | 381:5460fc57b6e4 | 1131 | { |
mbed_official | 381:5460fc57b6e4 | 1132 | /* Check the parameters */ |
mbed_official | 381:5460fc57b6e4 | 1133 | assert_param(RCC_OscInitStruct != HAL_NULL); |
mbed_official | 381:5460fc57b6e4 | 1134 | |
mbed_official | 381:5460fc57b6e4 | 1135 | /* Set all possible values for the Oscillator type parameter ---------------*/ |
mbed_official | 381:5460fc57b6e4 | 1136 | RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI; |
mbed_official | 381:5460fc57b6e4 | 1137 | |
mbed_official | 381:5460fc57b6e4 | 1138 | /* Get the HSE configuration -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1139 | if((RCC->CR & RCC_CR_HSEBYP) == RCC_CR_HSEBYP) |
mbed_official | 381:5460fc57b6e4 | 1140 | { |
mbed_official | 381:5460fc57b6e4 | 1141 | RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS; |
mbed_official | 381:5460fc57b6e4 | 1142 | } |
mbed_official | 381:5460fc57b6e4 | 1143 | else if((RCC->CR & RCC_CR_HSEON) == RCC_CR_HSEON) |
mbed_official | 381:5460fc57b6e4 | 1144 | { |
mbed_official | 381:5460fc57b6e4 | 1145 | RCC_OscInitStruct->HSEState = RCC_HSE_ON; |
mbed_official | 381:5460fc57b6e4 | 1146 | } |
mbed_official | 381:5460fc57b6e4 | 1147 | else |
mbed_official | 381:5460fc57b6e4 | 1148 | { |
mbed_official | 381:5460fc57b6e4 | 1149 | RCC_OscInitStruct->HSEState = RCC_HSE_OFF; |
mbed_official | 381:5460fc57b6e4 | 1150 | } |
mbed_official | 381:5460fc57b6e4 | 1151 | |
mbed_official | 381:5460fc57b6e4 | 1152 | #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1153 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1154 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1155 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 1156 | RCC_OscInitStruct->HSEPredivValue = (uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV); |
mbed_official | 381:5460fc57b6e4 | 1157 | #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 1158 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 1159 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 1160 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 1161 | |
mbed_official | 381:5460fc57b6e4 | 1162 | /* Get the HSI configuration -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1163 | if((RCC->CR & RCC_CR_HSION) == RCC_CR_HSION) |
mbed_official | 381:5460fc57b6e4 | 1164 | { |
mbed_official | 381:5460fc57b6e4 | 1165 | RCC_OscInitStruct->HSIState = RCC_HSI_ON; |
mbed_official | 381:5460fc57b6e4 | 1166 | } |
mbed_official | 381:5460fc57b6e4 | 1167 | else |
mbed_official | 381:5460fc57b6e4 | 1168 | { |
mbed_official | 381:5460fc57b6e4 | 1169 | RCC_OscInitStruct->HSIState = RCC_HSI_OFF; |
mbed_official | 381:5460fc57b6e4 | 1170 | } |
mbed_official | 381:5460fc57b6e4 | 1171 | |
mbed_official | 381:5460fc57b6e4 | 1172 | RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR &RCC_CR_HSITRIM) >> POSITION_VAL(RCC_CR_HSITRIM)); |
mbed_official | 381:5460fc57b6e4 | 1173 | |
mbed_official | 381:5460fc57b6e4 | 1174 | /* Get the LSE configuration -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1175 | if((RCC->BDCR & RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP) |
mbed_official | 381:5460fc57b6e4 | 1176 | { |
mbed_official | 381:5460fc57b6e4 | 1177 | RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS; |
mbed_official | 381:5460fc57b6e4 | 1178 | } |
mbed_official | 381:5460fc57b6e4 | 1179 | else if((RCC->BDCR & RCC_BDCR_LSEON) == RCC_BDCR_LSEON) |
mbed_official | 381:5460fc57b6e4 | 1180 | { |
mbed_official | 381:5460fc57b6e4 | 1181 | RCC_OscInitStruct->LSEState = RCC_LSE_ON; |
mbed_official | 381:5460fc57b6e4 | 1182 | } |
mbed_official | 381:5460fc57b6e4 | 1183 | else |
mbed_official | 381:5460fc57b6e4 | 1184 | { |
mbed_official | 381:5460fc57b6e4 | 1185 | RCC_OscInitStruct->LSEState = RCC_LSE_OFF; |
mbed_official | 381:5460fc57b6e4 | 1186 | } |
mbed_official | 381:5460fc57b6e4 | 1187 | |
mbed_official | 381:5460fc57b6e4 | 1188 | /* Get the LSI configuration -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1189 | if((RCC->CSR & RCC_CSR_LSION) == RCC_CSR_LSION) |
mbed_official | 381:5460fc57b6e4 | 1190 | { |
mbed_official | 381:5460fc57b6e4 | 1191 | RCC_OscInitStruct->LSIState = RCC_LSI_ON; |
mbed_official | 381:5460fc57b6e4 | 1192 | } |
mbed_official | 381:5460fc57b6e4 | 1193 | else |
mbed_official | 381:5460fc57b6e4 | 1194 | { |
mbed_official | 381:5460fc57b6e4 | 1195 | RCC_OscInitStruct->LSIState = RCC_LSI_OFF; |
mbed_official | 381:5460fc57b6e4 | 1196 | } |
mbed_official | 381:5460fc57b6e4 | 1197 | |
mbed_official | 381:5460fc57b6e4 | 1198 | /* Get the PLL configuration -----------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1199 | if((RCC->CR & RCC_CR_PLLON) == RCC_CR_PLLON) |
mbed_official | 381:5460fc57b6e4 | 1200 | { |
mbed_official | 381:5460fc57b6e4 | 1201 | RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON; |
mbed_official | 381:5460fc57b6e4 | 1202 | } |
mbed_official | 381:5460fc57b6e4 | 1203 | else |
mbed_official | 381:5460fc57b6e4 | 1204 | { |
mbed_official | 381:5460fc57b6e4 | 1205 | RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF; |
mbed_official | 381:5460fc57b6e4 | 1206 | } |
mbed_official | 381:5460fc57b6e4 | 1207 | |
mbed_official | 381:5460fc57b6e4 | 1208 | RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC); |
mbed_official | 381:5460fc57b6e4 | 1209 | RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMUL); |
mbed_official | 381:5460fc57b6e4 | 1210 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) |
mbed_official | 381:5460fc57b6e4 | 1211 | RCC_OscInitStruct->PLL.PREDIV = (uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV); |
mbed_official | 381:5460fc57b6e4 | 1212 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx */ |
mbed_official | 381:5460fc57b6e4 | 1213 | } |
mbed_official | 381:5460fc57b6e4 | 1214 | |
mbed_official | 381:5460fc57b6e4 | 1215 | /** |
mbed_official | 381:5460fc57b6e4 | 1216 | * @brief Returns the SYSCLK frequency |
mbed_official | 381:5460fc57b6e4 | 1217 | * @note The system frequency computed by this function is not the real |
mbed_official | 381:5460fc57b6e4 | 1218 | * frequency in the chip. It is calculated based on the predefined |
mbed_official | 381:5460fc57b6e4 | 1219 | * constant and the selected clock source: |
mbed_official | 381:5460fc57b6e4 | 1220 | * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*) |
mbed_official | 381:5460fc57b6e4 | 1221 | * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE |
mbed_official | 381:5460fc57b6e4 | 1222 | * divided by PREDIV factor(**) |
mbed_official | 381:5460fc57b6e4 | 1223 | * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE |
mbed_official | 381:5460fc57b6e4 | 1224 | * divided by PREDIV factor(**) or HSI_VALUE(*) multiplied by the PLL factor. |
mbed_official | 381:5460fc57b6e4 | 1225 | * @note (*) HSI_VALUE is a constant defined in stm32f3xx.h file (default value |
mbed_official | 381:5460fc57b6e4 | 1226 | * 8 MHz). |
mbed_official | 381:5460fc57b6e4 | 1227 | * @note (**) HSE_VALUE is a constant defined in stm32f3xx.h file (default value |
mbed_official | 381:5460fc57b6e4 | 1228 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real |
mbed_official | 381:5460fc57b6e4 | 1229 | * frequency of the crystal used. Otherwise, this function may |
mbed_official | 381:5460fc57b6e4 | 1230 | * have wrong result. |
mbed_official | 381:5460fc57b6e4 | 1231 | * |
mbed_official | 381:5460fc57b6e4 | 1232 | * @note The result of this function could be not correct when using fractional |
mbed_official | 381:5460fc57b6e4 | 1233 | * value for HSE crystal. |
mbed_official | 381:5460fc57b6e4 | 1234 | * |
mbed_official | 381:5460fc57b6e4 | 1235 | * @note This function can be used by the user application to compute the |
mbed_official | 381:5460fc57b6e4 | 1236 | * baudrate for the communication peripherals or configure other parameters. |
mbed_official | 381:5460fc57b6e4 | 1237 | * |
mbed_official | 381:5460fc57b6e4 | 1238 | * @note Each time SYSCLK changes, this function must be called to update the |
mbed_official | 381:5460fc57b6e4 | 1239 | * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect. |
mbed_official | 381:5460fc57b6e4 | 1240 | * |
mbed_official | 381:5460fc57b6e4 | 1241 | * @retval SYSCLK frequency |
mbed_official | 381:5460fc57b6e4 | 1242 | */ |
mbed_official | 381:5460fc57b6e4 | 1243 | uint32_t HAL_RCC_GetSysClockFreq(void) |
mbed_official | 381:5460fc57b6e4 | 1244 | { |
mbed_official | 381:5460fc57b6e4 | 1245 | uint32_t tmpreg = 0, prediv = 0, pllmul = 0, pllclk = 0; |
mbed_official | 381:5460fc57b6e4 | 1246 | uint32_t sysclockfreq = 0; |
mbed_official | 381:5460fc57b6e4 | 1247 | |
mbed_official | 381:5460fc57b6e4 | 1248 | tmpreg = RCC->CFGR; |
mbed_official | 381:5460fc57b6e4 | 1249 | |
mbed_official | 381:5460fc57b6e4 | 1250 | /* Get SYSCLK source -------------------------------------------------------*/ |
mbed_official | 381:5460fc57b6e4 | 1251 | switch (tmpreg & RCC_CFGR_SWS) |
mbed_official | 381:5460fc57b6e4 | 1252 | { |
mbed_official | 381:5460fc57b6e4 | 1253 | case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ |
mbed_official | 381:5460fc57b6e4 | 1254 | sysclockfreq = HSE_VALUE; |
mbed_official | 381:5460fc57b6e4 | 1255 | break; |
mbed_official | 381:5460fc57b6e4 | 1256 | |
mbed_official | 381:5460fc57b6e4 | 1257 | case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock source */ |
mbed_official | 381:5460fc57b6e4 | 1258 | pllmul = PLLMULFactorTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMUL) >> POSITION_VAL(RCC_CFGR_PLLMUL)]; |
mbed_official | 381:5460fc57b6e4 | 1259 | prediv = PredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV) >> POSITION_VAL(RCC_CFGR2_PREDIV)]; |
mbed_official | 381:5460fc57b6e4 | 1260 | #if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1261 | defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1262 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 381:5460fc57b6e4 | 1263 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 381:5460fc57b6e4 | 1264 | if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI) |
mbed_official | 381:5460fc57b6e4 | 1265 | { |
mbed_official | 381:5460fc57b6e4 | 1266 | /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV * PLLMUL */ |
mbed_official | 381:5460fc57b6e4 | 1267 | pllclk = (HSE_VALUE/prediv) * pllmul; |
mbed_official | 381:5460fc57b6e4 | 1268 | } |
mbed_official | 381:5460fc57b6e4 | 1269 | else |
mbed_official | 381:5460fc57b6e4 | 1270 | { |
mbed_official | 381:5460fc57b6e4 | 1271 | /* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */ |
mbed_official | 381:5460fc57b6e4 | 1272 | pllclk = (HSI_VALUE >> 1) * pllmul; |
mbed_official | 381:5460fc57b6e4 | 1273 | } |
mbed_official | 381:5460fc57b6e4 | 1274 | #else |
mbed_official | 381:5460fc57b6e4 | 1275 | if ((tmpreg & RCC_CFGR_PLLSRC_HSE_PREDIV) == RCC_CFGR_PLLSRC_HSE_PREDIV) |
mbed_official | 381:5460fc57b6e4 | 1276 | { |
mbed_official | 381:5460fc57b6e4 | 1277 | /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV * PLLMUL */ |
mbed_official | 381:5460fc57b6e4 | 1278 | pllclk = (HSE_VALUE/prediv) * pllmul; |
mbed_official | 381:5460fc57b6e4 | 1279 | } |
mbed_official | 381:5460fc57b6e4 | 1280 | else |
mbed_official | 381:5460fc57b6e4 | 1281 | { |
mbed_official | 381:5460fc57b6e4 | 1282 | /* HSI used as PLL clock source : PLLCLK = HSI/PREDIV * PLLMUL */ |
mbed_official | 381:5460fc57b6e4 | 1283 | pllclk = (HSI_VALUE/prediv) * pllmul; |
mbed_official | 381:5460fc57b6e4 | 1284 | } |
mbed_official | 381:5460fc57b6e4 | 1285 | #endif /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 381:5460fc57b6e4 | 1286 | /* STM32F303x8 || STM32F334x8 || STM32F328xx || */ |
mbed_official | 381:5460fc57b6e4 | 1287 | /* STM32F301x8 || STM32F302x8 || STM32F318xx */ |
mbed_official | 381:5460fc57b6e4 | 1288 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 381:5460fc57b6e4 | 1289 | sysclockfreq = pllclk; |
mbed_official | 381:5460fc57b6e4 | 1290 | break; |
mbed_official | 381:5460fc57b6e4 | 1291 | |
mbed_official | 381:5460fc57b6e4 | 1292 | case RCC_SYSCLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ |
mbed_official | 381:5460fc57b6e4 | 1293 | default: |
mbed_official | 381:5460fc57b6e4 | 1294 | sysclockfreq = HSI_VALUE; |
mbed_official | 381:5460fc57b6e4 | 1295 | break; |
mbed_official | 381:5460fc57b6e4 | 1296 | } |
mbed_official | 381:5460fc57b6e4 | 1297 | return sysclockfreq; |
mbed_official | 381:5460fc57b6e4 | 1298 | } |
mbed_official | 381:5460fc57b6e4 | 1299 | |
mbed_official | 381:5460fc57b6e4 | 1300 | /** |
mbed_official | 381:5460fc57b6e4 | 1301 | * @} |
mbed_official | 381:5460fc57b6e4 | 1302 | */ |
mbed_official | 381:5460fc57b6e4 | 1303 | |
mbed_official | 381:5460fc57b6e4 | 1304 | /** |
mbed_official | 381:5460fc57b6e4 | 1305 | * @} |
mbed_official | 381:5460fc57b6e4 | 1306 | */ |
mbed_official | 381:5460fc57b6e4 | 1307 | |
mbed_official | 381:5460fc57b6e4 | 1308 | #endif /* HAL_RCC_MODULE_ENABLED */ |
mbed_official | 381:5460fc57b6e4 | 1309 | /** |
mbed_official | 381:5460fc57b6e4 | 1310 | * @} |
mbed_official | 381:5460fc57b6e4 | 1311 | */ |
mbed_official | 381:5460fc57b6e4 | 1312 | |
mbed_official | 381:5460fc57b6e4 | 1313 | /** |
mbed_official | 381:5460fc57b6e4 | 1314 | * @} |
mbed_official | 381:5460fc57b6e4 | 1315 | */ |
mbed_official | 381:5460fc57b6e4 | 1316 | |
mbed_official | 381:5460fc57b6e4 | 1317 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |