mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 376:cb4d9db17537 1 /**
mbed_official 376:cb4d9db17537 2 ******************************************************************************
mbed_official 376:cb4d9db17537 3 * @file stm32l0xx_hal_rcc_ex.c
mbed_official 376:cb4d9db17537 4 * @author MCD Application Team
mbed_official 489:119543c9f674 5 * @version V1.2.0
mbed_official 489:119543c9f674 6 * @date 06-February-2015
mbed_official 376:cb4d9db17537 7 * @brief Extended RCC HAL module driver.
mbed_official 376:cb4d9db17537 8 *
mbed_official 376:cb4d9db17537 9 * This file provides firmware functions to manage the following
mbed_official 376:cb4d9db17537 10 * functionalities RCC extension peripheral:
mbed_official 376:cb4d9db17537 11 * + Extended Peripheral Control functions
mbed_official 376:cb4d9db17537 12 *
mbed_official 376:cb4d9db17537 13 @verbatim
mbed_official 376:cb4d9db17537 14 ==============================================================================
mbed_official 376:cb4d9db17537 15 ##### RCC specific features #####
mbed_official 376:cb4d9db17537 16 ==============================================================================
mbed_official 376:cb4d9db17537 17 For CRS, RCC Extension HAL driver can be used as follows:
mbed_official 376:cb4d9db17537 18
mbed_official 376:cb4d9db17537 19 (#) In System clock configuration, HSI48 need to be enabled
mbed_official 376:cb4d9db17537 20
mbed_official 376:cb4d9db17537 21 (#] Enable CRS clock in IP MSP init which will use CRS functions
mbed_official 376:cb4d9db17537 22
mbed_official 376:cb4d9db17537 23 (#) Call CRS functions like this
mbed_official 376:cb4d9db17537 24 (##) Prepare synchronization configuration necessary for HSI48 calibration
mbed_official 376:cb4d9db17537 25 (+++) Default values can be set for frequency Error Measurement (reload and error limit)
mbed_official 376:cb4d9db17537 26 and also HSI48 oscillator smooth trimming.
mbed_official 376:cb4d9db17537 27 (+++) Macro __HAL_RCC_CRS_CALCULATE_RELOADVALUE can be also used to calculate
mbed_official 376:cb4d9db17537 28 directly reload value with target and synchronization frequencies values
mbed_official 376:cb4d9db17537 29 (##) Call function HAL_RCCEx_CRSConfig which
mbed_official 376:cb4d9db17537 30 (+++) Reset CRS registers to their default values.
mbed_official 376:cb4d9db17537 31 (+++) Configure CRS registers with synchronization configuration
mbed_official 376:cb4d9db17537 32 (+++) Enable automatic calibration and frequency error counter feature
mbed_official 376:cb4d9db17537 33
mbed_official 376:cb4d9db17537 34 (##) A polling function is provided to wait for complete Synchronization
mbed_official 376:cb4d9db17537 35 (+++) Call function 'HAL_RCCEx_CRSWaitSynchronization()'
mbed_official 376:cb4d9db17537 36 (+++) According to CRS status, user can decide to adjust again the calibration or continue
mbed_official 376:cb4d9db17537 37 application if synchronization is OK
mbed_official 376:cb4d9db17537 38
mbed_official 376:cb4d9db17537 39 (#) User can retrieve information related to synchronization in calling function
mbed_official 376:cb4d9db17537 40 HAL_RCCEx_CRSGetSynchronizationInfo()
mbed_official 376:cb4d9db17537 41
mbed_official 376:cb4d9db17537 42 (#) Regarding synchronization status and synchronization information, user can try a new calibration
mbed_official 376:cb4d9db17537 43 in changing synchronization configuration and call again HAL_RCCEx_CRSConfig.
mbed_official 376:cb4d9db17537 44 Note: When the SYNC event is detected during the downcounting phase (before reaching the zero value),
mbed_official 376:cb4d9db17537 45 it means that the actual frequency is lower than the target (and so, that the TRIM value should be
mbed_official 376:cb4d9db17537 46 incremented), while when it is detected during the upcounting phase it means that the actual frequency
mbed_official 376:cb4d9db17537 47 is higher (and that the TRIM value should be decremented).
mbed_official 376:cb4d9db17537 48
mbed_official 376:cb4d9db17537 49 (#) To use IT mode, user needs to handle it in calling different macros available to do it
mbed_official 376:cb4d9db17537 50 (__HAL_RCC_CRS_XXX_IT). Interruptions will go through RCC Handler (RCC_IRQn/RCC_CRS_IRQHandler)
mbed_official 376:cb4d9db17537 51 (+++) Call function HAL_RCCEx_CRSConfig()
mbed_official 376:cb4d9db17537 52 (+++) Enable RCC_IRQn (thnaks to NVIC functions)
mbed_official 376:cb4d9db17537 53 (+++) Enable CRS IT (__HAL_RCC_CRS_ENABLE_IT)
mbed_official 376:cb4d9db17537 54 [+++) Implement CRS status management in RCC_CRS_IRQHandler
mbed_official 376:cb4d9db17537 55
mbed_official 376:cb4d9db17537 56 (#) To force a SYNC EVENT, user can use function 'HAL_RCCEx_CRSSoftwareSynchronizationGenerate()'. Function can be
mbed_official 376:cb4d9db17537 57 called before calling HAL_RCCEx_CRSConfig (for instance in Systick handler)
mbed_official 376:cb4d9db17537 58
mbed_official 376:cb4d9db17537 59 @endverbatim
mbed_official 376:cb4d9db17537 60 ******************************************************************************
mbed_official 376:cb4d9db17537 61 * @attention
mbed_official 376:cb4d9db17537 62 *
mbed_official 489:119543c9f674 63 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 376:cb4d9db17537 64 *
mbed_official 376:cb4d9db17537 65 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 376:cb4d9db17537 66 * are permitted provided that the following conditions are met:
mbed_official 376:cb4d9db17537 67 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 376:cb4d9db17537 68 * this list of conditions and the following disclaimer.
mbed_official 376:cb4d9db17537 69 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 376:cb4d9db17537 70 * this list of conditions and the following disclaimer in the documentation
mbed_official 376:cb4d9db17537 71 * and/or other materials provided with the distribution.
mbed_official 376:cb4d9db17537 72 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 376:cb4d9db17537 73 * may be used to endorse or promote products derived from this software
mbed_official 376:cb4d9db17537 74 * without specific prior written permission.
mbed_official 376:cb4d9db17537 75 *
mbed_official 376:cb4d9db17537 76 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 376:cb4d9db17537 77 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 376:cb4d9db17537 78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 376:cb4d9db17537 79 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 376:cb4d9db17537 80 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 376:cb4d9db17537 81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 376:cb4d9db17537 82 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 376:cb4d9db17537 83 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 376:cb4d9db17537 84 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 376:cb4d9db17537 85 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 376:cb4d9db17537 86 *
mbed_official 376:cb4d9db17537 87 ******************************************************************************
mbed_official 376:cb4d9db17537 88 */
mbed_official 376:cb4d9db17537 89
mbed_official 376:cb4d9db17537 90 /* Includes ------------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 91 #include "stm32l0xx_hal.h"
mbed_official 376:cb4d9db17537 92
mbed_official 376:cb4d9db17537 93 /** @addtogroup STM32L0xx_HAL_Driver
mbed_official 376:cb4d9db17537 94 * @{
mbed_official 376:cb4d9db17537 95 */
mbed_official 376:cb4d9db17537 96
mbed_official 489:119543c9f674 97 /** @addtogroup RCCEx
mbed_official 376:cb4d9db17537 98 * @brief RCC Extension HAL module driver
mbed_official 376:cb4d9db17537 99 * @{
mbed_official 376:cb4d9db17537 100 */
mbed_official 376:cb4d9db17537 101
mbed_official 376:cb4d9db17537 102 #ifdef HAL_RCC_MODULE_ENABLED
mbed_official 376:cb4d9db17537 103
mbed_official 489:119543c9f674 104 /** @defgroup RCCEx_Private_Constants
mbed_official 489:119543c9f674 105 * @{
mbed_official 489:119543c9f674 106 */
mbed_official 376:cb4d9db17537 107 /* Bit position in register */
mbed_official 376:cb4d9db17537 108 #define CRS_CFGR_FELIM_BITNUMBER 16
mbed_official 376:cb4d9db17537 109 #define CRS_CR_TRIM_BITNUMBER 8
mbed_official 376:cb4d9db17537 110 #define CRS_ISR_FECAP_BITNUMBER 16
mbed_official 376:cb4d9db17537 111
mbed_official 489:119543c9f674 112 /**
mbed_official 489:119543c9f674 113 * @}
mbed_official 489:119543c9f674 114 */
mbed_official 376:cb4d9db17537 115
mbed_official 489:119543c9f674 116 /** @addtogroup RCCEx_Exported_Functions
mbed_official 376:cb4d9db17537 117 * @{
mbed_official 376:cb4d9db17537 118 */
mbed_official 376:cb4d9db17537 119
mbed_official 489:119543c9f674 120 /** @addtogroup RCCEx_Exported_Functions_Group1
mbed_official 489:119543c9f674 121 * @brief Extended Peripheral Initialization and Control functions
mbed_official 376:cb4d9db17537 122 *
mbed_official 376:cb4d9db17537 123 @verbatim
mbed_official 376:cb4d9db17537 124 ===============================================================================
mbed_official 376:cb4d9db17537 125 ##### Extended Peripheral Control functions #####
mbed_official 376:cb4d9db17537 126 ===============================================================================
mbed_official 376:cb4d9db17537 127 [..]
mbed_official 376:cb4d9db17537 128 This subsection provides a set of functions allowing to control the RCC Clocks
mbed_official 376:cb4d9db17537 129 frequencies.
mbed_official 376:cb4d9db17537 130
mbed_official 376:cb4d9db17537 131 @endverbatim
mbed_official 376:cb4d9db17537 132 * @{
mbed_official 376:cb4d9db17537 133 */
mbed_official 376:cb4d9db17537 134
mbed_official 376:cb4d9db17537 135 /**
mbed_official 489:119543c9f674 136 * @brief Resets the RCC clock configuration to the default reset state.
mbed_official 489:119543c9f674 137 * @note The default reset state of the clock configuration is given below:
mbed_official 489:119543c9f674 138 * - MSI ON and used as system clock source (MSI range is not modified
mbed_official 489:119543c9f674 139 * - by this function, it keep the value configured by user application)
mbed_official 489:119543c9f674 140 * - HSI, HSI_OUT, HSE and PLL OFF
mbed_official 489:119543c9f674 141 * - AHB, APB1 and APB2 prescaler set to 1.
mbed_official 489:119543c9f674 142 * - CSS and MCO OFF
mbed_official 489:119543c9f674 143 * - All interrupts disabled
mbed_official 489:119543c9f674 144 * @note This function does not modify the configuration of the
mbed_official 489:119543c9f674 145 * @note -Peripheral clocks
mbed_official 489:119543c9f674 146 * @note -HSI48, LSI, LSE and RTC clocks
mbed_official 489:119543c9f674 147 * @param None
mbed_official 489:119543c9f674 148 * @retval None
mbed_official 489:119543c9f674 149 */
mbed_official 489:119543c9f674 150 void HAL_RCC_DeInit(void)
mbed_official 489:119543c9f674 151 {
mbed_official 489:119543c9f674 152 /* Set MSION bit */
mbed_official 489:119543c9f674 153 SET_BIT(RCC->CR, RCC_CR_MSION);
mbed_official 489:119543c9f674 154
mbed_official 489:119543c9f674 155 #if defined(STM32L073xx) || defined(STM32L083xx) || \
mbed_official 489:119543c9f674 156 defined(STM32L072xx) || defined(STM32L082xx) || \
mbed_official 489:119543c9f674 157 defined(STM32L071xx) || defined(STM32L081xx)
mbed_official 489:119543c9f674 158 /* Reset HSE, HSI, CSS, PLL */
mbed_official 489:119543c9f674 159 CLEAR_BIT(RCC->CR, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | RCC_CR_HSIOUTEN | \
mbed_official 489:119543c9f674 160 RCC_CR_HSEON | RCC_CR_CSSHSEON | RCC_CR_PLLON);
mbed_official 489:119543c9f674 161 #else
mbed_official 489:119543c9f674 162 CLEAR_BIT(RCC->CR, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | \
mbed_official 489:119543c9f674 163 RCC_CR_HSEON | RCC_CR_CSSHSEON | RCC_CR_PLLON);
mbed_official 489:119543c9f674 164 #endif
mbed_official 489:119543c9f674 165
mbed_official 489:119543c9f674 166 /* Reset HSEBYP bit */
mbed_official 489:119543c9f674 167 CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
mbed_official 489:119543c9f674 168
mbed_official 489:119543c9f674 169 /* Reset CFGR register */
mbed_official 489:119543c9f674 170 CLEAR_REG(RCC->CFGR);
mbed_official 489:119543c9f674 171
mbed_official 489:119543c9f674 172 /* Disable all interrupts */
mbed_official 489:119543c9f674 173 CLEAR_REG(RCC->CIER);
mbed_official 489:119543c9f674 174 }
mbed_official 489:119543c9f674 175
mbed_official 489:119543c9f674 176 /**
mbed_official 489:119543c9f674 177 * @brief Initializes the RCC extended peripherals clocks
mbed_official 489:119543c9f674 178 * @note Initializes the RCC extended peripherals clocks according to the specified parameters in the
mbed_official 376:cb4d9db17537 179 * RCC_PeriphCLKInitTypeDef.
mbed_official 376:cb4d9db17537 180 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 376:cb4d9db17537 181 * contains the configuration information for the Extended Peripherals clocks(USART1,USART2, LPUART1,
mbed_official 489:119543c9f674 182 * I2C1, I2C3, RTC, USB/RNG and LPTIM1 clocks).
mbed_official 376:cb4d9db17537 183 * @retval HAL status
mbed_official 376:cb4d9db17537 184 */
mbed_official 376:cb4d9db17537 185 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 376:cb4d9db17537 186 {
mbed_official 376:cb4d9db17537 187 uint32_t tickstart = 0;
mbed_official 376:cb4d9db17537 188 uint32_t tmpreg = 0;
mbed_official 376:cb4d9db17537 189
mbed_official 376:cb4d9db17537 190 /* Check the parameters */
mbed_official 376:cb4d9db17537 191 assert_param(IS_RCC_PERIPHCLK(PeriphClkInit->PeriphClockSelection));
mbed_official 376:cb4d9db17537 192
mbed_official 489:119543c9f674 193 #if !defined (STM32L031xx) && !defined (STM32L041xx)
mbed_official 376:cb4d9db17537 194 /*------------------------------- USART1 Configuration ------------------------*/
mbed_official 376:cb4d9db17537 195 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1)
mbed_official 376:cb4d9db17537 196 {
mbed_official 376:cb4d9db17537 197 /* Check the parameters */
mbed_official 376:cb4d9db17537 198 assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection));
mbed_official 376:cb4d9db17537 199
mbed_official 376:cb4d9db17537 200 /* Configure the USART1 clock source */
mbed_official 376:cb4d9db17537 201 __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection);
mbed_official 376:cb4d9db17537 202 }
mbed_official 489:119543c9f674 203 #endif
mbed_official 376:cb4d9db17537 204
mbed_official 376:cb4d9db17537 205 /*----------------------------- USART2 Configuration --------------------------*/
mbed_official 376:cb4d9db17537 206 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2)
mbed_official 376:cb4d9db17537 207 {
mbed_official 376:cb4d9db17537 208 /* Check the parameters */
mbed_official 376:cb4d9db17537 209 assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection));
mbed_official 376:cb4d9db17537 210
mbed_official 376:cb4d9db17537 211 /* Configure the USART2 clock source */
mbed_official 376:cb4d9db17537 212 __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection);
mbed_official 376:cb4d9db17537 213 }
mbed_official 376:cb4d9db17537 214
mbed_official 376:cb4d9db17537 215 /*------------------------------ LPUART1 Configuration ------------------------*/
mbed_official 376:cb4d9db17537 216 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1)
mbed_official 376:cb4d9db17537 217 {
mbed_official 376:cb4d9db17537 218 /* Check the parameters */
mbed_official 376:cb4d9db17537 219 assert_param(IS_RCC_LPUART1CLKSOURCE(PeriphClkInit->Lpuart1ClockSelection));
mbed_official 376:cb4d9db17537 220
mbed_official 376:cb4d9db17537 221 /* Configure the LPUAR1 clock source */
mbed_official 376:cb4d9db17537 222 __HAL_RCC_LPUART1_CONFIG(PeriphClkInit->Lpuart1ClockSelection);
mbed_official 376:cb4d9db17537 223 }
mbed_official 376:cb4d9db17537 224
mbed_official 376:cb4d9db17537 225 /*------------------------------ I2C1 Configuration ------------------------*/
mbed_official 376:cb4d9db17537 226 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1)
mbed_official 376:cb4d9db17537 227 {
mbed_official 376:cb4d9db17537 228 /* Check the parameters */
mbed_official 376:cb4d9db17537 229 assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection));
mbed_official 376:cb4d9db17537 230
mbed_official 376:cb4d9db17537 231 /* Configure the I2C1 clock source */
mbed_official 376:cb4d9db17537 232 __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection);
mbed_official 376:cb4d9db17537 233 }
mbed_official 489:119543c9f674 234
mbed_official 489:119543c9f674 235 #if defined (STM32L071xx) || (STM32L072xx) || defined(STM32L073xx) || \
mbed_official 489:119543c9f674 236 defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 237 /*------------------------------ I2C3 Configuration ------------------------*/
mbed_official 489:119543c9f674 238 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3)
mbed_official 489:119543c9f674 239 {
mbed_official 489:119543c9f674 240 /* Check the parameters */
mbed_official 489:119543c9f674 241 assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection));
mbed_official 376:cb4d9db17537 242
mbed_official 489:119543c9f674 243 /* Configure the I2C3 clock source */
mbed_official 489:119543c9f674 244 __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection);
mbed_official 489:119543c9f674 245 }
mbed_official 489:119543c9f674 246 #endif /* defined (STM32L071xx) (STM32L072xx)|| (STM32L073xx)|| (STM32L081xx)|| (STM32L082xx) || (STM32L083xx) */
mbed_official 489:119543c9f674 247
mbed_official 489:119543c9f674 248 /*---------------------------- RTC/LCD configuration -------------------------------*/
mbed_official 489:119543c9f674 249 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
mbed_official 489:119543c9f674 250 #if defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 251 || (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD)
mbed_official 489:119543c9f674 252 #endif /* defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx) */
mbed_official 489:119543c9f674 253 )
mbed_official 376:cb4d9db17537 254 {
mbed_official 376:cb4d9db17537 255 /* Enable Power Clock*/
mbed_official 489:119543c9f674 256 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 376:cb4d9db17537 257
mbed_official 376:cb4d9db17537 258 /* Enable write access to Backup domain */
mbed_official 376:cb4d9db17537 259 PWR->CR |= PWR_CR_DBP;
mbed_official 376:cb4d9db17537 260
mbed_official 376:cb4d9db17537 261 /* Wait for Backup domain Write protection disable */
mbed_official 376:cb4d9db17537 262 tickstart = HAL_GetTick();
mbed_official 376:cb4d9db17537 263
mbed_official 376:cb4d9db17537 264 while((PWR->CR & PWR_CR_DBP) == RESET)
mbed_official 376:cb4d9db17537 265 {
mbed_official 489:119543c9f674 266 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
mbed_official 376:cb4d9db17537 267 {
mbed_official 376:cb4d9db17537 268 return HAL_TIMEOUT;
mbed_official 376:cb4d9db17537 269 }
mbed_official 376:cb4d9db17537 270 }
mbed_official 376:cb4d9db17537 271
mbed_official 376:cb4d9db17537 272 /* Reset the Backup domain only if the RTC Clock source selection is modified */
mbed_official 489:119543c9f674 273 if(((RCC->CSR & RCC_CSR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL))
mbed_official 489:119543c9f674 274 #if defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 275 || (tmpreg != (PeriphClkInit->LCDClockSelection & RCC_CSR_RTCSEL))
mbed_official 489:119543c9f674 276 #endif /* defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx) */
mbed_official 489:119543c9f674 277 )
mbed_official 376:cb4d9db17537 278 {
mbed_official 376:cb4d9db17537 279 /* Store the content of CSR register before the reset of Backup Domain */
mbed_official 376:cb4d9db17537 280 tmpreg = (RCC->CSR & ~(RCC_CSR_RTCSEL));
mbed_official 376:cb4d9db17537 281 /* RTC Clock selection can be changed only if the Backup Domain is reset */
mbed_official 376:cb4d9db17537 282 __HAL_RCC_BACKUPRESET_FORCE();
mbed_official 376:cb4d9db17537 283 __HAL_RCC_BACKUPRESET_RELEASE();
mbed_official 376:cb4d9db17537 284 /* Restore the Content of CSR register */
mbed_official 376:cb4d9db17537 285 RCC->CSR = tmpreg;
mbed_official 376:cb4d9db17537 286 }
mbed_official 376:cb4d9db17537 287
mbed_official 376:cb4d9db17537 288 /* If LSE is selected as RTC clock source, wait for LSE reactivation */
mbed_official 489:119543c9f674 289 if((PeriphClkInit->RTCClockSelection == RCC_RTCCLKSOURCE_LSE)
mbed_official 489:119543c9f674 290 #if defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 291 || (PeriphClkInit->LCDClockSelection == RCC_RTCCLKSOURCE_LSE)
mbed_official 489:119543c9f674 292 #endif /* defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx) */
mbed_official 489:119543c9f674 293 )
mbed_official 376:cb4d9db17537 294 {
mbed_official 376:cb4d9db17537 295 /* Get timeout */
mbed_official 376:cb4d9db17537 296 tickstart = HAL_GetTick();
mbed_official 376:cb4d9db17537 297
mbed_official 376:cb4d9db17537 298 /* Wait till LSE is ready */
mbed_official 376:cb4d9db17537 299 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
mbed_official 376:cb4d9db17537 300 {
mbed_official 489:119543c9f674 301 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
mbed_official 376:cb4d9db17537 302 {
mbed_official 376:cb4d9db17537 303 return HAL_TIMEOUT;
mbed_official 376:cb4d9db17537 304 }
mbed_official 376:cb4d9db17537 305 }
mbed_official 376:cb4d9db17537 306 }
mbed_official 376:cb4d9db17537 307 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
mbed_official 376:cb4d9db17537 308 }
mbed_official 489:119543c9f674 309 #if !defined (STM32L031xx) && !defined (STM32L041xx) && !defined (STM32L031xx) && !defined (STM32L041xx) && !defined(STM32L051xx) && !defined(STM32L061xx) && !defined(STM32L071xx) && !defined(STM32L081xx)
mbed_official 376:cb4d9db17537 310 /*---------------------------- USB and RNG configuration --------------------*/
mbed_official 376:cb4d9db17537 311 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == (RCC_PERIPHCLK_USB))
mbed_official 376:cb4d9db17537 312 {
mbed_official 376:cb4d9db17537 313 assert_param(IS_RCC_USBCLKSOURCE(PeriphClkInit->UsbClockSelection));
mbed_official 376:cb4d9db17537 314 __HAL_RCC_USB_CONFIG(PeriphClkInit->UsbClockSelection);
mbed_official 376:cb4d9db17537 315 }
mbed_official 489:119543c9f674 316 #endif
mbed_official 376:cb4d9db17537 317
mbed_official 376:cb4d9db17537 318 /*---------------------------- LPTIM1 configuration ------------------------*/
mbed_official 376:cb4d9db17537 319 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == (RCC_PERIPHCLK_LPTIM1))
mbed_official 376:cb4d9db17537 320 {
mbed_official 376:cb4d9db17537 321 assert_param(IS_RCC_LPTIMCLK(PeriphClkInit->LptimClockSelection));
mbed_official 376:cb4d9db17537 322 __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->LptimClockSelection);
mbed_official 376:cb4d9db17537 323 }
mbed_official 376:cb4d9db17537 324 return HAL_OK;
mbed_official 376:cb4d9db17537 325 }
mbed_official 376:cb4d9db17537 326
mbed_official 489:119543c9f674 327
mbed_official 489:119543c9f674 328
mbed_official 376:cb4d9db17537 329 /**
mbed_official 489:119543c9f674 330 * @brief Get the RCC_ClkInitStruct according to the internal RCC configuration registers.
mbed_official 376:cb4d9db17537 331 * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
mbed_official 376:cb4d9db17537 332 * returns the configuration information for the Extended Peripherals clocks(USART1,USART2, LPUART1,
mbed_official 489:119543c9f674 333 * I2C1, I2C3, RTC, USB/RNG and LPTIM1 clocks).
mbed_official 376:cb4d9db17537 334 * @retval None
mbed_official 376:cb4d9db17537 335 */
mbed_official 376:cb4d9db17537 336 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
mbed_official 376:cb4d9db17537 337 {
mbed_official 376:cb4d9db17537 338 /* Set all possible values for the extended clock type parameter -----------*/
mbed_official 376:cb4d9db17537 339 /* Common part first */
mbed_official 489:119543c9f674 340 #if defined(STM32L031xx) || defined(STM32L041xx)
mbed_official 489:119543c9f674 341 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | \
mbed_official 489:119543c9f674 342 RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_LPTIM1;
mbed_official 489:119543c9f674 343 #endif
mbed_official 489:119543c9f674 344 #if defined(STM32L052xx) || defined(STM32L062xx)
mbed_official 489:119543c9f674 345 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 346 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB | \
mbed_official 489:119543c9f674 347 RCC_PERIPHCLK_LPTIM1 ;
mbed_official 489:119543c9f674 348 #endif
mbed_official 489:119543c9f674 349 #if defined(STM32L053xx) || defined(STM32L063xx)
mbed_official 376:cb4d9db17537 350 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 351 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB | \
mbed_official 489:119543c9f674 352 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LCD;
mbed_official 489:119543c9f674 353 #endif
mbed_official 489:119543c9f674 354 #if defined(STM32L072xx) || defined(STM32L082xx)
mbed_official 489:119543c9f674 355 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 356 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_RTC | \
mbed_official 489:119543c9f674 357 RCC_PERIPHCLK_USB | RCC_PERIPHCLK_LPTIM1 ;
mbed_official 489:119543c9f674 358 #endif
mbed_official 489:119543c9f674 359 #if defined(STM32L073xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 360 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 361 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_RTC | \
mbed_official 489:119543c9f674 362 RCC_PERIPHCLK_USB | RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LCD;
mbed_official 376:cb4d9db17537 363
mbed_official 489:119543c9f674 364 #endif
mbed_official 489:119543c9f674 365 #if defined(STM32L051xx) || defined(STM32L061xx)
mbed_official 376:cb4d9db17537 366 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 367 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_LPTIM1;
mbed_official 489:119543c9f674 368 #endif
mbed_official 489:119543c9f674 369 #if defined(STM32L071xx) || defined(STM32L081xx)
mbed_official 489:119543c9f674 370 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
mbed_official 489:119543c9f674 371 RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_RTC | \
mbed_official 376:cb4d9db17537 372 RCC_PERIPHCLK_LPTIM1;
mbed_official 489:119543c9f674 373 #endif
mbed_official 489:119543c9f674 374
mbed_official 489:119543c9f674 375 #if !defined (STM32L031xx) && !defined (STM32L041xx)
mbed_official 376:cb4d9db17537 376 /* Get the USART1 configuration --------------------------------------------*/
mbed_official 376:cb4d9db17537 377 PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE();
mbed_official 489:119543c9f674 378 #endif
mbed_official 376:cb4d9db17537 379 /* Get the USART2 clock source ---------------------------------------------*/
mbed_official 376:cb4d9db17537 380 PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE();
mbed_official 489:119543c9f674 381 /* Get the LPUART1 clock source ---------------------------------------------*/
mbed_official 376:cb4d9db17537 382 PeriphClkInit->Lpuart1ClockSelection = __HAL_RCC_GET_LPUART1_SOURCE();
mbed_official 376:cb4d9db17537 383 /* Get the I2C1 clock source -----------------------------------------------*/
mbed_official 376:cb4d9db17537 384 PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
mbed_official 489:119543c9f674 385 #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || \
mbed_official 489:119543c9f674 386 defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 387 /* Get the I2C3 clock source -----------------------------------------------*/
mbed_official 489:119543c9f674 388 PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE();
mbed_official 489:119543c9f674 389 #endif /* defined (STM32L071xx) || (STM32L073xx) || (STM32L082xx) || (STM32L082xx) || (STM32L083xx) */
mbed_official 376:cb4d9db17537 390 /* Get the LPTIM1 clock source -----------------------------------------------*/
mbed_official 376:cb4d9db17537 391 PeriphClkInit->LptimClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
mbed_official 376:cb4d9db17537 392 /* Get the RTC clock source -----------------------------------------------*/
mbed_official 376:cb4d9db17537 393 PeriphClkInit->RTCClockSelection = __HAL_RCC_GET_RTC_SOURCE();
mbed_official 489:119543c9f674 394 #if defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx)
mbed_official 489:119543c9f674 395 PeriphClkInit->LCDClockSelection = PeriphClkInit->RTCClockSelection;
mbed_official 489:119543c9f674 396 #endif /* defined (STM32L053xx) || defined(STM32L063xx) || defined(STM32L073xx) || defined(STM32L083xx) */
mbed_official 376:cb4d9db17537 397
mbed_official 489:119543c9f674 398 #if !defined (STM32L031xx) && !defined (STM32L041xx) && !defined(STM32L051xx) && !defined(STM32L061xx) && !defined(STM32L071xx) && !defined(STM32L081xx)
mbed_official 376:cb4d9db17537 399 /* Get the USB/RNG clock source -----------------------------------------------*/
mbed_official 376:cb4d9db17537 400 PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
mbed_official 489:119543c9f674 401 #endif
mbed_official 376:cb4d9db17537 402 }
mbed_official 376:cb4d9db17537 403
mbed_official 376:cb4d9db17537 404 /**
mbed_official 376:cb4d9db17537 405 * @brief Enables the LSE Clock Security System.
mbed_official 376:cb4d9db17537 406 * @param None
mbed_official 376:cb4d9db17537 407 * @retval None
mbed_official 376:cb4d9db17537 408 */
mbed_official 376:cb4d9db17537 409 void HAL_RCCEx_EnableLSECSS(void)
mbed_official 376:cb4d9db17537 410 {
mbed_official 376:cb4d9db17537 411 SET_BIT(RCC->CSR, RCC_CSR_LSECSSON) ;
mbed_official 376:cb4d9db17537 412 }
mbed_official 376:cb4d9db17537 413
mbed_official 376:cb4d9db17537 414 /**
mbed_official 376:cb4d9db17537 415 * @brief Disables the LSE Clock Security System.
mbed_official 376:cb4d9db17537 416 * @param None
mbed_official 376:cb4d9db17537 417 * @retval None
mbed_official 376:cb4d9db17537 418 */
mbed_official 376:cb4d9db17537 419 void HAL_RCCEx_DisableLSECSS(void)
mbed_official 376:cb4d9db17537 420 {
mbed_official 376:cb4d9db17537 421 CLEAR_BIT(RCC->CSR, RCC_CSR_LSECSSON) ;
mbed_official 376:cb4d9db17537 422 }
mbed_official 376:cb4d9db17537 423
mbed_official 489:119543c9f674 424 #if !defined (STM32L031xx) && !defined (STM32L041xx) && !defined(STM32L051xx) && !defined(STM32L061xx) && !defined(STM32L071xx) && !defined(STM32L081xx)
mbed_official 376:cb4d9db17537 425
mbed_official 376:cb4d9db17537 426 /**
mbed_official 376:cb4d9db17537 427 * @brief Start automatic synchronization using polling mode
mbed_official 376:cb4d9db17537 428 * @param pInit Pointer on RCC_CRSInitTypeDef structure
mbed_official 376:cb4d9db17537 429 * @retval None
mbed_official 376:cb4d9db17537 430 */
mbed_official 376:cb4d9db17537 431 void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit)
mbed_official 376:cb4d9db17537 432 {
mbed_official 376:cb4d9db17537 433 /* Check the parameters */
mbed_official 376:cb4d9db17537 434 assert_param(IS_RCC_CRS_SYNC_DIV(pInit->Prescaler));
mbed_official 376:cb4d9db17537 435 assert_param(IS_RCC_CRS_SYNC_SOURCE(pInit->Source));
mbed_official 376:cb4d9db17537 436 assert_param(IS_RCC_CRS_SYNC_POLARITY(pInit->Polarity));
mbed_official 376:cb4d9db17537 437 assert_param(IS_RCC_CRS_RELOADVALUE(pInit->ReloadValue));
mbed_official 376:cb4d9db17537 438 assert_param(IS_RCC_CRS_ERRORLIMIT(pInit->ErrorLimitValue));
mbed_official 376:cb4d9db17537 439 assert_param(IS_RCC_CRS_HSI48CALIBRATION(pInit->HSI48CalibrationValue));
mbed_official 376:cb4d9db17537 440
mbed_official 376:cb4d9db17537 441
mbed_official 376:cb4d9db17537 442 /* CONFIGURATION */
mbed_official 376:cb4d9db17537 443
mbed_official 376:cb4d9db17537 444 /* Before configuration, reset CRS registers to their default values*/
mbed_official 489:119543c9f674 445 __HAL_RCC_CRS_FORCE_RESET();
mbed_official 489:119543c9f674 446 __HAL_RCC_CRS_RELEASE_RESET();
mbed_official 376:cb4d9db17537 447
mbed_official 376:cb4d9db17537 448 /* Configure Synchronization input */
mbed_official 376:cb4d9db17537 449 /* Clear SYNCDIV[2:0], SYNCSRC[1:0] & SYNCSPOL bits */
mbed_official 376:cb4d9db17537 450 CRS->CFGR &= ~(CRS_CFGR_SYNCDIV | CRS_CFGR_SYNCSRC | CRS_CFGR_SYNCPOL);
mbed_official 376:cb4d9db17537 451
mbed_official 376:cb4d9db17537 452 /* Set the CRS_CFGR_SYNCDIV[2:0] bits according to Prescaler value */
mbed_official 376:cb4d9db17537 453 CRS->CFGR |= pInit->Prescaler;
mbed_official 376:cb4d9db17537 454
mbed_official 376:cb4d9db17537 455 /* Set the SYNCSRC[1:0] bits according to Source value */
mbed_official 376:cb4d9db17537 456 CRS->CFGR |= pInit->Source;
mbed_official 376:cb4d9db17537 457
mbed_official 376:cb4d9db17537 458 /* Set the SYNCSPOL bits according to Polarity value */
mbed_official 376:cb4d9db17537 459 CRS->CFGR |= pInit->Polarity;
mbed_official 376:cb4d9db17537 460
mbed_official 376:cb4d9db17537 461 /* Configure Frequency Error Measurement */
mbed_official 376:cb4d9db17537 462 /* Clear RELOAD[15:0] & FELIM[7:0] bits*/
mbed_official 376:cb4d9db17537 463 CRS->CFGR &= ~(CRS_CFGR_RELOAD | CRS_CFGR_FELIM);
mbed_official 376:cb4d9db17537 464
mbed_official 376:cb4d9db17537 465 /* Set the RELOAD[15:0] bits according to ReloadValue value */
mbed_official 376:cb4d9db17537 466 CRS->CFGR |= pInit->ReloadValue;
mbed_official 376:cb4d9db17537 467
mbed_official 376:cb4d9db17537 468 /* Set the FELIM[7:0] bits according to ErrorLimitValue value */
mbed_official 376:cb4d9db17537 469 CRS->CFGR |= (pInit->ErrorLimitValue << CRS_CFGR_FELIM_BITNUMBER);
mbed_official 376:cb4d9db17537 470
mbed_official 376:cb4d9db17537 471 /* Adjust HSI48 oscillator smooth trimming */
mbed_official 376:cb4d9db17537 472 /* Clear TRIM[5:0] bits */
mbed_official 376:cb4d9db17537 473 CRS->CR &= ~CRS_CR_TRIM;
mbed_official 376:cb4d9db17537 474
mbed_official 376:cb4d9db17537 475 /* Set the TRIM[5:0] bits according to RCC_CRS_HSI48CalibrationValue value */
mbed_official 376:cb4d9db17537 476 CRS->CR |= (pInit->HSI48CalibrationValue << CRS_CR_TRIM_BITNUMBER);
mbed_official 376:cb4d9db17537 477
mbed_official 376:cb4d9db17537 478
mbed_official 376:cb4d9db17537 479 /* START AUTOMATIC SYNCHRONIZATION*/
mbed_official 376:cb4d9db17537 480
mbed_official 376:cb4d9db17537 481 /* Enable Automatic trimming */
mbed_official 376:cb4d9db17537 482 __HAL_RCC_CRS_ENABLE_AUTOMATIC_CALIB();
mbed_official 376:cb4d9db17537 483
mbed_official 376:cb4d9db17537 484 /* Enable Frequency error counter */
mbed_official 376:cb4d9db17537 485 __HAL_RCC_CRS_ENABLE_FREQ_ERROR_COUNTER();
mbed_official 376:cb4d9db17537 486
mbed_official 376:cb4d9db17537 487 }
mbed_official 376:cb4d9db17537 488
mbed_official 376:cb4d9db17537 489 /**
mbed_official 376:cb4d9db17537 490 * @brief Generate the software synchronization event
mbed_official 376:cb4d9db17537 491 * @param None
mbed_official 376:cb4d9db17537 492 * @retval None
mbed_official 376:cb4d9db17537 493 */
mbed_official 376:cb4d9db17537 494 void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void)
mbed_official 376:cb4d9db17537 495 {
mbed_official 376:cb4d9db17537 496 CRS->CR |= CRS_CR_SWSYNC;
mbed_official 376:cb4d9db17537 497 }
mbed_official 376:cb4d9db17537 498
mbed_official 376:cb4d9db17537 499
mbed_official 376:cb4d9db17537 500 /**
mbed_official 376:cb4d9db17537 501 * @brief Function to return synchronization info
mbed_official 376:cb4d9db17537 502 * @param pSynchroInfo Pointer on RCC_CRSSynchroInfoTypeDef structure
mbed_official 376:cb4d9db17537 503 * @retval None
mbed_official 376:cb4d9db17537 504 */
mbed_official 376:cb4d9db17537 505 void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo)
mbed_official 376:cb4d9db17537 506 {
mbed_official 376:cb4d9db17537 507 /* Check the parameter */
mbed_official 489:119543c9f674 508 assert_param(pSynchroInfo != NULL);
mbed_official 376:cb4d9db17537 509
mbed_official 376:cb4d9db17537 510 /* Get the reload value */
mbed_official 376:cb4d9db17537 511 pSynchroInfo->ReloadValue = (uint32_t)(CRS->CFGR & CRS_CFGR_RELOAD);
mbed_official 376:cb4d9db17537 512
mbed_official 376:cb4d9db17537 513 /* Get HSI48 oscillator smooth trimming */
mbed_official 376:cb4d9db17537 514 pSynchroInfo->HSI48CalibrationValue = (uint32_t)((CRS->CR & CRS_CR_TRIM) >> CRS_CR_TRIM_BITNUMBER);
mbed_official 376:cb4d9db17537 515
mbed_official 376:cb4d9db17537 516 /* Get Frequency error capture */
mbed_official 376:cb4d9db17537 517 pSynchroInfo->FreqErrorCapture = (uint32_t)((CRS->ISR & CRS_ISR_FECAP) >> CRS_ISR_FECAP_BITNUMBER);
mbed_official 376:cb4d9db17537 518
mbed_official 376:cb4d9db17537 519 /* Get Frequency error direction */
mbed_official 376:cb4d9db17537 520 pSynchroInfo->FreqErrorDirection = (uint32_t)(CRS->ISR & CRS_ISR_FEDIR);
mbed_official 376:cb4d9db17537 521
mbed_official 376:cb4d9db17537 522
mbed_official 376:cb4d9db17537 523 }
mbed_official 376:cb4d9db17537 524
mbed_official 376:cb4d9db17537 525 /**
mbed_official 376:cb4d9db17537 526 * @brief This function handles CRS Synchronization Timeout.
mbed_official 376:cb4d9db17537 527 * @param Timeout: Duration of the timeout
mbed_official 376:cb4d9db17537 528 * @note Timeout is based on the maximum time to receive a SYNC event based on synchronization
mbed_official 376:cb4d9db17537 529 * frequency.
mbed_official 376:cb4d9db17537 530 * @note If Timeout set to HAL_MAX_DELAY, HAL_TIMEOUT will be never returned.
mbed_official 376:cb4d9db17537 531 * @retval Combination of Synchronization status
mbed_official 376:cb4d9db17537 532 * This parameter can be a combination of the following values:
mbed_official 376:cb4d9db17537 533 * @arg RCC_CRS_TIMEOUT
mbed_official 376:cb4d9db17537 534 * @arg RCC_CRS_SYNCOK
mbed_official 376:cb4d9db17537 535 * @arg RCC_CRS_SYNCWARM
mbed_official 376:cb4d9db17537 536 * @arg RCC_CRS_SYNCERR
mbed_official 376:cb4d9db17537 537 * @arg RCC_CRS_SYNCMISS
mbed_official 376:cb4d9db17537 538 * @arg RCC_CRS_TRIMOV
mbed_official 376:cb4d9db17537 539 */
mbed_official 489:119543c9f674 540 uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout)
mbed_official 376:cb4d9db17537 541 {
mbed_official 489:119543c9f674 542 uint32_t crsstatus = RCC_CRS_NONE;
mbed_official 376:cb4d9db17537 543 uint32_t tickstart = 0;
mbed_official 376:cb4d9db17537 544
mbed_official 376:cb4d9db17537 545 /* Get timeout */
mbed_official 376:cb4d9db17537 546 tickstart = HAL_GetTick();
mbed_official 376:cb4d9db17537 547
mbed_official 376:cb4d9db17537 548 /* Check that if one of CRS flags have been set */
mbed_official 376:cb4d9db17537 549 while(RCC_CRS_NONE == crsstatus)
mbed_official 376:cb4d9db17537 550 {
mbed_official 376:cb4d9db17537 551 if(Timeout != HAL_MAX_DELAY)
mbed_official 376:cb4d9db17537 552 {
mbed_official 376:cb4d9db17537 553 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 376:cb4d9db17537 554 {
mbed_official 376:cb4d9db17537 555 crsstatus = RCC_CRS_TIMEOUT;
mbed_official 376:cb4d9db17537 556 }
mbed_official 376:cb4d9db17537 557 }
mbed_official 376:cb4d9db17537 558 /* Check CRS SYNCOK flag */
mbed_official 376:cb4d9db17537 559 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCOK))
mbed_official 376:cb4d9db17537 560 {
mbed_official 376:cb4d9db17537 561 /* CRS SYNC event OK */
mbed_official 376:cb4d9db17537 562 crsstatus |= RCC_CRS_SYNCOK;
mbed_official 376:cb4d9db17537 563
mbed_official 376:cb4d9db17537 564 /* Clear CRS SYNC event OK bit */
mbed_official 376:cb4d9db17537 565 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCOK);
mbed_official 376:cb4d9db17537 566 }
mbed_official 376:cb4d9db17537 567
mbed_official 376:cb4d9db17537 568 /* Check CRS SYNCWARN flag */
mbed_official 376:cb4d9db17537 569 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCWARN))
mbed_official 376:cb4d9db17537 570 {
mbed_official 376:cb4d9db17537 571 /* CRS SYNC warning */
mbed_official 376:cb4d9db17537 572 crsstatus |= RCC_CRS_SYNCWARM;
mbed_official 376:cb4d9db17537 573
mbed_official 376:cb4d9db17537 574 /* Clear CRS SYNCWARN bit */
mbed_official 376:cb4d9db17537 575 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCWARN);
mbed_official 376:cb4d9db17537 576 }
mbed_official 376:cb4d9db17537 577
mbed_official 376:cb4d9db17537 578 /* Check CRS TRIM overflow flag */
mbed_official 376:cb4d9db17537 579 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_TRIMOVF))
mbed_official 376:cb4d9db17537 580 {
mbed_official 376:cb4d9db17537 581 /* CRS SYNC Error */
mbed_official 376:cb4d9db17537 582 crsstatus |= RCC_CRS_TRIMOV;
mbed_official 376:cb4d9db17537 583
mbed_official 376:cb4d9db17537 584 /* Clear CRS Error bit */
mbed_official 376:cb4d9db17537 585 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_TRIMOVF);
mbed_official 376:cb4d9db17537 586 }
mbed_official 376:cb4d9db17537 587
mbed_official 376:cb4d9db17537 588 /* Check CRS Error flag */
mbed_official 376:cb4d9db17537 589 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCERR))
mbed_official 376:cb4d9db17537 590 {
mbed_official 376:cb4d9db17537 591 /* CRS SYNC Error */
mbed_official 376:cb4d9db17537 592 crsstatus |= RCC_CRS_SYNCERR;
mbed_official 376:cb4d9db17537 593
mbed_official 376:cb4d9db17537 594 /* Clear CRS Error bit */
mbed_official 376:cb4d9db17537 595 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCERR);
mbed_official 376:cb4d9db17537 596 }
mbed_official 376:cb4d9db17537 597
mbed_official 376:cb4d9db17537 598 /* Check CRS SYNC Missed flag */
mbed_official 376:cb4d9db17537 599 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCMISS))
mbed_official 376:cb4d9db17537 600 {
mbed_official 376:cb4d9db17537 601 /* CRS SYNC Missed */
mbed_official 376:cb4d9db17537 602 crsstatus |= RCC_CRS_SYNCMISS;
mbed_official 376:cb4d9db17537 603
mbed_official 376:cb4d9db17537 604 /* Clear CRS SYNC Missed bit */
mbed_official 376:cb4d9db17537 605 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCMISS);
mbed_official 376:cb4d9db17537 606 }
mbed_official 376:cb4d9db17537 607
mbed_official 376:cb4d9db17537 608 /* Check CRS Expected SYNC flag */
mbed_official 376:cb4d9db17537 609 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_ESYNC))
mbed_official 376:cb4d9db17537 610 {
mbed_official 376:cb4d9db17537 611 /* frequency error counter reached a zero value */
mbed_official 376:cb4d9db17537 612 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_ESYNC);
mbed_official 376:cb4d9db17537 613 }
mbed_official 376:cb4d9db17537 614 }
mbed_official 489:119543c9f674 615
mbed_official 376:cb4d9db17537 616 return crsstatus;
mbed_official 489:119543c9f674 617 }
mbed_official 489:119543c9f674 618 /**
mbed_official 489:119543c9f674 619 * @brief Enables Vrefint for the HSI48.
mbed_official 489:119543c9f674 620 * @param None
mbed_official 489:119543c9f674 621 * @note This is functional only if the LOCK is not set
mbed_official 489:119543c9f674 622 * @retval None
mbed_official 489:119543c9f674 623 */
mbed_official 489:119543c9f674 624 void HAL_RCCEx_EnableHSI48_VREFINT(void)
mbed_official 489:119543c9f674 625 {
mbed_official 489:119543c9f674 626 /* Enable the Buffer for the ADC by setting EN_VREFINT bit */
mbed_official 489:119543c9f674 627 /* and the SYSCFG_CFGR3_ENREF_HSI48 in the CFGR3 register */
mbed_official 489:119543c9f674 628 SET_BIT (SYSCFG->CFGR3, (SYSCFG_CFGR3_ENREF_HSI48 | SYSCFG_CFGR3_EN_VREFINT));
mbed_official 376:cb4d9db17537 629 }
mbed_official 489:119543c9f674 630
mbed_official 489:119543c9f674 631 /**
mbed_official 489:119543c9f674 632 * @brief Disables the Vrefint for the HSI48.
mbed_official 489:119543c9f674 633 * @param None.
mbed_official 489:119543c9f674 634 * @note This is functional only if the LOCK is not set
mbed_official 489:119543c9f674 635 * @retval None
mbed_official 489:119543c9f674 636 */
mbed_official 489:119543c9f674 637 void HAL_RCCEx_DisableHSI48_VREFINT(void)
mbed_official 489:119543c9f674 638 {
mbed_official 489:119543c9f674 639 /* Disable the Vrefint by resetting SYSCFG_CFGR3_ENREF_HSI48 bit */
mbed_official 489:119543c9f674 640 /* and the EN_VREFINT bit in the CFGR3 register */
mbed_official 489:119543c9f674 641 CLEAR_BIT(SYSCFG->CFGR3, (SYSCFG_CFGR3_ENREF_HSI48 | SYSCFG_CFGR3_EN_VREFINT));
mbed_official 489:119543c9f674 642 }
mbed_official 489:119543c9f674 643 #endif /* !defined (STM32L031xx) && !defined (STM32L041xx) && !defined(STM32L051xx) && !defined(STM32L061xx) && !defined(STM32L071xx) && !defined(STM32L081xx) */
mbed_official 489:119543c9f674 644
mbed_official 376:cb4d9db17537 645
mbed_official 376:cb4d9db17537 646 /**
mbed_official 376:cb4d9db17537 647 * @}
mbed_official 376:cb4d9db17537 648 */
mbed_official 376:cb4d9db17537 649
mbed_official 376:cb4d9db17537 650 /**
mbed_official 376:cb4d9db17537 651 * @}
mbed_official 376:cb4d9db17537 652 */
mbed_official 376:cb4d9db17537 653
mbed_official 376:cb4d9db17537 654 #endif /* HAL_RCC_MODULE_ENABLED */
mbed_official 376:cb4d9db17537 655 /**
mbed_official 376:cb4d9db17537 656 * @}
mbed_official 376:cb4d9db17537 657 */
mbed_official 376:cb4d9db17537 658
mbed_official 376:cb4d9db17537 659 /**
mbed_official 376:cb4d9db17537 660 * @}
mbed_official 376:cb4d9db17537 661 */
mbed_official 376:cb4d9db17537 662
mbed_official 376:cb4d9db17537 663 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
mbed_official 489:119543c9f674 664