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