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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Parent:
573:ad23fe03a082
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 573:ad23fe03a082 1 /**
mbed_official 573:ad23fe03a082 2 ******************************************************************************
mbed_official 573:ad23fe03a082 3 * @file stm32f7xx_hal_pwr_ex.c
mbed_official 573:ad23fe03a082 4 * @author MCD Application Team
mbed_official 610:813dcc80987e 5 * @version V1.0.1
mbed_official 610:813dcc80987e 6 * @date 25-June-2015
mbed_official 573:ad23fe03a082 7 * @brief Extended PWR HAL module driver.
mbed_official 573:ad23fe03a082 8 * This file provides firmware functions to manage the following
mbed_official 573:ad23fe03a082 9 * functionalities of PWR extension peripheral:
mbed_official 573:ad23fe03a082 10 * + Peripheral Extended features functions
mbed_official 573:ad23fe03a082 11 *
mbed_official 573:ad23fe03a082 12 ******************************************************************************
mbed_official 573:ad23fe03a082 13 * @attention
mbed_official 573:ad23fe03a082 14 *
mbed_official 573:ad23fe03a082 15 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 573:ad23fe03a082 16 *
mbed_official 573:ad23fe03a082 17 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 573:ad23fe03a082 18 * are permitted provided that the following conditions are met:
mbed_official 573:ad23fe03a082 19 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 573:ad23fe03a082 20 * this list of conditions and the following disclaimer.
mbed_official 573:ad23fe03a082 21 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 573:ad23fe03a082 22 * this list of conditions and the following disclaimer in the documentation
mbed_official 573:ad23fe03a082 23 * and/or other materials provided with the distribution.
mbed_official 573:ad23fe03a082 24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 573:ad23fe03a082 25 * may be used to endorse or promote products derived from this software
mbed_official 573:ad23fe03a082 26 * without specific prior written permission.
mbed_official 573:ad23fe03a082 27 *
mbed_official 573:ad23fe03a082 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 573:ad23fe03a082 29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 573:ad23fe03a082 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 573:ad23fe03a082 31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 573:ad23fe03a082 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 573:ad23fe03a082 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 573:ad23fe03a082 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 573:ad23fe03a082 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 573:ad23fe03a082 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 573:ad23fe03a082 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 573:ad23fe03a082 38 *
mbed_official 573:ad23fe03a082 39 ******************************************************************************
mbed_official 573:ad23fe03a082 40 */
mbed_official 573:ad23fe03a082 41
mbed_official 573:ad23fe03a082 42 /* Includes ------------------------------------------------------------------*/
mbed_official 573:ad23fe03a082 43 #include "stm32f7xx_hal.h"
mbed_official 573:ad23fe03a082 44
mbed_official 573:ad23fe03a082 45 /** @addtogroup STM32F7xx_HAL_Driver
mbed_official 573:ad23fe03a082 46 * @{
mbed_official 573:ad23fe03a082 47 */
mbed_official 573:ad23fe03a082 48
mbed_official 573:ad23fe03a082 49 /** @defgroup PWREx PWREx
mbed_official 573:ad23fe03a082 50 * @brief PWR HAL module driver
mbed_official 573:ad23fe03a082 51 * @{
mbed_official 573:ad23fe03a082 52 */
mbed_official 573:ad23fe03a082 53
mbed_official 573:ad23fe03a082 54 #ifdef HAL_PWR_MODULE_ENABLED
mbed_official 573:ad23fe03a082 55
mbed_official 573:ad23fe03a082 56 /* Private typedef -----------------------------------------------------------*/
mbed_official 573:ad23fe03a082 57 /* Private define ------------------------------------------------------------*/
mbed_official 573:ad23fe03a082 58 /** @addtogroup PWREx_Private_Constants
mbed_official 573:ad23fe03a082 59 * @{
mbed_official 573:ad23fe03a082 60 */
mbed_official 573:ad23fe03a082 61 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000
mbed_official 573:ad23fe03a082 62 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000
mbed_official 573:ad23fe03a082 63 #define PWR_BKPREG_TIMEOUT_VALUE 1000
mbed_official 573:ad23fe03a082 64 #define PWR_VOSRDY_TIMEOUT_VALUE 1000
mbed_official 573:ad23fe03a082 65 /**
mbed_official 573:ad23fe03a082 66 * @}
mbed_official 573:ad23fe03a082 67 */
mbed_official 573:ad23fe03a082 68
mbed_official 573:ad23fe03a082 69 /* Private macro -------------------------------------------------------------*/
mbed_official 573:ad23fe03a082 70 /* Private variables ---------------------------------------------------------*/
mbed_official 573:ad23fe03a082 71 /* Private function prototypes -----------------------------------------------*/
mbed_official 573:ad23fe03a082 72 /* Private functions ---------------------------------------------------------*/
mbed_official 573:ad23fe03a082 73 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
mbed_official 573:ad23fe03a082 74 * @{
mbed_official 573:ad23fe03a082 75 */
mbed_official 573:ad23fe03a082 76
mbed_official 573:ad23fe03a082 77 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions
mbed_official 573:ad23fe03a082 78 * @brief Peripheral Extended features functions
mbed_official 573:ad23fe03a082 79 *
mbed_official 573:ad23fe03a082 80 @verbatim
mbed_official 573:ad23fe03a082 81
mbed_official 573:ad23fe03a082 82 ===============================================================================
mbed_official 573:ad23fe03a082 83 ##### Peripheral extended features functions #####
mbed_official 573:ad23fe03a082 84 ===============================================================================
mbed_official 573:ad23fe03a082 85
mbed_official 573:ad23fe03a082 86 *** Main and Backup Regulators configuration ***
mbed_official 573:ad23fe03a082 87 ================================================
mbed_official 573:ad23fe03a082 88 [..]
mbed_official 573:ad23fe03a082 89 (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
mbed_official 573:ad23fe03a082 90 the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
mbed_official 573:ad23fe03a082 91 retained even in Standby or VBAT mode when the low power backup regulator
mbed_official 573:ad23fe03a082 92 is enabled. It can be considered as an internal EEPROM when VBAT is
mbed_official 573:ad23fe03a082 93 always present. You can use the HAL_PWREx_EnableBkUpReg() function to
mbed_official 573:ad23fe03a082 94 enable the low power backup regulator.
mbed_official 573:ad23fe03a082 95
mbed_official 573:ad23fe03a082 96 (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
mbed_official 573:ad23fe03a082 97 the backup SRAM is powered from VDD which replaces the VBAT power supply to
mbed_official 573:ad23fe03a082 98 save battery life.
mbed_official 573:ad23fe03a082 99
mbed_official 573:ad23fe03a082 100 (+) The backup SRAM is not mass erased by a tamper event. It is read
mbed_official 573:ad23fe03a082 101 protected to prevent confidential data, such as cryptographic private
mbed_official 573:ad23fe03a082 102 key, from being accessed. The backup SRAM can be erased only through
mbed_official 573:ad23fe03a082 103 the Flash interface when a protection level change from level 1 to
mbed_official 573:ad23fe03a082 104 level 0 is requested.
mbed_official 573:ad23fe03a082 105 -@- Refer to the description of Read protection (RDP) in the Flash
mbed_official 573:ad23fe03a082 106 programming manual.
mbed_official 573:ad23fe03a082 107
mbed_official 573:ad23fe03a082 108 (+) The main internal regulator can be configured to have a tradeoff between
mbed_official 573:ad23fe03a082 109 performance and power consumption when the device does not operate at
mbed_official 573:ad23fe03a082 110 the maximum frequency. This is done through __HAL_PWR_MAINREGULATORMODE_CONFIG()
mbed_official 573:ad23fe03a082 111 macro which configure VOS bit in PWR_CR register
mbed_official 573:ad23fe03a082 112
mbed_official 573:ad23fe03a082 113 Refer to the product datasheets for more details.
mbed_official 573:ad23fe03a082 114
mbed_official 573:ad23fe03a082 115 *** FLASH Power Down configuration ****
mbed_official 573:ad23fe03a082 116 =======================================
mbed_official 573:ad23fe03a082 117 [..]
mbed_official 573:ad23fe03a082 118 (+) By setting the FPDS bit in the PWR_CR register by using the
mbed_official 573:ad23fe03a082 119 HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power
mbed_official 573:ad23fe03a082 120 down mode when the device enters Stop mode. When the Flash memory
mbed_official 573:ad23fe03a082 121 is in power down mode, an additional startup delay is incurred when
mbed_official 573:ad23fe03a082 122 waking up from Stop mode.
mbed_official 573:ad23fe03a082 123
mbed_official 573:ad23fe03a082 124 *** Over-Drive and Under-Drive configuration ****
mbed_official 573:ad23fe03a082 125 =================================================
mbed_official 573:ad23fe03a082 126 [..]
mbed_official 573:ad23fe03a082 127 (+) In Run mode: the main regulator has 2 operating modes available:
mbed_official 573:ad23fe03a082 128 (++) Normal mode: The CPU and core logic operate at maximum frequency at a given
mbed_official 573:ad23fe03a082 129 voltage scaling (scale 1, scale 2 or scale 3)
mbed_official 573:ad23fe03a082 130 (++) Over-drive mode: This mode allows the CPU and the core logic to operate at a
mbed_official 573:ad23fe03a082 131 higher frequency than the normal mode for a given voltage scaling (scale 1,
mbed_official 573:ad23fe03a082 132 scale 2 or scale 3). This mode is enabled through HAL_PWREx_EnableOverDrive() function and
mbed_official 573:ad23fe03a082 133 disabled by HAL_PWREx_DisableOverDrive() function, to enter or exit from Over-drive mode please follow
mbed_official 573:ad23fe03a082 134 the sequence described in Reference manual.
mbed_official 573:ad23fe03a082 135
mbed_official 573:ad23fe03a082 136 (+) In Stop mode: the main regulator or low power regulator supplies a low power
mbed_official 573:ad23fe03a082 137 voltage to the 1.2V domain, thus preserving the content of registers
mbed_official 573:ad23fe03a082 138 and internal SRAM. 2 operating modes are available:
mbed_official 573:ad23fe03a082 139 (++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only
mbed_official 573:ad23fe03a082 140 available when the main regulator or the low power regulator is used in Scale 3 or
mbed_official 573:ad23fe03a082 141 low voltage mode.
mbed_official 573:ad23fe03a082 142 (++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only
mbed_official 573:ad23fe03a082 143 available when the main regulator or the low power regulator is in low voltage mode.
mbed_official 573:ad23fe03a082 144
mbed_official 573:ad23fe03a082 145 @endverbatim
mbed_official 573:ad23fe03a082 146 * @{
mbed_official 573:ad23fe03a082 147 */
mbed_official 573:ad23fe03a082 148
mbed_official 573:ad23fe03a082 149 /**
mbed_official 573:ad23fe03a082 150 * @brief Enables the Backup Regulator.
mbed_official 573:ad23fe03a082 151 * @retval HAL status
mbed_official 573:ad23fe03a082 152 */
mbed_official 573:ad23fe03a082 153 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
mbed_official 573:ad23fe03a082 154 {
mbed_official 573:ad23fe03a082 155 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 156
mbed_official 573:ad23fe03a082 157 /* Enable Backup regulator */
mbed_official 573:ad23fe03a082 158 PWR->CSR1 |= PWR_CSR1_BRE;
mbed_official 573:ad23fe03a082 159
mbed_official 573:ad23fe03a082 160 /* Get tick */
mbed_official 573:ad23fe03a082 161 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 162
mbed_official 573:ad23fe03a082 163 /* Wait till Backup regulator ready flag is set */
mbed_official 573:ad23fe03a082 164 while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
mbed_official 573:ad23fe03a082 165 {
mbed_official 573:ad23fe03a082 166 if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 167 {
mbed_official 573:ad23fe03a082 168 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 169 }
mbed_official 573:ad23fe03a082 170 }
mbed_official 573:ad23fe03a082 171 return HAL_OK;
mbed_official 573:ad23fe03a082 172 }
mbed_official 573:ad23fe03a082 173
mbed_official 573:ad23fe03a082 174 /**
mbed_official 573:ad23fe03a082 175 * @brief Disables the Backup Regulator.
mbed_official 573:ad23fe03a082 176 * @retval HAL status
mbed_official 573:ad23fe03a082 177 */
mbed_official 573:ad23fe03a082 178 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
mbed_official 573:ad23fe03a082 179 {
mbed_official 573:ad23fe03a082 180 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 181
mbed_official 573:ad23fe03a082 182 /* Disable Backup regulator */
mbed_official 573:ad23fe03a082 183 PWR->CSR1 &= (uint32_t)~((uint32_t)PWR_CSR1_BRE);
mbed_official 573:ad23fe03a082 184
mbed_official 573:ad23fe03a082 185 /* Get tick */
mbed_official 573:ad23fe03a082 186 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 187
mbed_official 573:ad23fe03a082 188 /* Wait till Backup regulator ready flag is set */
mbed_official 573:ad23fe03a082 189 while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
mbed_official 573:ad23fe03a082 190 {
mbed_official 573:ad23fe03a082 191 if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 192 {
mbed_official 573:ad23fe03a082 193 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 194 }
mbed_official 573:ad23fe03a082 195 }
mbed_official 573:ad23fe03a082 196 return HAL_OK;
mbed_official 573:ad23fe03a082 197 }
mbed_official 573:ad23fe03a082 198
mbed_official 573:ad23fe03a082 199 /**
mbed_official 573:ad23fe03a082 200 * @brief Enables the Flash Power Down in Stop mode.
mbed_official 573:ad23fe03a082 201 * @retval None
mbed_official 573:ad23fe03a082 202 */
mbed_official 573:ad23fe03a082 203 void HAL_PWREx_EnableFlashPowerDown(void)
mbed_official 573:ad23fe03a082 204 {
mbed_official 573:ad23fe03a082 205 /* Enable the Flash Power Down */
mbed_official 573:ad23fe03a082 206 PWR->CR1 |= PWR_CR1_FPDS;
mbed_official 573:ad23fe03a082 207 }
mbed_official 573:ad23fe03a082 208
mbed_official 573:ad23fe03a082 209 /**
mbed_official 573:ad23fe03a082 210 * @brief Disables the Flash Power Down in Stop mode.
mbed_official 573:ad23fe03a082 211 * @retval None
mbed_official 573:ad23fe03a082 212 */
mbed_official 573:ad23fe03a082 213 void HAL_PWREx_DisableFlashPowerDown(void)
mbed_official 573:ad23fe03a082 214 {
mbed_official 573:ad23fe03a082 215 /* Disable the Flash Power Down */
mbed_official 573:ad23fe03a082 216 PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_FPDS);
mbed_official 573:ad23fe03a082 217 }
mbed_official 573:ad23fe03a082 218
mbed_official 573:ad23fe03a082 219 /**
mbed_official 573:ad23fe03a082 220 * @brief Enables Main Regulator low voltage mode.
mbed_official 573:ad23fe03a082 221 * @retval None
mbed_official 573:ad23fe03a082 222 */
mbed_official 573:ad23fe03a082 223 void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
mbed_official 573:ad23fe03a082 224 {
mbed_official 573:ad23fe03a082 225 /* Enable Main regulator low voltage */
mbed_official 573:ad23fe03a082 226 PWR->CR1 |= PWR_CR1_MRUDS;
mbed_official 573:ad23fe03a082 227 }
mbed_official 573:ad23fe03a082 228
mbed_official 573:ad23fe03a082 229 /**
mbed_official 573:ad23fe03a082 230 * @brief Disables Main Regulator low voltage mode.
mbed_official 573:ad23fe03a082 231 * @retval None
mbed_official 573:ad23fe03a082 232 */
mbed_official 573:ad23fe03a082 233 void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
mbed_official 573:ad23fe03a082 234 {
mbed_official 573:ad23fe03a082 235 /* Disable Main regulator low voltage */
mbed_official 573:ad23fe03a082 236 PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_MRUDS);
mbed_official 573:ad23fe03a082 237 }
mbed_official 573:ad23fe03a082 238
mbed_official 573:ad23fe03a082 239 /**
mbed_official 573:ad23fe03a082 240 * @brief Enables Low Power Regulator low voltage mode.
mbed_official 573:ad23fe03a082 241 * @retval None
mbed_official 573:ad23fe03a082 242 */
mbed_official 573:ad23fe03a082 243 void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
mbed_official 573:ad23fe03a082 244 {
mbed_official 573:ad23fe03a082 245 /* Enable low power regulator */
mbed_official 573:ad23fe03a082 246 PWR->CR1 |= PWR_CR1_LPUDS;
mbed_official 573:ad23fe03a082 247 }
mbed_official 573:ad23fe03a082 248
mbed_official 573:ad23fe03a082 249 /**
mbed_official 573:ad23fe03a082 250 * @brief Disables Low Power Regulator low voltage mode.
mbed_official 573:ad23fe03a082 251 * @retval None
mbed_official 573:ad23fe03a082 252 */
mbed_official 573:ad23fe03a082 253 void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
mbed_official 573:ad23fe03a082 254 {
mbed_official 573:ad23fe03a082 255 /* Disable low power regulator */
mbed_official 573:ad23fe03a082 256 PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_LPUDS);
mbed_official 573:ad23fe03a082 257 }
mbed_official 573:ad23fe03a082 258
mbed_official 573:ad23fe03a082 259 /**
mbed_official 573:ad23fe03a082 260 * @brief Activates the Over-Drive mode.
mbed_official 573:ad23fe03a082 261 * @note This mode allows the CPU and the core logic to operate at a higher frequency
mbed_official 573:ad23fe03a082 262 * than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).
mbed_official 573:ad23fe03a082 263 * @note It is recommended to enter or exit Over-drive mode when the application is not running
mbed_official 573:ad23fe03a082 264 * critical tasks and when the system clock source is either HSI or HSE.
mbed_official 573:ad23fe03a082 265 * During the Over-drive switch activation, no peripheral clocks should be enabled.
mbed_official 573:ad23fe03a082 266 * The peripheral clocks must be enabled once the Over-drive mode is activated.
mbed_official 573:ad23fe03a082 267 * @retval HAL status
mbed_official 573:ad23fe03a082 268 */
mbed_official 573:ad23fe03a082 269 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
mbed_official 573:ad23fe03a082 270 {
mbed_official 573:ad23fe03a082 271 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 272
mbed_official 573:ad23fe03a082 273 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 573:ad23fe03a082 274
mbed_official 573:ad23fe03a082 275 /* Enable the Over-drive to extend the clock frequency to 216 MHz */
mbed_official 573:ad23fe03a082 276 __HAL_PWR_OVERDRIVE_ENABLE();
mbed_official 573:ad23fe03a082 277
mbed_official 573:ad23fe03a082 278 /* Get tick */
mbed_official 573:ad23fe03a082 279 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 280
mbed_official 573:ad23fe03a082 281 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
mbed_official 573:ad23fe03a082 282 {
mbed_official 573:ad23fe03a082 283 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 284 {
mbed_official 573:ad23fe03a082 285 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 286 }
mbed_official 573:ad23fe03a082 287 }
mbed_official 573:ad23fe03a082 288
mbed_official 573:ad23fe03a082 289 /* Enable the Over-drive switch */
mbed_official 573:ad23fe03a082 290 __HAL_PWR_OVERDRIVESWITCHING_ENABLE();
mbed_official 573:ad23fe03a082 291
mbed_official 573:ad23fe03a082 292 /* Get tick */
mbed_official 573:ad23fe03a082 293 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 294
mbed_official 573:ad23fe03a082 295 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
mbed_official 573:ad23fe03a082 296 {
mbed_official 573:ad23fe03a082 297 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 298 {
mbed_official 573:ad23fe03a082 299 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 300 }
mbed_official 573:ad23fe03a082 301 }
mbed_official 573:ad23fe03a082 302 return HAL_OK;
mbed_official 573:ad23fe03a082 303 }
mbed_official 573:ad23fe03a082 304
mbed_official 573:ad23fe03a082 305 /**
mbed_official 573:ad23fe03a082 306 * @brief Deactivates the Over-Drive mode.
mbed_official 573:ad23fe03a082 307 * @note This mode allows the CPU and the core logic to operate at a higher frequency
mbed_official 573:ad23fe03a082 308 * than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).
mbed_official 573:ad23fe03a082 309 * @note It is recommended to enter or exit Over-drive mode when the application is not running
mbed_official 573:ad23fe03a082 310 * critical tasks and when the system clock source is either HSI or HSE.
mbed_official 573:ad23fe03a082 311 * During the Over-drive switch activation, no peripheral clocks should be enabled.
mbed_official 573:ad23fe03a082 312 * The peripheral clocks must be enabled once the Over-drive mode is activated.
mbed_official 573:ad23fe03a082 313 * @retval HAL status
mbed_official 573:ad23fe03a082 314 */
mbed_official 573:ad23fe03a082 315 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
mbed_official 573:ad23fe03a082 316 {
mbed_official 573:ad23fe03a082 317 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 318
mbed_official 573:ad23fe03a082 319 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 573:ad23fe03a082 320
mbed_official 573:ad23fe03a082 321 /* Disable the Over-drive switch */
mbed_official 573:ad23fe03a082 322 __HAL_PWR_OVERDRIVESWITCHING_DISABLE();
mbed_official 573:ad23fe03a082 323
mbed_official 573:ad23fe03a082 324 /* Get tick */
mbed_official 573:ad23fe03a082 325 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 326
mbed_official 573:ad23fe03a082 327 while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
mbed_official 573:ad23fe03a082 328 {
mbed_official 573:ad23fe03a082 329 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 330 {
mbed_official 573:ad23fe03a082 331 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 332 }
mbed_official 573:ad23fe03a082 333 }
mbed_official 573:ad23fe03a082 334
mbed_official 573:ad23fe03a082 335 /* Disable the Over-drive */
mbed_official 573:ad23fe03a082 336 __HAL_PWR_OVERDRIVE_DISABLE();
mbed_official 573:ad23fe03a082 337
mbed_official 573:ad23fe03a082 338 /* Get tick */
mbed_official 573:ad23fe03a082 339 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 340
mbed_official 573:ad23fe03a082 341 while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
mbed_official 573:ad23fe03a082 342 {
mbed_official 573:ad23fe03a082 343 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 344 {
mbed_official 573:ad23fe03a082 345 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 346 }
mbed_official 573:ad23fe03a082 347 }
mbed_official 573:ad23fe03a082 348
mbed_official 573:ad23fe03a082 349 return HAL_OK;
mbed_official 573:ad23fe03a082 350 }
mbed_official 573:ad23fe03a082 351
mbed_official 573:ad23fe03a082 352 /**
mbed_official 573:ad23fe03a082 353 * @brief Enters in Under-Drive STOP mode.
mbed_official 573:ad23fe03a082 354 *
mbed_official 573:ad23fe03a082 355 * @note This mode can be selected only when the Under-Drive is already active
mbed_official 573:ad23fe03a082 356 *
mbed_official 573:ad23fe03a082 357 * @note This mode is enabled only with STOP low power mode.
mbed_official 573:ad23fe03a082 358 * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
mbed_official 573:ad23fe03a082 359 * mode is only available when the main regulator or the low power regulator
mbed_official 573:ad23fe03a082 360 * is in low voltage mode
mbed_official 573:ad23fe03a082 361 *
mbed_official 573:ad23fe03a082 362 * @note If the Under-drive mode was enabled, it is automatically disabled after
mbed_official 573:ad23fe03a082 363 * exiting Stop mode.
mbed_official 573:ad23fe03a082 364 * When the voltage regulator operates in Under-drive mode, an additional
mbed_official 573:ad23fe03a082 365 * startup delay is induced when waking up from Stop mode.
mbed_official 573:ad23fe03a082 366 *
mbed_official 573:ad23fe03a082 367 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 573:ad23fe03a082 368 *
mbed_official 573:ad23fe03a082 369 * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
mbed_official 573:ad23fe03a082 370 * the HSI RC oscillator is selected as system clock.
mbed_official 573:ad23fe03a082 371 *
mbed_official 573:ad23fe03a082 372 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 573:ad23fe03a082 373 * startup delay is incurred when waking up from Stop mode.
mbed_official 573:ad23fe03a082 374 * By keeping the internal regulator ON during Stop mode, the consumption
mbed_official 573:ad23fe03a082 375 * is higher although the startup time is reduced.
mbed_official 573:ad23fe03a082 376 *
mbed_official 573:ad23fe03a082 377 * @param Regulator: specifies the regulator state in STOP mode.
mbed_official 573:ad23fe03a082 378 * This parameter can be one of the following values:
mbed_official 573:ad23fe03a082 379 * @arg PWR_MAINREGULATOR_UNDERDRIVE_ON: Main Regulator in under-drive mode
mbed_official 573:ad23fe03a082 380 * and Flash memory in power-down when the device is in Stop under-drive mode
mbed_official 573:ad23fe03a082 381 * @arg PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON: Low Power Regulator in under-drive mode
mbed_official 573:ad23fe03a082 382 * and Flash memory in power-down when the device is in Stop under-drive mode
mbed_official 573:ad23fe03a082 383 * @param STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
mbed_official 573:ad23fe03a082 384 * This parameter can be one of the following values:
mbed_official 573:ad23fe03a082 385 * @arg PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction
mbed_official 573:ad23fe03a082 386 * @arg PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction
mbed_official 573:ad23fe03a082 387 * @retval None
mbed_official 573:ad23fe03a082 388 */
mbed_official 573:ad23fe03a082 389 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
mbed_official 573:ad23fe03a082 390 {
mbed_official 573:ad23fe03a082 391 uint32_t tempreg = 0;
mbed_official 573:ad23fe03a082 392 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 393
mbed_official 573:ad23fe03a082 394 /* Check the parameters */
mbed_official 573:ad23fe03a082 395 assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator));
mbed_official 573:ad23fe03a082 396 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
mbed_official 573:ad23fe03a082 397
mbed_official 573:ad23fe03a082 398 /* Enable Power ctrl clock */
mbed_official 573:ad23fe03a082 399 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 573:ad23fe03a082 400 /* Enable the Under-drive Mode ---------------------------------------------*/
mbed_official 573:ad23fe03a082 401 /* Clear Under-drive flag */
mbed_official 573:ad23fe03a082 402 __HAL_PWR_CLEAR_ODRUDR_FLAG();
mbed_official 573:ad23fe03a082 403
mbed_official 573:ad23fe03a082 404 /* Enable the Under-drive */
mbed_official 573:ad23fe03a082 405 __HAL_PWR_UNDERDRIVE_ENABLE();
mbed_official 573:ad23fe03a082 406
mbed_official 573:ad23fe03a082 407 /* Get tick */
mbed_official 573:ad23fe03a082 408 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 409
mbed_official 573:ad23fe03a082 410 /* Wait for UnderDrive mode is ready */
mbed_official 573:ad23fe03a082 411 while(__HAL_PWR_GET_FLAG(PWR_FLAG_UDRDY))
mbed_official 573:ad23fe03a082 412 {
mbed_official 573:ad23fe03a082 413 if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 414 {
mbed_official 573:ad23fe03a082 415 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 416 }
mbed_official 573:ad23fe03a082 417 }
mbed_official 573:ad23fe03a082 418
mbed_official 573:ad23fe03a082 419 /* Select the regulator state in STOP mode ---------------------------------*/
mbed_official 573:ad23fe03a082 420 tempreg = PWR->CR1;
mbed_official 573:ad23fe03a082 421 /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
mbed_official 573:ad23fe03a082 422 tempreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS);
mbed_official 573:ad23fe03a082 423
mbed_official 573:ad23fe03a082 424 /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
mbed_official 573:ad23fe03a082 425 tempreg |= Regulator;
mbed_official 573:ad23fe03a082 426
mbed_official 573:ad23fe03a082 427 /* Store the new value */
mbed_official 573:ad23fe03a082 428 PWR->CR1 = tempreg;
mbed_official 573:ad23fe03a082 429
mbed_official 573:ad23fe03a082 430 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 573:ad23fe03a082 431 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 573:ad23fe03a082 432
mbed_official 573:ad23fe03a082 433 /* Select STOP mode entry --------------------------------------------------*/
mbed_official 573:ad23fe03a082 434 if(STOPEntry == PWR_SLEEPENTRY_WFI)
mbed_official 573:ad23fe03a082 435 {
mbed_official 573:ad23fe03a082 436 /* Request Wait For Interrupt */
mbed_official 573:ad23fe03a082 437 __WFI();
mbed_official 573:ad23fe03a082 438 }
mbed_official 573:ad23fe03a082 439 else
mbed_official 573:ad23fe03a082 440 {
mbed_official 573:ad23fe03a082 441 /* Request Wait For Event */
mbed_official 573:ad23fe03a082 442 __WFE();
mbed_official 573:ad23fe03a082 443 }
mbed_official 573:ad23fe03a082 444 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 573:ad23fe03a082 445 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 573:ad23fe03a082 446
mbed_official 573:ad23fe03a082 447 return HAL_OK;
mbed_official 573:ad23fe03a082 448 }
mbed_official 573:ad23fe03a082 449
mbed_official 573:ad23fe03a082 450 /**
mbed_official 573:ad23fe03a082 451 * @brief Returns Voltage Scaling Range.
mbed_official 573:ad23fe03a082 452 * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or
mbed_official 573:ad23fe03a082 453 * PWR_REGULATOR_VOLTAGE_SCALE3)PWR_REGULATOR_VOLTAGE_SCALE1
mbed_official 573:ad23fe03a082 454 */
mbed_official 573:ad23fe03a082 455 uint32_t HAL_PWREx_GetVoltageRange(void)
mbed_official 573:ad23fe03a082 456 {
mbed_official 573:ad23fe03a082 457 return (PWR->CR1 & PWR_CR1_VOS);
mbed_official 573:ad23fe03a082 458 }
mbed_official 573:ad23fe03a082 459
mbed_official 573:ad23fe03a082 460 /**
mbed_official 573:ad23fe03a082 461 * @brief Configures the main internal regulator output voltage.
mbed_official 573:ad23fe03a082 462 * @param VoltageScaling: specifies the regulator output voltage to achieve
mbed_official 573:ad23fe03a082 463 * a tradeoff between performance and power consumption.
mbed_official 573:ad23fe03a082 464 * This parameter can be one of the following values:
mbed_official 573:ad23fe03a082 465 * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode,
mbed_official 573:ad23fe03a082 466 * typical output voltage at 1.4 V,
mbed_official 573:ad23fe03a082 467 * system frequency up to 216 MHz.
mbed_official 573:ad23fe03a082 468 * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode,
mbed_official 573:ad23fe03a082 469 * typical output voltage at 1.2 V,
mbed_official 573:ad23fe03a082 470 * system frequency up to 180 MHz.
mbed_official 573:ad23fe03a082 471 * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output range 2 mode,
mbed_official 573:ad23fe03a082 472 * typical output voltage at 1.00 V,
mbed_official 573:ad23fe03a082 473 * system frequency up to 151 MHz.
mbed_official 573:ad23fe03a082 474 * @note To update the system clock frequency(SYSCLK):
mbed_official 573:ad23fe03a082 475 * - Set the HSI or HSE as system clock frequency using the HAL_RCC_ClockConfig().
mbed_official 573:ad23fe03a082 476 * - Call the HAL_RCC_OscConfig() to configure the PLL.
mbed_official 573:ad23fe03a082 477 * - Call HAL_PWREx_ConfigVoltageScaling() API to adjust the voltage scale.
mbed_official 573:ad23fe03a082 478 * - Set the new system clock frequency using the HAL_RCC_ClockConfig().
mbed_official 573:ad23fe03a082 479 * @note The scale can be modified only when the HSI or HSE clock source is selected
mbed_official 573:ad23fe03a082 480 * as system clock source, otherwise the API returns HAL_ERROR.
mbed_official 573:ad23fe03a082 481 * @note When the PLL is OFF, the voltage scale 3 is automatically selected and the VOS bits
mbed_official 573:ad23fe03a082 482 * value in the PWR_CR1 register are not taken in account.
mbed_official 573:ad23fe03a082 483 * @note This API forces the PLL state ON to allow the possibility to configure the voltage scale 1 or 2.
mbed_official 573:ad23fe03a082 484 * @note The new voltage scale is active only when the PLL is ON.
mbed_official 573:ad23fe03a082 485 * @retval HAL Status
mbed_official 573:ad23fe03a082 486 */
mbed_official 573:ad23fe03a082 487 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
mbed_official 573:ad23fe03a082 488 {
mbed_official 573:ad23fe03a082 489 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 490
mbed_official 573:ad23fe03a082 491 assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));
mbed_official 573:ad23fe03a082 492
mbed_official 573:ad23fe03a082 493 /* Enable Power ctrl clock */
mbed_official 573:ad23fe03a082 494 __HAL_RCC_PWR_CLK_ENABLE();
mbed_official 573:ad23fe03a082 495
mbed_official 573:ad23fe03a082 496 /* Check if the PLL is used as system clock or not */
mbed_official 573:ad23fe03a082 497 if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
mbed_official 573:ad23fe03a082 498 {
mbed_official 573:ad23fe03a082 499 /* Disable the main PLL */
mbed_official 573:ad23fe03a082 500 __HAL_RCC_PLL_DISABLE();
mbed_official 573:ad23fe03a082 501
mbed_official 573:ad23fe03a082 502 /* Get Start Tick */
mbed_official 573:ad23fe03a082 503 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 504 /* Wait till PLL is disabled */
mbed_official 573:ad23fe03a082 505 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
mbed_official 573:ad23fe03a082 506 {
mbed_official 573:ad23fe03a082 507 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 508 {
mbed_official 573:ad23fe03a082 509 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 510 }
mbed_official 573:ad23fe03a082 511 }
mbed_official 573:ad23fe03a082 512
mbed_official 573:ad23fe03a082 513 /* Set Range */
mbed_official 573:ad23fe03a082 514 __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
mbed_official 573:ad23fe03a082 515
mbed_official 573:ad23fe03a082 516 /* Enable the main PLL */
mbed_official 573:ad23fe03a082 517 __HAL_RCC_PLL_ENABLE();
mbed_official 573:ad23fe03a082 518
mbed_official 573:ad23fe03a082 519 /* Get Start Tick */
mbed_official 573:ad23fe03a082 520 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 521 /* Wait till PLL is ready */
mbed_official 573:ad23fe03a082 522 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
mbed_official 573:ad23fe03a082 523 {
mbed_official 573:ad23fe03a082 524 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 525 {
mbed_official 573:ad23fe03a082 526 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 527 }
mbed_official 573:ad23fe03a082 528 }
mbed_official 573:ad23fe03a082 529
mbed_official 573:ad23fe03a082 530 /* Get Start Tick */
mbed_official 573:ad23fe03a082 531 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 532 while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))
mbed_official 573:ad23fe03a082 533 {
mbed_official 573:ad23fe03a082 534 if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 535 {
mbed_official 573:ad23fe03a082 536 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 537 }
mbed_official 573:ad23fe03a082 538 }
mbed_official 573:ad23fe03a082 539 }
mbed_official 573:ad23fe03a082 540 else
mbed_official 573:ad23fe03a082 541 {
mbed_official 573:ad23fe03a082 542 return HAL_ERROR;
mbed_official 573:ad23fe03a082 543 }
mbed_official 573:ad23fe03a082 544 return HAL_OK;
mbed_official 573:ad23fe03a082 545 }
mbed_official 573:ad23fe03a082 546
mbed_official 573:ad23fe03a082 547 /**
mbed_official 573:ad23fe03a082 548 * @}
mbed_official 573:ad23fe03a082 549 */
mbed_official 573:ad23fe03a082 550
mbed_official 573:ad23fe03a082 551 /**
mbed_official 573:ad23fe03a082 552 * @}
mbed_official 573:ad23fe03a082 553 */
mbed_official 573:ad23fe03a082 554
mbed_official 573:ad23fe03a082 555 #endif /* HAL_PWR_MODULE_ENABLED */
mbed_official 573:ad23fe03a082 556 /**
mbed_official 573:ad23fe03a082 557 * @}
mbed_official 573:ad23fe03a082 558 */
mbed_official 573:ad23fe03a082 559
mbed_official 573:ad23fe03a082 560 /**
mbed_official 573:ad23fe03a082 561 * @}
mbed_official 573:ad23fe03a082 562 */
mbed_official 573:ad23fe03a082 563
mbed_official 573:ad23fe03a082 564 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/