mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_pwr.c@87:085cde657901, 2014-02-08 (annotated)
- Committer:
- mbed_official
- Date:
- Sat Feb 08 19:45:06 2014 +0000
- Revision:
- 87:085cde657901
- Child:
- 106:ced8cbb51063
Synchronized with git revision 9272cdeb45ec7e6077641536509413da8fd2ebc2
Full URL: https://github.com/mbedmicro/mbed/commit/9272cdeb45ec7e6077641536509413da8fd2ebc2/
Add NUCLEO_F401RE, improvements
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_pwr.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 87:085cde657901 | 5 | * @version V1.0.0RC2 |
mbed_official | 87:085cde657901 | 6 | * @date 04-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief PWR HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the Power Controller (PWR) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 11 | * + Peripheral Control functions |
mbed_official | 87:085cde657901 | 12 | * |
mbed_official | 87:085cde657901 | 13 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 14 | * @attention |
mbed_official | 87:085cde657901 | 15 | * |
mbed_official | 87:085cde657901 | 16 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 17 | * |
mbed_official | 87:085cde657901 | 18 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 19 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 20 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 21 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 22 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 23 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 24 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 25 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 26 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 27 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 28 | * |
mbed_official | 87:085cde657901 | 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 30 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 32 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 39 | * |
mbed_official | 87:085cde657901 | 40 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 41 | */ |
mbed_official | 87:085cde657901 | 42 | |
mbed_official | 87:085cde657901 | 43 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 44 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 45 | |
mbed_official | 87:085cde657901 | 46 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 47 | * @{ |
mbed_official | 87:085cde657901 | 48 | */ |
mbed_official | 87:085cde657901 | 49 | |
mbed_official | 87:085cde657901 | 50 | /** @defgroup PWR |
mbed_official | 87:085cde657901 | 51 | * @brief PWR HAL module driver |
mbed_official | 87:085cde657901 | 52 | * @{ |
mbed_official | 87:085cde657901 | 53 | */ |
mbed_official | 87:085cde657901 | 54 | |
mbed_official | 87:085cde657901 | 55 | #ifdef HAL_PWR_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 56 | |
mbed_official | 87:085cde657901 | 57 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 58 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 59 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 60 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 61 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 62 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 63 | |
mbed_official | 87:085cde657901 | 64 | /** @defgroup PWR_Private_Functions |
mbed_official | 87:085cde657901 | 65 | * @{ |
mbed_official | 87:085cde657901 | 66 | */ |
mbed_official | 87:085cde657901 | 67 | |
mbed_official | 87:085cde657901 | 68 | /** @defgroup PWR_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 69 | * @brief Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 70 | * |
mbed_official | 87:085cde657901 | 71 | @verbatim |
mbed_official | 87:085cde657901 | 72 | =============================================================================== |
mbed_official | 87:085cde657901 | 73 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 74 | =============================================================================== |
mbed_official | 87:085cde657901 | 75 | [..] |
mbed_official | 87:085cde657901 | 76 | After reset, the backup domain (RTC registers, RTC backup data |
mbed_official | 87:085cde657901 | 77 | registers and backup SRAM) is protected against possible unwanted |
mbed_official | 87:085cde657901 | 78 | write accesses. |
mbed_official | 87:085cde657901 | 79 | To enable access to the RTC Domain and RTC registers, proceed as follows: |
mbed_official | 87:085cde657901 | 80 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
mbed_official | 87:085cde657901 | 81 | __PWR_CLK_ENABLE() macro. |
mbed_official | 87:085cde657901 | 82 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
mbed_official | 87:085cde657901 | 83 | |
mbed_official | 87:085cde657901 | 84 | @endverbatim |
mbed_official | 87:085cde657901 | 85 | * @{ |
mbed_official | 87:085cde657901 | 86 | */ |
mbed_official | 87:085cde657901 | 87 | |
mbed_official | 87:085cde657901 | 88 | /** |
mbed_official | 87:085cde657901 | 89 | * @brief Deinitializes the HAL PWR peripheral registers to their default reset values. |
mbed_official | 87:085cde657901 | 90 | * @param None |
mbed_official | 87:085cde657901 | 91 | * @retval None |
mbed_official | 87:085cde657901 | 92 | */ |
mbed_official | 87:085cde657901 | 93 | void HAL_PWR_DeInit(void) |
mbed_official | 87:085cde657901 | 94 | { |
mbed_official | 87:085cde657901 | 95 | __PWR_FORCE_RESET(); |
mbed_official | 87:085cde657901 | 96 | __PWR_RELEASE_RESET(); |
mbed_official | 87:085cde657901 | 97 | } |
mbed_official | 87:085cde657901 | 98 | |
mbed_official | 87:085cde657901 | 99 | /** |
mbed_official | 87:085cde657901 | 100 | * @brief Enables access to the backup domain (RTC registers, RTC |
mbed_official | 87:085cde657901 | 101 | * backup data registers and backup SRAM). |
mbed_official | 87:085cde657901 | 102 | * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the |
mbed_official | 87:085cde657901 | 103 | * Backup Domain Access should be kept enabled. |
mbed_official | 87:085cde657901 | 104 | * @param None |
mbed_official | 87:085cde657901 | 105 | * @retval None |
mbed_official | 87:085cde657901 | 106 | */ |
mbed_official | 87:085cde657901 | 107 | void HAL_PWR_EnableBkUpAccess(void) |
mbed_official | 87:085cde657901 | 108 | { |
mbed_official | 87:085cde657901 | 109 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE; |
mbed_official | 87:085cde657901 | 110 | } |
mbed_official | 87:085cde657901 | 111 | |
mbed_official | 87:085cde657901 | 112 | /** |
mbed_official | 87:085cde657901 | 113 | * @brief Disables access to the backup domain (RTC registers, RTC |
mbed_official | 87:085cde657901 | 114 | * backup data registers and backup SRAM). |
mbed_official | 87:085cde657901 | 115 | * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the |
mbed_official | 87:085cde657901 | 116 | * Backup Domain Access should be kept enabled. |
mbed_official | 87:085cde657901 | 117 | * @param None |
mbed_official | 87:085cde657901 | 118 | * @retval None |
mbed_official | 87:085cde657901 | 119 | */ |
mbed_official | 87:085cde657901 | 120 | void HAL_PWR_DisableBkUpAccess(void) |
mbed_official | 87:085cde657901 | 121 | { |
mbed_official | 87:085cde657901 | 122 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE; |
mbed_official | 87:085cde657901 | 123 | } |
mbed_official | 87:085cde657901 | 124 | |
mbed_official | 87:085cde657901 | 125 | /** |
mbed_official | 87:085cde657901 | 126 | * @} |
mbed_official | 87:085cde657901 | 127 | */ |
mbed_official | 87:085cde657901 | 128 | |
mbed_official | 87:085cde657901 | 129 | /** @defgroup PWR_Group2 Peripheral Control functions |
mbed_official | 87:085cde657901 | 130 | * @brief Low Power modes configuration functions |
mbed_official | 87:085cde657901 | 131 | * |
mbed_official | 87:085cde657901 | 132 | @verbatim |
mbed_official | 87:085cde657901 | 133 | |
mbed_official | 87:085cde657901 | 134 | =============================================================================== |
mbed_official | 87:085cde657901 | 135 | ##### Peripheral Control functions ##### |
mbed_official | 87:085cde657901 | 136 | =============================================================================== |
mbed_official | 87:085cde657901 | 137 | |
mbed_official | 87:085cde657901 | 138 | *** PVD configuration *** |
mbed_official | 87:085cde657901 | 139 | ========================= |
mbed_official | 87:085cde657901 | 140 | [..] |
mbed_official | 87:085cde657901 | 141 | (+) The PVD is used to monitor the VDD power supply by comparing it to a |
mbed_official | 87:085cde657901 | 142 | threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR). |
mbed_official | 87:085cde657901 | 143 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower |
mbed_official | 87:085cde657901 | 144 | than the PVD threshold. This event is internally connected to the EXTI |
mbed_official | 87:085cde657901 | 145 | line16 and can generate an interrupt if enabled. This is done through |
mbed_official | 87:085cde657901 | 146 | __HAL_PVD_EXTI_ENABLE_IT() macro. |
mbed_official | 87:085cde657901 | 147 | (+) The PVD is stopped in Standby mode. |
mbed_official | 87:085cde657901 | 148 | |
mbed_official | 87:085cde657901 | 149 | *** WakeUp pin configuration *** |
mbed_official | 87:085cde657901 | 150 | ================================ |
mbed_official | 87:085cde657901 | 151 | [..] |
mbed_official | 87:085cde657901 | 152 | (+) WakeUp pin is used to wake up the system from Standby mode. This pin is |
mbed_official | 87:085cde657901 | 153 | forced in input pull-down configuration and is active on rising edges. |
mbed_official | 87:085cde657901 | 154 | (+) There is only one WakeUp pin: WakeUp Pin 1 on PA.00. |
mbed_official | 87:085cde657901 | 155 | |
mbed_official | 87:085cde657901 | 156 | *** Low Power modes configuration *** |
mbed_official | 87:085cde657901 | 157 | ===================================== |
mbed_official | 87:085cde657901 | 158 | [..] |
mbed_official | 87:085cde657901 | 159 | The devices feature 3 low-power modes: |
mbed_official | 87:085cde657901 | 160 | (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running. |
mbed_official | 87:085cde657901 | 161 | (+) Stop mode: all clocks are stopped, regulator running, regulator |
mbed_official | 87:085cde657901 | 162 | in low power mode |
mbed_official | 87:085cde657901 | 163 | (+) Standby mode: 1.2V domain powered off. |
mbed_official | 87:085cde657901 | 164 | |
mbed_official | 87:085cde657901 | 165 | *** Sleep mode *** |
mbed_official | 87:085cde657901 | 166 | ================== |
mbed_official | 87:085cde657901 | 167 | [..] |
mbed_official | 87:085cde657901 | 168 | (+) Entry: |
mbed_official | 87:085cde657901 | 169 | The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI) |
mbed_official | 87:085cde657901 | 170 | functions with |
mbed_official | 87:085cde657901 | 171 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
mbed_official | 87:085cde657901 | 172 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
mbed_official | 87:085cde657901 | 173 | |
mbed_official | 87:085cde657901 | 174 | -@@- The Regulator parameter is not used for the STM32F4 family |
mbed_official | 87:085cde657901 | 175 | and is kept as parameter just to maintain compatibility with the |
mbed_official | 87:085cde657901 | 176 | lower power families (STM32L). |
mbed_official | 87:085cde657901 | 177 | (+) Exit: |
mbed_official | 87:085cde657901 | 178 | Any peripheral interrupt acknowledged by the nested vectored interrupt |
mbed_official | 87:085cde657901 | 179 | controller (NVIC) can wake up the device from Sleep mode. |
mbed_official | 87:085cde657901 | 180 | |
mbed_official | 87:085cde657901 | 181 | *** Stop mode *** |
mbed_official | 87:085cde657901 | 182 | ================= |
mbed_official | 87:085cde657901 | 183 | [..] |
mbed_official | 87:085cde657901 | 184 | In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI, |
mbed_official | 87:085cde657901 | 185 | and the HSE RC oscillators are disabled. Internal SRAM and register contents |
mbed_official | 87:085cde657901 | 186 | are preserved. |
mbed_official | 87:085cde657901 | 187 | The voltage regulator can be configured either in normal or low-power mode. |
mbed_official | 87:085cde657901 | 188 | To minimize the consumption In Stop mode, FLASH can be powered off before |
mbed_official | 87:085cde657901 | 189 | entering the Stop mode using the HAL_PWR_EnableFlashPowerDown() function. |
mbed_official | 87:085cde657901 | 190 | It can be switched on again by software after exiting the Stop mode using |
mbed_official | 87:085cde657901 | 191 | the HAL_PWR_DisableFlashPowerDown() function. |
mbed_official | 87:085cde657901 | 192 | |
mbed_official | 87:085cde657901 | 193 | (+) Entry: |
mbed_official | 87:085cde657901 | 194 | The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON) |
mbed_official | 87:085cde657901 | 195 | function with: |
mbed_official | 87:085cde657901 | 196 | (++) Main regulator ON. |
mbed_official | 87:085cde657901 | 197 | (++) Low Power regulator ON. |
mbed_official | 87:085cde657901 | 198 | (+) Exit: |
mbed_official | 87:085cde657901 | 199 | Any EXTI Line (Internal or External) configured in Interrupt/Event mode. |
mbed_official | 87:085cde657901 | 200 | |
mbed_official | 87:085cde657901 | 201 | *** Standby mode *** |
mbed_official | 87:085cde657901 | 202 | ==================== |
mbed_official | 87:085cde657901 | 203 | [..] |
mbed_official | 87:085cde657901 | 204 | (+) |
mbed_official | 87:085cde657901 | 205 | The Standby mode allows to achieve the lowest power consumption. It is based |
mbed_official | 87:085cde657901 | 206 | on the Cortex-M4 deep sleep mode, with the voltage regulator disabled. |
mbed_official | 87:085cde657901 | 207 | The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and |
mbed_official | 87:085cde657901 | 208 | the HSE oscillator are also switched off. SRAM and register contents are lost |
mbed_official | 87:085cde657901 | 209 | except for the RTC registers, RTC backup registers, backup SRAM and Standby |
mbed_official | 87:085cde657901 | 210 | circuitry. |
mbed_official | 87:085cde657901 | 211 | |
mbed_official | 87:085cde657901 | 212 | The voltage regulator is OFF. |
mbed_official | 87:085cde657901 | 213 | |
mbed_official | 87:085cde657901 | 214 | (++) Entry: |
mbed_official | 87:085cde657901 | 215 | (+++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function. |
mbed_official | 87:085cde657901 | 216 | (++) Exit: |
mbed_official | 87:085cde657901 | 217 | (+++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, |
mbed_official | 87:085cde657901 | 218 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset. |
mbed_official | 87:085cde657901 | 219 | |
mbed_official | 87:085cde657901 | 220 | *** Auto-wakeup (AWU) from low-power mode *** |
mbed_official | 87:085cde657901 | 221 | ============================================= |
mbed_official | 87:085cde657901 | 222 | [..] |
mbed_official | 87:085cde657901 | 223 | |
mbed_official | 87:085cde657901 | 224 | (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC |
mbed_official | 87:085cde657901 | 225 | Wakeup event, a tamper event or a time-stamp event, without depending on |
mbed_official | 87:085cde657901 | 226 | an external interrupt (Auto-wakeup mode). |
mbed_official | 87:085cde657901 | 227 | |
mbed_official | 87:085cde657901 | 228 | (+) RTC auto-wakeup (AWU) from the Stop and Standby modes |
mbed_official | 87:085cde657901 | 229 | |
mbed_official | 87:085cde657901 | 230 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to |
mbed_official | 87:085cde657901 | 231 | configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function. |
mbed_official | 87:085cde657901 | 232 | |
mbed_official | 87:085cde657901 | 233 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it |
mbed_official | 87:085cde657901 | 234 | is necessary to configure the RTC to detect the tamper or time stamp event using the |
mbed_official | 87:085cde657901 | 235 | HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions. |
mbed_official | 87:085cde657901 | 236 | |
mbed_official | 87:085cde657901 | 237 | (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to |
mbed_official | 87:085cde657901 | 238 | configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
mbed_official | 87:085cde657901 | 239 | |
mbed_official | 87:085cde657901 | 240 | @endverbatim |
mbed_official | 87:085cde657901 | 241 | * @{ |
mbed_official | 87:085cde657901 | 242 | */ |
mbed_official | 87:085cde657901 | 243 | |
mbed_official | 87:085cde657901 | 244 | /** |
mbed_official | 87:085cde657901 | 245 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD). |
mbed_official | 87:085cde657901 | 246 | * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration |
mbed_official | 87:085cde657901 | 247 | * information for the PVD. |
mbed_official | 87:085cde657901 | 248 | * @note Refer to the electrical characteristics of your device datasheet for |
mbed_official | 87:085cde657901 | 249 | * more details about the voltage threshold corresponding to each |
mbed_official | 87:085cde657901 | 250 | * detection level. |
mbed_official | 87:085cde657901 | 251 | * @retval None |
mbed_official | 87:085cde657901 | 252 | */ |
mbed_official | 87:085cde657901 | 253 | void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD) |
mbed_official | 87:085cde657901 | 254 | { |
mbed_official | 87:085cde657901 | 255 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 256 | |
mbed_official | 87:085cde657901 | 257 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 258 | assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel)); |
mbed_official | 87:085cde657901 | 259 | assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode)); |
mbed_official | 87:085cde657901 | 260 | |
mbed_official | 87:085cde657901 | 261 | tmpreg = PWR->CR; |
mbed_official | 87:085cde657901 | 262 | |
mbed_official | 87:085cde657901 | 263 | /* Clear PLS[7:5] bits */ |
mbed_official | 87:085cde657901 | 264 | tmpreg &= ~ (uint32_t)PWR_CR_PLS; |
mbed_official | 87:085cde657901 | 265 | |
mbed_official | 87:085cde657901 | 266 | /* Set PLS[7:5] bits according to PVDLevel value */ |
mbed_official | 87:085cde657901 | 267 | tmpreg |= sConfigPVD->PVDLevel; |
mbed_official | 87:085cde657901 | 268 | |
mbed_official | 87:085cde657901 | 269 | /* Store the new value */ |
mbed_official | 87:085cde657901 | 270 | PWR->CR = tmpreg; |
mbed_official | 87:085cde657901 | 271 | |
mbed_official | 87:085cde657901 | 272 | /* Configure the EXTI 16 interrupt */ |
mbed_official | 87:085cde657901 | 273 | if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\ |
mbed_official | 87:085cde657901 | 274 | (sConfigPVD->Mode == PWR_MODE_IT_FALLING) ||\ |
mbed_official | 87:085cde657901 | 275 | (sConfigPVD->Mode == PWR_MODE_IT_RISING)) |
mbed_official | 87:085cde657901 | 276 | { |
mbed_official | 87:085cde657901 | 277 | __HAL_PVD_EXTI_ENABLE_IT(PWR_EXTI_LINE_PVD); |
mbed_official | 87:085cde657901 | 278 | } |
mbed_official | 87:085cde657901 | 279 | /* Configure the rising edge */ |
mbed_official | 87:085cde657901 | 280 | if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\ |
mbed_official | 87:085cde657901 | 281 | (sConfigPVD->Mode == PWR_MODE_IT_RISING)) |
mbed_official | 87:085cde657901 | 282 | { |
mbed_official | 87:085cde657901 | 283 | EXTI->RTSR |= PWR_EXTI_LINE_PVD; |
mbed_official | 87:085cde657901 | 284 | } |
mbed_official | 87:085cde657901 | 285 | /* Configure the falling edge */ |
mbed_official | 87:085cde657901 | 286 | if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\ |
mbed_official | 87:085cde657901 | 287 | (sConfigPVD->Mode == PWR_MODE_IT_FALLING)) |
mbed_official | 87:085cde657901 | 288 | { |
mbed_official | 87:085cde657901 | 289 | EXTI->FTSR |= PWR_EXTI_LINE_PVD; |
mbed_official | 87:085cde657901 | 290 | } |
mbed_official | 87:085cde657901 | 291 | } |
mbed_official | 87:085cde657901 | 292 | |
mbed_official | 87:085cde657901 | 293 | /** |
mbed_official | 87:085cde657901 | 294 | * @brief Enables the Power Voltage Detector(PVD). |
mbed_official | 87:085cde657901 | 295 | * @param None |
mbed_official | 87:085cde657901 | 296 | * @retval None |
mbed_official | 87:085cde657901 | 297 | */ |
mbed_official | 87:085cde657901 | 298 | void HAL_PWR_EnablePVD(void) |
mbed_official | 87:085cde657901 | 299 | { |
mbed_official | 87:085cde657901 | 300 | *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE; |
mbed_official | 87:085cde657901 | 301 | } |
mbed_official | 87:085cde657901 | 302 | |
mbed_official | 87:085cde657901 | 303 | /** |
mbed_official | 87:085cde657901 | 304 | * @brief Disables the Power Voltage Detector(PVD). |
mbed_official | 87:085cde657901 | 305 | * @param None |
mbed_official | 87:085cde657901 | 306 | * @retval None |
mbed_official | 87:085cde657901 | 307 | */ |
mbed_official | 87:085cde657901 | 308 | void HAL_PWR_DisablePVD(void) |
mbed_official | 87:085cde657901 | 309 | { |
mbed_official | 87:085cde657901 | 310 | *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE; |
mbed_official | 87:085cde657901 | 311 | } |
mbed_official | 87:085cde657901 | 312 | |
mbed_official | 87:085cde657901 | 313 | /** |
mbed_official | 87:085cde657901 | 314 | * @brief Enables the WakeUp PINx functionality. |
mbed_official | 87:085cde657901 | 315 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable |
mbed_official | 87:085cde657901 | 316 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 317 | * @arg PWR_WAKEUP_PIN1 |
mbed_official | 87:085cde657901 | 318 | * @retval None |
mbed_official | 87:085cde657901 | 319 | */ |
mbed_official | 87:085cde657901 | 320 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) |
mbed_official | 87:085cde657901 | 321 | { |
mbed_official | 87:085cde657901 | 322 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 323 | assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx)); |
mbed_official | 87:085cde657901 | 324 | *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)ENABLE; |
mbed_official | 87:085cde657901 | 325 | } |
mbed_official | 87:085cde657901 | 326 | |
mbed_official | 87:085cde657901 | 327 | /** |
mbed_official | 87:085cde657901 | 328 | * @brief Disables the WakeUp PINx functionality. |
mbed_official | 87:085cde657901 | 329 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable |
mbed_official | 87:085cde657901 | 330 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 331 | * @arg PWR_WAKEUP_PIN1 |
mbed_official | 87:085cde657901 | 332 | * @retval None |
mbed_official | 87:085cde657901 | 333 | */ |
mbed_official | 87:085cde657901 | 334 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) |
mbed_official | 87:085cde657901 | 335 | { |
mbed_official | 87:085cde657901 | 336 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 337 | assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx)); |
mbed_official | 87:085cde657901 | 338 | *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)DISABLE; |
mbed_official | 87:085cde657901 | 339 | } |
mbed_official | 87:085cde657901 | 340 | |
mbed_official | 87:085cde657901 | 341 | /** |
mbed_official | 87:085cde657901 | 342 | * @brief Enters Sleep mode. |
mbed_official | 87:085cde657901 | 343 | * |
mbed_official | 87:085cde657901 | 344 | * @note In Sleep mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 87:085cde657901 | 345 | * |
mbed_official | 87:085cde657901 | 346 | * @note In Sleep mode, the systick is stopped to avoid exit from this mode with |
mbed_official | 87:085cde657901 | 347 | * systick interrupt when used as time base for Timeout |
mbed_official | 87:085cde657901 | 348 | * |
mbed_official | 87:085cde657901 | 349 | * @param Regulator: Specifies the regulator state in SLEEP mode. |
mbed_official | 87:085cde657901 | 350 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 351 | * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON |
mbed_official | 87:085cde657901 | 352 | * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON |
mbed_official | 87:085cde657901 | 353 | * @note This parameter is not used for the STM32F4 family and is kept as parameter |
mbed_official | 87:085cde657901 | 354 | * just to maintain compatibility with the lower power families. |
mbed_official | 87:085cde657901 | 355 | * @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction. |
mbed_official | 87:085cde657901 | 356 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 357 | * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
mbed_official | 87:085cde657901 | 358 | * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
mbed_official | 87:085cde657901 | 359 | * @retval None |
mbed_official | 87:085cde657901 | 360 | */ |
mbed_official | 87:085cde657901 | 361 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry) |
mbed_official | 87:085cde657901 | 362 | { |
mbed_official | 87:085cde657901 | 363 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 364 | assert_param(IS_PWR_REGULATOR(Regulator)); |
mbed_official | 87:085cde657901 | 365 | assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry)); |
mbed_official | 87:085cde657901 | 366 | |
mbed_official | 87:085cde657901 | 367 | /* Disable SysTick Timer */ |
mbed_official | 87:085cde657901 | 368 | SysTick->CTRL &= 0xFE; |
mbed_official | 87:085cde657901 | 369 | |
mbed_official | 87:085cde657901 | 370 | /* Select SLEEP mode entry -------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 371 | if(SLEEPEntry == PWR_SLEEPENTRY_WFI) |
mbed_official | 87:085cde657901 | 372 | { |
mbed_official | 87:085cde657901 | 373 | /* Request Wait For Interrupt */ |
mbed_official | 87:085cde657901 | 374 | __WFI(); |
mbed_official | 87:085cde657901 | 375 | } |
mbed_official | 87:085cde657901 | 376 | else |
mbed_official | 87:085cde657901 | 377 | { |
mbed_official | 87:085cde657901 | 378 | /* Request Wait For Event */ |
mbed_official | 87:085cde657901 | 379 | __WFE(); |
mbed_official | 87:085cde657901 | 380 | } |
mbed_official | 87:085cde657901 | 381 | |
mbed_official | 87:085cde657901 | 382 | /* Enable SysTick Timer */ |
mbed_official | 87:085cde657901 | 383 | SysTick->CTRL |= 0x01; |
mbed_official | 87:085cde657901 | 384 | } |
mbed_official | 87:085cde657901 | 385 | |
mbed_official | 87:085cde657901 | 386 | /** |
mbed_official | 87:085cde657901 | 387 | * @brief Enters Stop mode. |
mbed_official | 87:085cde657901 | 388 | * @note In Stop mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 87:085cde657901 | 389 | * @note When exiting Stop mode by issuing an interrupt or a wakeup event, |
mbed_official | 87:085cde657901 | 390 | * the HSI RC oscillator is selected as system clock. |
mbed_official | 87:085cde657901 | 391 | * @note When the voltage regulator operates in low power mode, an additional |
mbed_official | 87:085cde657901 | 392 | * startup delay is incurred when waking up from Stop mode. |
mbed_official | 87:085cde657901 | 393 | * By keeping the internal regulator ON during Stop mode, the consumption |
mbed_official | 87:085cde657901 | 394 | * is higher although the startup time is reduced. |
mbed_official | 87:085cde657901 | 395 | * @param Regulator: Specifies the regulator state in Stop mode. |
mbed_official | 87:085cde657901 | 396 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 397 | * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON |
mbed_official | 87:085cde657901 | 398 | * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON |
mbed_official | 87:085cde657901 | 399 | * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction. |
mbed_official | 87:085cde657901 | 400 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 401 | * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction |
mbed_official | 87:085cde657901 | 402 | * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction |
mbed_official | 87:085cde657901 | 403 | * @retval None |
mbed_official | 87:085cde657901 | 404 | */ |
mbed_official | 87:085cde657901 | 405 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) |
mbed_official | 87:085cde657901 | 406 | { |
mbed_official | 87:085cde657901 | 407 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 408 | |
mbed_official | 87:085cde657901 | 409 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 410 | assert_param(IS_PWR_REGULATOR(Regulator)); |
mbed_official | 87:085cde657901 | 411 | assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); |
mbed_official | 87:085cde657901 | 412 | |
mbed_official | 87:085cde657901 | 413 | /* Select the regulator state in Stop mode ---------------------------------*/ |
mbed_official | 87:085cde657901 | 414 | tmpreg = PWR->CR; |
mbed_official | 87:085cde657901 | 415 | /* Clear PDDS and LPDS bits */ |
mbed_official | 87:085cde657901 | 416 | tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS); |
mbed_official | 87:085cde657901 | 417 | |
mbed_official | 87:085cde657901 | 418 | /* Set LPDS, MRLVDS and LPLVDS bits according to Regulator value */ |
mbed_official | 87:085cde657901 | 419 | tmpreg |= Regulator; |
mbed_official | 87:085cde657901 | 420 | |
mbed_official | 87:085cde657901 | 421 | /* Store the new value */ |
mbed_official | 87:085cde657901 | 422 | PWR->CR = tmpreg; |
mbed_official | 87:085cde657901 | 423 | |
mbed_official | 87:085cde657901 | 424 | /* Set SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 87:085cde657901 | 425 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 87:085cde657901 | 426 | |
mbed_official | 87:085cde657901 | 427 | /* Select Stop mode entry --------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 428 | if(STOPEntry == PWR_STOPENTRY_WFI) |
mbed_official | 87:085cde657901 | 429 | { |
mbed_official | 87:085cde657901 | 430 | /* Request Wait For Interrupt */ |
mbed_official | 87:085cde657901 | 431 | __WFI(); |
mbed_official | 87:085cde657901 | 432 | } |
mbed_official | 87:085cde657901 | 433 | else |
mbed_official | 87:085cde657901 | 434 | { |
mbed_official | 87:085cde657901 | 435 | /* Request Wait For Event */ |
mbed_official | 87:085cde657901 | 436 | __WFE(); |
mbed_official | 87:085cde657901 | 437 | } |
mbed_official | 87:085cde657901 | 438 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 87:085cde657901 | 439 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 87:085cde657901 | 440 | } |
mbed_official | 87:085cde657901 | 441 | |
mbed_official | 87:085cde657901 | 442 | /** |
mbed_official | 87:085cde657901 | 443 | * @brief Enters Standby mode. |
mbed_official | 87:085cde657901 | 444 | * @note In Standby mode, all I/O pins are high impedance except for: |
mbed_official | 87:085cde657901 | 445 | * - Reset pad (still available) |
mbed_official | 87:085cde657901 | 446 | * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC |
mbed_official | 87:085cde657901 | 447 | * Alarm out, or RTC clock calibration out. |
mbed_official | 87:085cde657901 | 448 | * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp. |
mbed_official | 87:085cde657901 | 449 | * - WKUP pin 1 (PA0) if enabled. |
mbed_official | 87:085cde657901 | 450 | * @param None |
mbed_official | 87:085cde657901 | 451 | * @retval None |
mbed_official | 87:085cde657901 | 452 | */ |
mbed_official | 87:085cde657901 | 453 | void HAL_PWR_EnterSTANDBYMode(void) |
mbed_official | 87:085cde657901 | 454 | { |
mbed_official | 87:085cde657901 | 455 | /* Clear Wakeup flag */ |
mbed_official | 87:085cde657901 | 456 | PWR->CR |= PWR_CR_CWUF; |
mbed_official | 87:085cde657901 | 457 | |
mbed_official | 87:085cde657901 | 458 | /* Select Standby mode */ |
mbed_official | 87:085cde657901 | 459 | PWR->CR |= PWR_CR_PDDS; |
mbed_official | 87:085cde657901 | 460 | |
mbed_official | 87:085cde657901 | 461 | /* Set SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 87:085cde657901 | 462 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 87:085cde657901 | 463 | |
mbed_official | 87:085cde657901 | 464 | /* This option is used to ensure that store operations are completed */ |
mbed_official | 87:085cde657901 | 465 | #if defined ( __CC_ARM) |
mbed_official | 87:085cde657901 | 466 | __force_stores(); |
mbed_official | 87:085cde657901 | 467 | #endif |
mbed_official | 87:085cde657901 | 468 | /* Request Wait For Interrupt */ |
mbed_official | 87:085cde657901 | 469 | __WFI(); |
mbed_official | 87:085cde657901 | 470 | } |
mbed_official | 87:085cde657901 | 471 | |
mbed_official | 87:085cde657901 | 472 | /** |
mbed_official | 87:085cde657901 | 473 | * @brief This function handles the PWR PVD interrupt request. |
mbed_official | 87:085cde657901 | 474 | * @note This API should be called under the PVD_IRQHandler(). |
mbed_official | 87:085cde657901 | 475 | * @param None |
mbed_official | 87:085cde657901 | 476 | * @retval None |
mbed_official | 87:085cde657901 | 477 | */ |
mbed_official | 87:085cde657901 | 478 | void HAL_PWR_PVD_IRQHandler(void) |
mbed_official | 87:085cde657901 | 479 | { |
mbed_official | 87:085cde657901 | 480 | /* Check PWR exti flag */ |
mbed_official | 87:085cde657901 | 481 | if(__HAL_PVD_EXTI_GET_FLAG(PWR_EXTI_LINE_PVD) != RESET) |
mbed_official | 87:085cde657901 | 482 | { |
mbed_official | 87:085cde657901 | 483 | /* PWR PVD interrupt user callback */ |
mbed_official | 87:085cde657901 | 484 | HAL_PWR_PVDCallback(); |
mbed_official | 87:085cde657901 | 485 | |
mbed_official | 87:085cde657901 | 486 | /* Clear PWR Exti pending bit */ |
mbed_official | 87:085cde657901 | 487 | __HAL_PVD_EXTI_CLEAR_FLAG(PWR_EXTI_LINE_PVD); |
mbed_official | 87:085cde657901 | 488 | } |
mbed_official | 87:085cde657901 | 489 | } |
mbed_official | 87:085cde657901 | 490 | |
mbed_official | 87:085cde657901 | 491 | /** |
mbed_official | 87:085cde657901 | 492 | * @brief PWR PVD interrupt callback |
mbed_official | 87:085cde657901 | 493 | * @param none |
mbed_official | 87:085cde657901 | 494 | * @retval none |
mbed_official | 87:085cde657901 | 495 | */ |
mbed_official | 87:085cde657901 | 496 | __weak void HAL_PWR_PVDCallback(void) |
mbed_official | 87:085cde657901 | 497 | { |
mbed_official | 87:085cde657901 | 498 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 499 | the HAL_PWR_PVDCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 500 | */ |
mbed_official | 87:085cde657901 | 501 | } |
mbed_official | 87:085cde657901 | 502 | |
mbed_official | 87:085cde657901 | 503 | /** |
mbed_official | 87:085cde657901 | 504 | * @} |
mbed_official | 87:085cde657901 | 505 | */ |
mbed_official | 87:085cde657901 | 506 | |
mbed_official | 87:085cde657901 | 507 | /** |
mbed_official | 87:085cde657901 | 508 | * @} |
mbed_official | 87:085cde657901 | 509 | */ |
mbed_official | 87:085cde657901 | 510 | |
mbed_official | 87:085cde657901 | 511 | #endif /* HAL_PWR_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 512 | /** |
mbed_official | 87:085cde657901 | 513 | * @} |
mbed_official | 87:085cde657901 | 514 | */ |
mbed_official | 87:085cde657901 | 515 | |
mbed_official | 87:085cde657901 | 516 | /** |
mbed_official | 87:085cde657901 | 517 | * @} |
mbed_official | 87:085cde657901 | 518 | */ |
mbed_official | 87:085cde657901 | 519 | |
mbed_official | 87:085cde657901 | 520 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |