mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_pwr.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 237:f3da66175598
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_pwr.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief PWR HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the Power Controller (PWR) peripheral: |
mbed_official | 237:f3da66175598 | 11 | * + Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 12 | * + Peripheral Control functions |
mbed_official | 237:f3da66175598 | 13 | * |
mbed_official | 237:f3da66175598 | 14 | @verbatim |
mbed_official | 237:f3da66175598 | 15 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 16 | * @attention |
mbed_official | 237:f3da66175598 | 17 | * |
mbed_official | 237:f3da66175598 | 18 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 19 | * |
mbed_official | 237:f3da66175598 | 20 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 21 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 22 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 23 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 24 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 25 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 26 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 27 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 28 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 29 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 30 | * |
mbed_official | 237:f3da66175598 | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 34 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 39 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 41 | * |
mbed_official | 237:f3da66175598 | 42 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 43 | */ |
mbed_official | 237:f3da66175598 | 44 | |
mbed_official | 237:f3da66175598 | 45 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 46 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 47 | |
mbed_official | 237:f3da66175598 | 48 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 49 | * @{ |
mbed_official | 237:f3da66175598 | 50 | */ |
mbed_official | 237:f3da66175598 | 51 | |
mbed_official | 237:f3da66175598 | 52 | /** @defgroup PWR |
mbed_official | 237:f3da66175598 | 53 | * @brief PWR HAL module driver |
mbed_official | 237:f3da66175598 | 54 | * @{ |
mbed_official | 237:f3da66175598 | 55 | */ |
mbed_official | 237:f3da66175598 | 56 | |
mbed_official | 237:f3da66175598 | 57 | #ifdef HAL_PWR_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 58 | |
mbed_official | 237:f3da66175598 | 59 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 60 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 61 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 62 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 63 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 64 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 65 | |
mbed_official | 237:f3da66175598 | 66 | /** @defgroup PWR_Private_Functions |
mbed_official | 237:f3da66175598 | 67 | * @{ |
mbed_official | 237:f3da66175598 | 68 | */ |
mbed_official | 237:f3da66175598 | 69 | |
mbed_official | 237:f3da66175598 | 70 | /** @defgroup HAL_PWR_Group1 Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 71 | * @brief Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 72 | * |
mbed_official | 237:f3da66175598 | 73 | @verbatim |
mbed_official | 237:f3da66175598 | 74 | =============================================================================== |
mbed_official | 237:f3da66175598 | 75 | ##### Initialization/de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 76 | =============================================================================== |
mbed_official | 237:f3da66175598 | 77 | [..] |
mbed_official | 237:f3da66175598 | 78 | After reset, the backup domain (RTC registers, RTC backup data |
mbed_official | 237:f3da66175598 | 79 | registers and backup SRAM) is protected against possible unwanted |
mbed_official | 237:f3da66175598 | 80 | write accesses. |
mbed_official | 237:f3da66175598 | 81 | To enable access to the RTC Domain and RTC registers, proceed as follows: |
mbed_official | 237:f3da66175598 | 82 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
mbed_official | 237:f3da66175598 | 83 | __PWR_CLK_ENABLE() macro. |
mbed_official | 237:f3da66175598 | 84 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
mbed_official | 237:f3da66175598 | 85 | |
mbed_official | 237:f3da66175598 | 86 | @endverbatim |
mbed_official | 237:f3da66175598 | 87 | * @{ |
mbed_official | 237:f3da66175598 | 88 | */ |
mbed_official | 237:f3da66175598 | 89 | |
mbed_official | 237:f3da66175598 | 90 | /** |
mbed_official | 237:f3da66175598 | 91 | * @brief Deinitializes the HAL PWR peripheral registers to their default reset values. |
mbed_official | 237:f3da66175598 | 92 | * @param None |
mbed_official | 237:f3da66175598 | 93 | * @retval None |
mbed_official | 237:f3da66175598 | 94 | */ |
mbed_official | 237:f3da66175598 | 95 | void HAL_PWR_DeInit(void) |
mbed_official | 237:f3da66175598 | 96 | { |
mbed_official | 237:f3da66175598 | 97 | __PWR_FORCE_RESET(); |
mbed_official | 237:f3da66175598 | 98 | __PWR_RELEASE_RESET(); |
mbed_official | 237:f3da66175598 | 99 | } |
mbed_official | 237:f3da66175598 | 100 | |
mbed_official | 237:f3da66175598 | 101 | /** |
mbed_official | 237:f3da66175598 | 102 | * @brief Enables access to the backup domain (RTC registers, RTC |
mbed_official | 237:f3da66175598 | 103 | * backup data registers and backup SRAM). |
mbed_official | 237:f3da66175598 | 104 | * @note If the HSE divided by 32 is used as the RTC clock, the |
mbed_official | 237:f3da66175598 | 105 | * Backup Domain Access should be kept enabled. |
mbed_official | 237:f3da66175598 | 106 | * @param None |
mbed_official | 237:f3da66175598 | 107 | * @retval None |
mbed_official | 237:f3da66175598 | 108 | */ |
mbed_official | 237:f3da66175598 | 109 | void HAL_PWR_EnableBkUpAccess(void) |
mbed_official | 237:f3da66175598 | 110 | { |
mbed_official | 237:f3da66175598 | 111 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE; |
mbed_official | 237:f3da66175598 | 112 | } |
mbed_official | 237:f3da66175598 | 113 | |
mbed_official | 237:f3da66175598 | 114 | /** |
mbed_official | 237:f3da66175598 | 115 | * @brief Disables access to the backup domain (RTC registers, RTC |
mbed_official | 237:f3da66175598 | 116 | * backup data registers and backup SRAM). |
mbed_official | 237:f3da66175598 | 117 | * @note If the HSE divided by 32 is used as the RTC clock, the |
mbed_official | 237:f3da66175598 | 118 | * Backup Domain Access should be kept enabled. |
mbed_official | 237:f3da66175598 | 119 | * @param None |
mbed_official | 237:f3da66175598 | 120 | * @retval None |
mbed_official | 237:f3da66175598 | 121 | */ |
mbed_official | 237:f3da66175598 | 122 | void HAL_PWR_DisableBkUpAccess(void) |
mbed_official | 237:f3da66175598 | 123 | { |
mbed_official | 237:f3da66175598 | 124 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE; |
mbed_official | 237:f3da66175598 | 125 | } |
mbed_official | 237:f3da66175598 | 126 | |
mbed_official | 237:f3da66175598 | 127 | /** |
mbed_official | 237:f3da66175598 | 128 | * @} |
mbed_official | 237:f3da66175598 | 129 | */ |
mbed_official | 237:f3da66175598 | 130 | |
mbed_official | 237:f3da66175598 | 131 | /** @defgroup HAL_PWR_Group2 Peripheral Control functions |
mbed_official | 237:f3da66175598 | 132 | * @brief Low Power modes configuration functions |
mbed_official | 237:f3da66175598 | 133 | * |
mbed_official | 237:f3da66175598 | 134 | @verbatim |
mbed_official | 237:f3da66175598 | 135 | |
mbed_official | 237:f3da66175598 | 136 | =============================================================================== |
mbed_official | 237:f3da66175598 | 137 | ##### Peripheral Control functions ##### |
mbed_official | 237:f3da66175598 | 138 | =============================================================================== |
mbed_official | 237:f3da66175598 | 139 | [..] |
mbed_official | 237:f3da66175598 | 140 | *** WakeUp pin configuration *** |
mbed_official | 237:f3da66175598 | 141 | ================================ |
mbed_official | 237:f3da66175598 | 142 | (+) WakeUp pin is used to wakeup the system from Standby mode. This pin is |
mbed_official | 237:f3da66175598 | 143 | forced in input pull down configuration and is active on rising edges. |
mbed_official | 237:f3da66175598 | 144 | (+) There are up to three WakeUp pins: |
mbed_official | 237:f3da66175598 | 145 | WakeUp Pin 1 on PA.00. |
mbed_official | 237:f3da66175598 | 146 | WakeUp Pin 2 on PC.13 (STM32F303xC, only). |
mbed_official | 237:f3da66175598 | 147 | WakeUp Pin 3 on PE.06. |
mbed_official | 237:f3da66175598 | 148 | |
mbed_official | 237:f3da66175598 | 149 | *** Main and Backup Regulators configuration *** |
mbed_official | 237:f3da66175598 | 150 | ================================================ |
mbed_official | 237:f3da66175598 | 151 | [..] |
mbed_official | 237:f3da66175598 | 152 | (+) When the backup domain is supplied by VDD (analog switch connected to VDD) |
mbed_official | 237:f3da66175598 | 153 | the backup SRAM is powered from VDD which replaces the VBAT power supply to |
mbed_official | 237:f3da66175598 | 154 | save battery life. |
mbed_official | 237:f3da66175598 | 155 | |
mbed_official | 237:f3da66175598 | 156 | (+) The backup SRAM is not mass erased by an tamper event. It is read |
mbed_official | 237:f3da66175598 | 157 | protected to prevent confidential data, such as cryptographic private |
mbed_official | 237:f3da66175598 | 158 | key, from being accessed. The backup SRAM can be erased only through |
mbed_official | 237:f3da66175598 | 159 | the Flash interface when a protection level change from level 1 to |
mbed_official | 237:f3da66175598 | 160 | level 0 is requested. |
mbed_official | 237:f3da66175598 | 161 | -@- Refer to the description of Read protection (RDP) in the Flash |
mbed_official | 237:f3da66175598 | 162 | programming manual. |
mbed_official | 237:f3da66175598 | 163 | |
mbed_official | 237:f3da66175598 | 164 | Refer to the datasheets for more details. |
mbed_official | 237:f3da66175598 | 165 | |
mbed_official | 237:f3da66175598 | 166 | *** Low Power modes configuration *** |
mbed_official | 237:f3da66175598 | 167 | ===================================== |
mbed_official | 237:f3da66175598 | 168 | [..] |
mbed_official | 237:f3da66175598 | 169 | The devices feature 3 low-power modes: |
mbed_official | 237:f3da66175598 | 170 | (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running. |
mbed_official | 237:f3da66175598 | 171 | (+) Stop mode: all clocks are stopped, regulator running, regulator |
mbed_official | 237:f3da66175598 | 172 | in low power mode |
mbed_official | 237:f3da66175598 | 173 | (+) Standby mode: 1.2V domain powered off (mode not available on STM32F3x8 devices). |
mbed_official | 237:f3da66175598 | 174 | |
mbed_official | 237:f3da66175598 | 175 | *** Sleep mode *** |
mbed_official | 237:f3da66175598 | 176 | ================== |
mbed_official | 237:f3da66175598 | 177 | [..] |
mbed_official | 237:f3da66175598 | 178 | (+) Entry: |
mbed_official | 237:f3da66175598 | 179 | The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx) |
mbed_official | 237:f3da66175598 | 180 | functions with |
mbed_official | 237:f3da66175598 | 181 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
mbed_official | 237:f3da66175598 | 182 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
mbed_official | 237:f3da66175598 | 183 | |
mbed_official | 237:f3da66175598 | 184 | (+) Exit: |
mbed_official | 237:f3da66175598 | 185 | (++) Any peripheral interrupt acknowledged by the nested vectored interrupt |
mbed_official | 237:f3da66175598 | 186 | controller (NVIC) can wake up the device from Sleep mode. |
mbed_official | 237:f3da66175598 | 187 | |
mbed_official | 237:f3da66175598 | 188 | *** Stop mode *** |
mbed_official | 237:f3da66175598 | 189 | ================= |
mbed_official | 237:f3da66175598 | 190 | [..] |
mbed_official | 237:f3da66175598 | 191 | In Stop mode, all clocks in the 1.8V domain are stopped, the PLL, the HSI, |
mbed_official | 237:f3da66175598 | 192 | and the HSE RC oscillators are disabled. Internal SRAM and register contents |
mbed_official | 237:f3da66175598 | 193 | are preserved. |
mbed_official | 237:f3da66175598 | 194 | The voltage regulator can be configured either in normal or low-power mode. |
mbed_official | 237:f3da66175598 | 195 | To minimize the consumption. |
mbed_official | 237:f3da66175598 | 196 | |
mbed_official | 237:f3da66175598 | 197 | (+) Entry: |
mbed_official | 237:f3da66175598 | 198 | The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI ) |
mbed_official | 237:f3da66175598 | 199 | function with: |
mbed_official | 237:f3da66175598 | 200 | (++) Main regulator ON. |
mbed_official | 237:f3da66175598 | 201 | (++) Low Power regulator ON. |
mbed_official | 237:f3da66175598 | 202 | (++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction |
mbed_official | 237:f3da66175598 | 203 | (++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction |
mbed_official | 237:f3da66175598 | 204 | (+) Exit: |
mbed_official | 237:f3da66175598 | 205 | (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode. |
mbed_official | 237:f3da66175598 | 206 | (++) Some specific communication peripherals (CEC, USART, I2C) interrupts, |
mbed_official | 237:f3da66175598 | 207 | when programmed in wakeup mode (the peripheral must be |
mbed_official | 237:f3da66175598 | 208 | programmed in wakeup mode and the corresponding interrupt vector |
mbed_official | 237:f3da66175598 | 209 | must be enabled in the NVIC) |
mbed_official | 237:f3da66175598 | 210 | |
mbed_official | 237:f3da66175598 | 211 | *** Standby mode *** |
mbed_official | 237:f3da66175598 | 212 | ==================== |
mbed_official | 237:f3da66175598 | 213 | [..] |
mbed_official | 237:f3da66175598 | 214 | The Standby mode allows to achieve the lowest power consumption. It is based |
mbed_official | 237:f3da66175598 | 215 | on the Cortex-M4 deep sleep mode, with the voltage regulator disabled. |
mbed_official | 237:f3da66175598 | 216 | The 1.8V domain is consequently powered off. The PLL, the HSI oscillator and |
mbed_official | 237:f3da66175598 | 217 | the HSE oscillator are also switched off. SRAM and register contents are lost |
mbed_official | 237:f3da66175598 | 218 | except for the RTC registers, RTC backup registers, backup SRAM and Standby |
mbed_official | 237:f3da66175598 | 219 | circuitry. |
mbed_official | 237:f3da66175598 | 220 | The voltage regulator is OFF. |
mbed_official | 237:f3da66175598 | 221 | |
mbed_official | 237:f3da66175598 | 222 | (+) Entry: |
mbed_official | 237:f3da66175598 | 223 | (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function. |
mbed_official | 237:f3da66175598 | 224 | (+) Exit: |
mbed_official | 237:f3da66175598 | 225 | (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, |
mbed_official | 237:f3da66175598 | 226 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset. |
mbed_official | 237:f3da66175598 | 227 | |
mbed_official | 237:f3da66175598 | 228 | *** Auto-wakeup (AWU) from low-power mode *** |
mbed_official | 237:f3da66175598 | 229 | ============================================= |
mbed_official | 237:f3da66175598 | 230 | [..] |
mbed_official | 237:f3da66175598 | 231 | The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC |
mbed_official | 237:f3da66175598 | 232 | Wakeup event, a tamper event, a time-stamp event, or a comparator event, |
mbed_official | 237:f3da66175598 | 233 | without depending on an external interrupt (Auto-wakeup mode). |
mbed_official | 237:f3da66175598 | 234 | |
mbed_official | 237:f3da66175598 | 235 | (+) RTC auto-wakeup (AWU) from the Stop and Standby modes |
mbed_official | 237:f3da66175598 | 236 | |
mbed_official | 237:f3da66175598 | 237 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to |
mbed_official | 237:f3da66175598 | 238 | configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function. |
mbed_official | 237:f3da66175598 | 239 | |
mbed_official | 237:f3da66175598 | 240 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it |
mbed_official | 237:f3da66175598 | 241 | is necessary to configure the RTC to detect the tamper or time stamp event using the |
mbed_official | 237:f3da66175598 | 242 | HAL_RTC_SetTimeStamp_IT() or HAL_RTC_SetTamper_IT() functions. |
mbed_official | 237:f3da66175598 | 243 | |
mbed_official | 237:f3da66175598 | 244 | (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to |
mbed_official | 237:f3da66175598 | 245 | configure the RTC to generate the RTC WakeUp event using the HAL_RTC_SetWakeUpTimer_IT() function. |
mbed_official | 237:f3da66175598 | 246 | |
mbed_official | 237:f3da66175598 | 247 | (+) Comparator auto-wakeup (AWU) from the Stop mode |
mbed_official | 237:f3da66175598 | 248 | |
mbed_official | 237:f3da66175598 | 249 | (++) To wake up from the Stop mode with a comparator wakeup event, it is necessary to: |
mbed_official | 237:f3da66175598 | 250 | (+++) Configure the EXTI Line associated with the comparator (example EXTI Line 22 for comparator 2) |
mbed_official | 237:f3da66175598 | 251 | to be sensitive to to the selected edges (falling, rising or falling |
mbed_official | 237:f3da66175598 | 252 | and rising) (Interrupt or Event modes) using the EXTI_Init() function. |
mbed_official | 237:f3da66175598 | 253 | (+++) Configure the comparator to generate the event. |
mbed_official | 237:f3da66175598 | 254 | @endverbatim |
mbed_official | 237:f3da66175598 | 255 | * @{ |
mbed_official | 237:f3da66175598 | 256 | */ |
mbed_official | 237:f3da66175598 | 257 | |
mbed_official | 237:f3da66175598 | 258 | /** |
mbed_official | 237:f3da66175598 | 259 | * @brief Enables the WakeUp PINx functionality. |
mbed_official | 237:f3da66175598 | 260 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable. |
mbed_official | 237:f3da66175598 | 261 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 262 | * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3 |
mbed_official | 237:f3da66175598 | 263 | * @retval None |
mbed_official | 237:f3da66175598 | 264 | */ |
mbed_official | 237:f3da66175598 | 265 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) |
mbed_official | 237:f3da66175598 | 266 | { |
mbed_official | 237:f3da66175598 | 267 | __IO uint32_t tmp = 0; |
mbed_official | 237:f3da66175598 | 268 | |
mbed_official | 237:f3da66175598 | 269 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 270 | assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx)); |
mbed_official | 237:f3da66175598 | 271 | tmp = CSR_EWUP1_BB + (WakeUpPinx << 2); |
mbed_official | 237:f3da66175598 | 272 | *(__IO uint32_t *) (tmp) = (uint32_t)ENABLE; |
mbed_official | 237:f3da66175598 | 273 | } |
mbed_official | 237:f3da66175598 | 274 | |
mbed_official | 237:f3da66175598 | 275 | /** |
mbed_official | 237:f3da66175598 | 276 | * @brief Disables the WakeUp PINx functionality. |
mbed_official | 237:f3da66175598 | 277 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable. |
mbed_official | 237:f3da66175598 | 278 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 279 | * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3 |
mbed_official | 237:f3da66175598 | 280 | * @retval None |
mbed_official | 237:f3da66175598 | 281 | */ |
mbed_official | 237:f3da66175598 | 282 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) |
mbed_official | 237:f3da66175598 | 283 | { |
mbed_official | 237:f3da66175598 | 284 | __IO uint32_t tmp = 0; |
mbed_official | 237:f3da66175598 | 285 | |
mbed_official | 237:f3da66175598 | 286 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 287 | assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx)); |
mbed_official | 237:f3da66175598 | 288 | tmp = CSR_EWUP1_BB + (WakeUpPinx << 2); |
mbed_official | 237:f3da66175598 | 289 | *(__IO uint32_t *) (tmp) = (uint32_t)DISABLE; |
mbed_official | 237:f3da66175598 | 290 | } |
mbed_official | 237:f3da66175598 | 291 | |
mbed_official | 237:f3da66175598 | 292 | /** |
mbed_official | 237:f3da66175598 | 293 | * @brief Enters Sleep mode. |
mbed_official | 237:f3da66175598 | 294 | * @note In Sleep mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 237:f3da66175598 | 295 | * @param Regulator: Specifies the regulator state in SLEEP mode. |
mbed_official | 237:f3da66175598 | 296 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 297 | * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON |
mbed_official | 237:f3da66175598 | 298 | * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON |
mbed_official | 237:f3da66175598 | 299 | * @param SLEEPEntry: Specifies if SLEEP mode is entered with WFI or WFE instruction. |
mbed_official | 237:f3da66175598 | 300 | * When WFI entry is used, tick interrupt have to be disabled if not desired as |
mbed_official | 237:f3da66175598 | 301 | * the interrupt wake up source. |
mbed_official | 237:f3da66175598 | 302 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 303 | * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
mbed_official | 237:f3da66175598 | 304 | * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
mbed_official | 237:f3da66175598 | 305 | * @retval None |
mbed_official | 237:f3da66175598 | 306 | */ |
mbed_official | 237:f3da66175598 | 307 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry) |
mbed_official | 237:f3da66175598 | 308 | { |
mbed_official | 237:f3da66175598 | 309 | uint32_t tmpreg = 0; |
mbed_official | 237:f3da66175598 | 310 | |
mbed_official | 237:f3da66175598 | 311 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 312 | assert_param(IS_PWR_REGULATOR(Regulator)); |
mbed_official | 237:f3da66175598 | 313 | assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry)); |
mbed_official | 237:f3da66175598 | 314 | |
mbed_official | 237:f3da66175598 | 315 | /* Select the regulator state in SLEEP mode ---------------------------------*/ |
mbed_official | 237:f3da66175598 | 316 | tmpreg = PWR->CR; |
mbed_official | 237:f3da66175598 | 317 | |
mbed_official | 237:f3da66175598 | 318 | /* Clear PDDS and LPDS bits */ |
mbed_official | 237:f3da66175598 | 319 | tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS); |
mbed_official | 237:f3da66175598 | 320 | |
mbed_official | 237:f3da66175598 | 321 | /* Set LPDS bit according to Regulator value */ |
mbed_official | 237:f3da66175598 | 322 | tmpreg |= Regulator; |
mbed_official | 237:f3da66175598 | 323 | |
mbed_official | 237:f3da66175598 | 324 | /* Store the new value */ |
mbed_official | 237:f3da66175598 | 325 | PWR->CR = tmpreg; |
mbed_official | 237:f3da66175598 | 326 | |
mbed_official | 237:f3da66175598 | 327 | /* Clear SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 237:f3da66175598 | 328 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 237:f3da66175598 | 329 | |
mbed_official | 237:f3da66175598 | 330 | /* Select SLEEP mode entry -------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 331 | if(SLEEPEntry == PWR_SLEEPENTRY_WFI) |
mbed_official | 237:f3da66175598 | 332 | { |
mbed_official | 237:f3da66175598 | 333 | /* Request Wait For Interrupt */ |
mbed_official | 237:f3da66175598 | 334 | __WFI(); |
mbed_official | 237:f3da66175598 | 335 | } |
mbed_official | 237:f3da66175598 | 336 | else |
mbed_official | 237:f3da66175598 | 337 | { |
mbed_official | 237:f3da66175598 | 338 | /* Request Wait For Event */ |
mbed_official | 237:f3da66175598 | 339 | __SEV(); |
mbed_official | 237:f3da66175598 | 340 | __WFE(); |
mbed_official | 237:f3da66175598 | 341 | __WFE(); |
mbed_official | 237:f3da66175598 | 342 | } |
mbed_official | 237:f3da66175598 | 343 | |
mbed_official | 237:f3da66175598 | 344 | } |
mbed_official | 237:f3da66175598 | 345 | |
mbed_official | 237:f3da66175598 | 346 | /** |
mbed_official | 237:f3da66175598 | 347 | * @brief Enters STOP mode. |
mbed_official | 237:f3da66175598 | 348 | * @note In Stop mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 237:f3da66175598 | 349 | * @note When exiting Stop mode by issuing an interrupt or a wakeup event, |
mbed_official | 237:f3da66175598 | 350 | * the HSI RC oscillator is selected as system clock. |
mbed_official | 237:f3da66175598 | 351 | * @note When the voltage regulator operates in low power mode, an additional |
mbed_official | 237:f3da66175598 | 352 | * startup delay is incurred when waking up from Stop mode. |
mbed_official | 237:f3da66175598 | 353 | * By keeping the internal regulator ON during Stop mode, the consumption |
mbed_official | 237:f3da66175598 | 354 | * is higher although the startup time is reduced. |
mbed_official | 237:f3da66175598 | 355 | * @param Regulator: Specifies the regulator state in STOP mode. |
mbed_official | 237:f3da66175598 | 356 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 357 | * @arg PWR_MAINREGULATOR_ON: STOP mode with regulator ON |
mbed_official | 237:f3da66175598 | 358 | * @arg PWR_LOWPOWERREGULATOR_ON: STOP mode with low power regulator ON |
mbed_official | 237:f3da66175598 | 359 | * @param STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction. |
mbed_official | 237:f3da66175598 | 360 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 361 | * @arg PWR_STOPENTRY_WFI:Enter STOP mode with WFI instruction |
mbed_official | 237:f3da66175598 | 362 | * @arg PWR_STOPENTRY_WFE: Enter STOP mode with WFE instruction |
mbed_official | 237:f3da66175598 | 363 | * @retval None |
mbed_official | 237:f3da66175598 | 364 | */ |
mbed_official | 237:f3da66175598 | 365 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) |
mbed_official | 237:f3da66175598 | 366 | { |
mbed_official | 237:f3da66175598 | 367 | uint32_t tmpreg = 0; |
mbed_official | 237:f3da66175598 | 368 | |
mbed_official | 237:f3da66175598 | 369 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 370 | assert_param(IS_PWR_REGULATOR(Regulator)); |
mbed_official | 237:f3da66175598 | 371 | assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); |
mbed_official | 237:f3da66175598 | 372 | |
mbed_official | 237:f3da66175598 | 373 | /* Select the regulator state in STOP mode ---------------------------------*/ |
mbed_official | 237:f3da66175598 | 374 | tmpreg = PWR->CR; |
mbed_official | 237:f3da66175598 | 375 | |
mbed_official | 237:f3da66175598 | 376 | /* Clear PDDS and LPDS bits */ |
mbed_official | 237:f3da66175598 | 377 | tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS); |
mbed_official | 237:f3da66175598 | 378 | |
mbed_official | 237:f3da66175598 | 379 | /* Set LPDS bit according to Regulator value */ |
mbed_official | 237:f3da66175598 | 380 | tmpreg |= Regulator; |
mbed_official | 237:f3da66175598 | 381 | |
mbed_official | 237:f3da66175598 | 382 | /* Store the new value */ |
mbed_official | 237:f3da66175598 | 383 | PWR->CR = tmpreg; |
mbed_official | 237:f3da66175598 | 384 | |
mbed_official | 237:f3da66175598 | 385 | /* Set SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 237:f3da66175598 | 386 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 237:f3da66175598 | 387 | |
mbed_official | 237:f3da66175598 | 388 | /* Select STOP mode entry --------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 389 | if(STOPEntry == PWR_STOPENTRY_WFI) |
mbed_official | 237:f3da66175598 | 390 | { |
mbed_official | 237:f3da66175598 | 391 | /* Request Wait For Interrupt */ |
mbed_official | 237:f3da66175598 | 392 | __WFI(); |
mbed_official | 237:f3da66175598 | 393 | } |
mbed_official | 237:f3da66175598 | 394 | else |
mbed_official | 237:f3da66175598 | 395 | { |
mbed_official | 237:f3da66175598 | 396 | /* Request Wait For Event */ |
mbed_official | 237:f3da66175598 | 397 | __SEV(); |
mbed_official | 237:f3da66175598 | 398 | __WFE(); |
mbed_official | 237:f3da66175598 | 399 | __WFE(); |
mbed_official | 237:f3da66175598 | 400 | } |
mbed_official | 237:f3da66175598 | 401 | |
mbed_official | 237:f3da66175598 | 402 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 237:f3da66175598 | 403 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 237:f3da66175598 | 404 | } |
mbed_official | 237:f3da66175598 | 405 | |
mbed_official | 237:f3da66175598 | 406 | /** |
mbed_official | 237:f3da66175598 | 407 | * @brief Enters STANDBY mode. |
mbed_official | 237:f3da66175598 | 408 | * @note In Standby mode, all I/O pins are high impedance except for: |
mbed_official | 237:f3da66175598 | 409 | * - Reset pad (still available) |
mbed_official | 237:f3da66175598 | 410 | * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC |
mbed_official | 237:f3da66175598 | 411 | * Alarm out, or RTC clock calibration out. |
mbed_official | 237:f3da66175598 | 412 | * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp. |
mbed_official | 237:f3da66175598 | 413 | * - WKUP pin 1 (PA0) if enabled. |
mbed_official | 237:f3da66175598 | 414 | * @param None |
mbed_official | 237:f3da66175598 | 415 | * @retval None |
mbed_official | 237:f3da66175598 | 416 | */ |
mbed_official | 237:f3da66175598 | 417 | void HAL_PWR_EnterSTANDBYMode(void) |
mbed_official | 237:f3da66175598 | 418 | { |
mbed_official | 237:f3da66175598 | 419 | /* Select STANDBY mode */ |
mbed_official | 237:f3da66175598 | 420 | PWR->CR |= PWR_CR_PDDS; |
mbed_official | 237:f3da66175598 | 421 | |
mbed_official | 237:f3da66175598 | 422 | /* Set SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 237:f3da66175598 | 423 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 237:f3da66175598 | 424 | |
mbed_official | 237:f3da66175598 | 425 | /* This option is used to ensure that store operations are completed */ |
mbed_official | 237:f3da66175598 | 426 | #if defined ( __CC_ARM) |
mbed_official | 237:f3da66175598 | 427 | __force_stores(); |
mbed_official | 237:f3da66175598 | 428 | #endif |
mbed_official | 237:f3da66175598 | 429 | /* Request Wait For Interrupt */ |
mbed_official | 237:f3da66175598 | 430 | __WFI(); |
mbed_official | 237:f3da66175598 | 431 | } |
mbed_official | 237:f3da66175598 | 432 | |
mbed_official | 237:f3da66175598 | 433 | /** |
mbed_official | 237:f3da66175598 | 434 | * @} |
mbed_official | 237:f3da66175598 | 435 | */ |
mbed_official | 237:f3da66175598 | 436 | |
mbed_official | 237:f3da66175598 | 437 | /** |
mbed_official | 237:f3da66175598 | 438 | * @} |
mbed_official | 237:f3da66175598 | 439 | */ |
mbed_official | 237:f3da66175598 | 440 | |
mbed_official | 237:f3da66175598 | 441 | #endif /* HAL_PWR_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 442 | /** |
mbed_official | 237:f3da66175598 | 443 | * @} |
mbed_official | 237:f3da66175598 | 444 | */ |
mbed_official | 237:f3da66175598 | 445 | |
mbed_official | 237:f3da66175598 | 446 | /** |
mbed_official | 237:f3da66175598 | 447 | * @} |
mbed_official | 237:f3da66175598 | 448 | */ |
mbed_official | 237:f3da66175598 | 449 | |
mbed_official | 237:f3da66175598 | 450 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |