mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F051R8/stm32f0xx_pwr.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 130:1dec54e4aec3
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 130:1dec54e4aec3 | 1 | /** |
mbed_official | 130:1dec54e4aec3 | 2 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 3 | * @file stm32f0xx_pwr.c |
mbed_official | 130:1dec54e4aec3 | 4 | * @author MCD Application Team |
mbed_official | 130:1dec54e4aec3 | 5 | * @version V1.3.0 |
mbed_official | 130:1dec54e4aec3 | 6 | * @date 16-January-2014 |
mbed_official | 130:1dec54e4aec3 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 130:1dec54e4aec3 | 8 | * functionalities of the Power Controller (PWR) peripheral: |
mbed_official | 130:1dec54e4aec3 | 9 | * + Backup Domain Access |
mbed_official | 130:1dec54e4aec3 | 10 | * + PVD configuration |
mbed_official | 130:1dec54e4aec3 | 11 | * + WakeUp pins configuration |
mbed_official | 130:1dec54e4aec3 | 12 | * + Low Power modes configuration |
mbed_official | 130:1dec54e4aec3 | 13 | * + Flags management |
mbed_official | 130:1dec54e4aec3 | 14 | * |
mbed_official | 130:1dec54e4aec3 | 15 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 16 | * @attention |
mbed_official | 130:1dec54e4aec3 | 17 | * |
mbed_official | 130:1dec54e4aec3 | 18 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 130:1dec54e4aec3 | 19 | * |
mbed_official | 130:1dec54e4aec3 | 20 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 130:1dec54e4aec3 | 21 | * are permitted provided that the following conditions are met: |
mbed_official | 130:1dec54e4aec3 | 22 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 130:1dec54e4aec3 | 23 | * this list of conditions and the following disclaimer. |
mbed_official | 130:1dec54e4aec3 | 24 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 130:1dec54e4aec3 | 25 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 130:1dec54e4aec3 | 26 | * and/or other materials provided with the distribution. |
mbed_official | 130:1dec54e4aec3 | 27 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 130:1dec54e4aec3 | 28 | * may be used to endorse or promote products derived from this software |
mbed_official | 130:1dec54e4aec3 | 29 | * without specific prior written permission. |
mbed_official | 130:1dec54e4aec3 | 30 | * |
mbed_official | 130:1dec54e4aec3 | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 130:1dec54e4aec3 | 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 130:1dec54e4aec3 | 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 130:1dec54e4aec3 | 34 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 130:1dec54e4aec3 | 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 130:1dec54e4aec3 | 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 130:1dec54e4aec3 | 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 130:1dec54e4aec3 | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 130:1dec54e4aec3 | 39 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 130:1dec54e4aec3 | 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 130:1dec54e4aec3 | 41 | * |
mbed_official | 130:1dec54e4aec3 | 42 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 43 | */ |
mbed_official | 130:1dec54e4aec3 | 44 | |
mbed_official | 130:1dec54e4aec3 | 45 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 46 | #include "stm32f0xx_pwr.h" |
mbed_official | 130:1dec54e4aec3 | 47 | #include "stm32f0xx_rcc.h" |
mbed_official | 130:1dec54e4aec3 | 48 | |
mbed_official | 130:1dec54e4aec3 | 49 | /** @addtogroup STM32F0xx_StdPeriph_Driver |
mbed_official | 130:1dec54e4aec3 | 50 | * @{ |
mbed_official | 130:1dec54e4aec3 | 51 | */ |
mbed_official | 130:1dec54e4aec3 | 52 | |
mbed_official | 130:1dec54e4aec3 | 53 | /** @defgroup PWR |
mbed_official | 130:1dec54e4aec3 | 54 | * @brief PWR driver modules |
mbed_official | 130:1dec54e4aec3 | 55 | * @{ |
mbed_official | 130:1dec54e4aec3 | 56 | */ |
mbed_official | 130:1dec54e4aec3 | 57 | |
mbed_official | 130:1dec54e4aec3 | 58 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 59 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 60 | |
mbed_official | 130:1dec54e4aec3 | 61 | /* ------------------ PWR registers bit mask ------------------------ */ |
mbed_official | 130:1dec54e4aec3 | 62 | |
mbed_official | 130:1dec54e4aec3 | 63 | /* CR register bit mask */ |
mbed_official | 130:1dec54e4aec3 | 64 | #define CR_DS_MASK ((uint32_t)0xFFFFFFFC) |
mbed_official | 130:1dec54e4aec3 | 65 | #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F) |
mbed_official | 130:1dec54e4aec3 | 66 | |
mbed_official | 130:1dec54e4aec3 | 67 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 68 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 69 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 70 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 71 | |
mbed_official | 130:1dec54e4aec3 | 72 | /** @defgroup PWR_Private_Functions |
mbed_official | 130:1dec54e4aec3 | 73 | * @{ |
mbed_official | 130:1dec54e4aec3 | 74 | */ |
mbed_official | 130:1dec54e4aec3 | 75 | |
mbed_official | 130:1dec54e4aec3 | 76 | /** @defgroup PWR_Group1 Backup Domain Access function |
mbed_official | 130:1dec54e4aec3 | 77 | * @brief Backup Domain Access function |
mbed_official | 130:1dec54e4aec3 | 78 | * |
mbed_official | 130:1dec54e4aec3 | 79 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 80 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 81 | ##### Backup Domain Access function ##### |
mbed_official | 130:1dec54e4aec3 | 82 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 83 | |
mbed_official | 130:1dec54e4aec3 | 84 | [..] After reset, the Backup Domain Registers (RCC BDCR Register, RTC registers |
mbed_official | 130:1dec54e4aec3 | 85 | and RTC backup registers) are protected against possible stray write accesses. |
mbed_official | 130:1dec54e4aec3 | 86 | [..] To enable access to Backup domain use the PWR_BackupAccessCmd(ENABLE) function. |
mbed_official | 130:1dec54e4aec3 | 87 | |
mbed_official | 130:1dec54e4aec3 | 88 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 89 | * @{ |
mbed_official | 130:1dec54e4aec3 | 90 | */ |
mbed_official | 130:1dec54e4aec3 | 91 | |
mbed_official | 130:1dec54e4aec3 | 92 | /** |
mbed_official | 130:1dec54e4aec3 | 93 | * @brief Deinitializes the PWR peripheral registers to their default reset values. |
mbed_official | 130:1dec54e4aec3 | 94 | * @param None |
mbed_official | 130:1dec54e4aec3 | 95 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 96 | */ |
mbed_official | 130:1dec54e4aec3 | 97 | void PWR_DeInit(void) |
mbed_official | 130:1dec54e4aec3 | 98 | { |
mbed_official | 130:1dec54e4aec3 | 99 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE); |
mbed_official | 130:1dec54e4aec3 | 100 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE); |
mbed_official | 130:1dec54e4aec3 | 101 | } |
mbed_official | 130:1dec54e4aec3 | 102 | |
mbed_official | 130:1dec54e4aec3 | 103 | /** |
mbed_official | 130:1dec54e4aec3 | 104 | * @brief Enables or disables access to the Backup domain registers. |
mbed_official | 130:1dec54e4aec3 | 105 | * @note If the HSE divided by 32 is used as the RTC clock, the |
mbed_official | 130:1dec54e4aec3 | 106 | * Backup Domain Access should be kept enabled. |
mbed_official | 130:1dec54e4aec3 | 107 | * @param NewState: new state of the access to the Backup domain registers. |
mbed_official | 130:1dec54e4aec3 | 108 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 130:1dec54e4aec3 | 109 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 110 | */ |
mbed_official | 130:1dec54e4aec3 | 111 | void PWR_BackupAccessCmd(FunctionalState NewState) |
mbed_official | 130:1dec54e4aec3 | 112 | { |
mbed_official | 130:1dec54e4aec3 | 113 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 114 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 130:1dec54e4aec3 | 115 | |
mbed_official | 130:1dec54e4aec3 | 116 | if (NewState != DISABLE) |
mbed_official | 130:1dec54e4aec3 | 117 | { |
mbed_official | 130:1dec54e4aec3 | 118 | /* Enable the Backup Domain Access */ |
mbed_official | 130:1dec54e4aec3 | 119 | PWR->CR |= PWR_CR_DBP; |
mbed_official | 130:1dec54e4aec3 | 120 | } |
mbed_official | 130:1dec54e4aec3 | 121 | else |
mbed_official | 130:1dec54e4aec3 | 122 | { |
mbed_official | 130:1dec54e4aec3 | 123 | /* Disable the Backup Domain Access */ |
mbed_official | 130:1dec54e4aec3 | 124 | PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_DBP); |
mbed_official | 130:1dec54e4aec3 | 125 | } |
mbed_official | 130:1dec54e4aec3 | 126 | } |
mbed_official | 130:1dec54e4aec3 | 127 | |
mbed_official | 130:1dec54e4aec3 | 128 | /** |
mbed_official | 130:1dec54e4aec3 | 129 | * @} |
mbed_official | 130:1dec54e4aec3 | 130 | */ |
mbed_official | 130:1dec54e4aec3 | 131 | |
mbed_official | 130:1dec54e4aec3 | 132 | /** @defgroup PWR_Group2 PVD configuration functions |
mbed_official | 130:1dec54e4aec3 | 133 | * @brief PVD configuration functions |
mbed_official | 130:1dec54e4aec3 | 134 | * |
mbed_official | 130:1dec54e4aec3 | 135 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 136 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 137 | ##### PVD configuration functions ##### |
mbed_official | 130:1dec54e4aec3 | 138 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 139 | [..] |
mbed_official | 130:1dec54e4aec3 | 140 | (+) The PVD is used to monitor the VDD power supply by comparing it to a threshold |
mbed_official | 130:1dec54e4aec3 | 141 | selected by the PVD Level (PLS[2:0] bits in the PWR_CR). |
mbed_official | 130:1dec54e4aec3 | 142 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower than the |
mbed_official | 130:1dec54e4aec3 | 143 | PVD threshold. This event is internally connected to the EXTI line16 |
mbed_official | 130:1dec54e4aec3 | 144 | and can generate an interrupt if enabled through the EXTI registers. |
mbed_official | 130:1dec54e4aec3 | 145 | (+) The PVD is stopped in Standby mode. |
mbed_official | 130:1dec54e4aec3 | 146 | |
mbed_official | 130:1dec54e4aec3 | 147 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 148 | * @{ |
mbed_official | 130:1dec54e4aec3 | 149 | */ |
mbed_official | 130:1dec54e4aec3 | 150 | |
mbed_official | 130:1dec54e4aec3 | 151 | /** |
mbed_official | 130:1dec54e4aec3 | 152 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD). |
mbed_official | 130:1dec54e4aec3 | 153 | * @note This function is not applicable for STM32F030 devices. |
mbed_official | 130:1dec54e4aec3 | 154 | * @param PWR_PVDLevel: specifies the PVD detection level |
mbed_official | 130:1dec54e4aec3 | 155 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 156 | * @arg PWR_PVDLevel_0 |
mbed_official | 130:1dec54e4aec3 | 157 | * @arg PWR_PVDLevel_1 |
mbed_official | 130:1dec54e4aec3 | 158 | * @arg PWR_PVDLevel_2 |
mbed_official | 130:1dec54e4aec3 | 159 | * @arg PWR_PVDLevel_3 |
mbed_official | 130:1dec54e4aec3 | 160 | * @arg PWR_PVDLevel_4 |
mbed_official | 130:1dec54e4aec3 | 161 | * @arg PWR_PVDLevel_5 |
mbed_official | 130:1dec54e4aec3 | 162 | * @arg PWR_PVDLevel_6 |
mbed_official | 130:1dec54e4aec3 | 163 | * @arg PWR_PVDLevel_7 |
mbed_official | 130:1dec54e4aec3 | 164 | * @note Refer to the electrical characteristics of your device datasheet for |
mbed_official | 130:1dec54e4aec3 | 165 | * more details about the voltage threshold corresponding to each |
mbed_official | 130:1dec54e4aec3 | 166 | * detection level. |
mbed_official | 130:1dec54e4aec3 | 167 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 168 | */ |
mbed_official | 130:1dec54e4aec3 | 169 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel) |
mbed_official | 130:1dec54e4aec3 | 170 | { |
mbed_official | 130:1dec54e4aec3 | 171 | uint32_t tmpreg = 0; |
mbed_official | 130:1dec54e4aec3 | 172 | |
mbed_official | 130:1dec54e4aec3 | 173 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 174 | assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel)); |
mbed_official | 130:1dec54e4aec3 | 175 | |
mbed_official | 130:1dec54e4aec3 | 176 | tmpreg = PWR->CR; |
mbed_official | 130:1dec54e4aec3 | 177 | |
mbed_official | 130:1dec54e4aec3 | 178 | /* Clear PLS[7:5] bits */ |
mbed_official | 130:1dec54e4aec3 | 179 | tmpreg &= CR_PLS_MASK; |
mbed_official | 130:1dec54e4aec3 | 180 | |
mbed_official | 130:1dec54e4aec3 | 181 | /* Set PLS[7:5] bits according to PWR_PVDLevel value */ |
mbed_official | 130:1dec54e4aec3 | 182 | tmpreg |= PWR_PVDLevel; |
mbed_official | 130:1dec54e4aec3 | 183 | |
mbed_official | 130:1dec54e4aec3 | 184 | /* Store the new value */ |
mbed_official | 130:1dec54e4aec3 | 185 | PWR->CR = tmpreg; |
mbed_official | 130:1dec54e4aec3 | 186 | } |
mbed_official | 130:1dec54e4aec3 | 187 | |
mbed_official | 130:1dec54e4aec3 | 188 | /** |
mbed_official | 130:1dec54e4aec3 | 189 | * @brief Enables or disables the Power Voltage Detector(PVD). |
mbed_official | 130:1dec54e4aec3 | 190 | * @note This function is not applicable for STM32F030 devices. |
mbed_official | 130:1dec54e4aec3 | 191 | * @param NewState: new state of the PVD. |
mbed_official | 130:1dec54e4aec3 | 192 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 130:1dec54e4aec3 | 193 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 194 | */ |
mbed_official | 130:1dec54e4aec3 | 195 | void PWR_PVDCmd(FunctionalState NewState) |
mbed_official | 130:1dec54e4aec3 | 196 | { |
mbed_official | 130:1dec54e4aec3 | 197 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 198 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 130:1dec54e4aec3 | 199 | |
mbed_official | 130:1dec54e4aec3 | 200 | if (NewState != DISABLE) |
mbed_official | 130:1dec54e4aec3 | 201 | { |
mbed_official | 130:1dec54e4aec3 | 202 | /* Enable the PVD */ |
mbed_official | 130:1dec54e4aec3 | 203 | PWR->CR |= PWR_CR_PVDE; |
mbed_official | 130:1dec54e4aec3 | 204 | } |
mbed_official | 130:1dec54e4aec3 | 205 | else |
mbed_official | 130:1dec54e4aec3 | 206 | { |
mbed_official | 130:1dec54e4aec3 | 207 | /* Disable the PVD */ |
mbed_official | 130:1dec54e4aec3 | 208 | PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_PVDE); |
mbed_official | 130:1dec54e4aec3 | 209 | } |
mbed_official | 130:1dec54e4aec3 | 210 | } |
mbed_official | 130:1dec54e4aec3 | 211 | |
mbed_official | 130:1dec54e4aec3 | 212 | /** |
mbed_official | 130:1dec54e4aec3 | 213 | * @} |
mbed_official | 130:1dec54e4aec3 | 214 | */ |
mbed_official | 130:1dec54e4aec3 | 215 | |
mbed_official | 130:1dec54e4aec3 | 216 | /** @defgroup PWR_Group3 WakeUp pins configuration functions |
mbed_official | 130:1dec54e4aec3 | 217 | * @brief WakeUp pins configuration functions |
mbed_official | 130:1dec54e4aec3 | 218 | * |
mbed_official | 130:1dec54e4aec3 | 219 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 220 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 221 | ##### WakeUp pin configuration functions ##### |
mbed_official | 130:1dec54e4aec3 | 222 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 223 | |
mbed_official | 130:1dec54e4aec3 | 224 | (+) WakeUp pins are used to wakeup the system from Standby mode. These pins are |
mbed_official | 130:1dec54e4aec3 | 225 | forced in input pull down configuration and are active on rising edges. |
mbed_official | 130:1dec54e4aec3 | 226 | (+) There are eight WakeUp pins: WakeUp Pin 1 on PA.00 and WakeUp Pin 2 on PC.13. |
mbed_official | 130:1dec54e4aec3 | 227 | The following WakeUp pins are only applicable for STM32F072 dvices: |
mbed_official | 130:1dec54e4aec3 | 228 | WakeUp Pin 3 on PE.06, WakeUp Pin 4 on PA.02, WakeUp Pin 5 on PC.05, |
mbed_official | 130:1dec54e4aec3 | 229 | WakeUp Pin 6 on PB.05, WakeUp Pin 7 on PB.15 and WakeUp Pin 8 on PF.02. |
mbed_official | 130:1dec54e4aec3 | 230 | |
mbed_official | 130:1dec54e4aec3 | 231 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 232 | * @{ |
mbed_official | 130:1dec54e4aec3 | 233 | */ |
mbed_official | 130:1dec54e4aec3 | 234 | |
mbed_official | 130:1dec54e4aec3 | 235 | /** |
mbed_official | 130:1dec54e4aec3 | 236 | * @brief Enables or disables the WakeUp Pin functionality. |
mbed_official | 130:1dec54e4aec3 | 237 | * @param PWR_WakeUpPin: specifies the WakeUpPin. |
mbed_official | 130:1dec54e4aec3 | 238 | * This parameter can be one of the following values |
mbed_official | 130:1dec54e4aec3 | 239 | * @arg PWR_WakeUpPin_1 |
mbed_official | 130:1dec54e4aec3 | 240 | * @arg PWR_WakeUpPin_2 |
mbed_official | 130:1dec54e4aec3 | 241 | * @arg PWR_WakeUpPin_3, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 242 | * @arg PWR_WakeUpPin_4, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 243 | * @arg PWR_WakeUpPin_5, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 244 | * @arg PWR_WakeUpPin_6, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 245 | * @arg PWR_WakeUpPin_7, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 246 | * @arg PWR_WakeUpPin_8, only applicable for STM32F072 devices |
mbed_official | 130:1dec54e4aec3 | 247 | * @param NewState: new state of the WakeUp Pin functionality. |
mbed_official | 130:1dec54e4aec3 | 248 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 130:1dec54e4aec3 | 249 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 250 | */ |
mbed_official | 130:1dec54e4aec3 | 251 | void PWR_WakeUpPinCmd(uint32_t PWR_WakeUpPin, FunctionalState NewState) |
mbed_official | 130:1dec54e4aec3 | 252 | { |
mbed_official | 130:1dec54e4aec3 | 253 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 254 | assert_param(IS_PWR_WAKEUP_PIN(PWR_WakeUpPin)); |
mbed_official | 130:1dec54e4aec3 | 255 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 130:1dec54e4aec3 | 256 | |
mbed_official | 130:1dec54e4aec3 | 257 | if (NewState != DISABLE) |
mbed_official | 130:1dec54e4aec3 | 258 | { |
mbed_official | 130:1dec54e4aec3 | 259 | /* Enable the EWUPx pin */ |
mbed_official | 130:1dec54e4aec3 | 260 | PWR->CSR |= PWR_WakeUpPin; |
mbed_official | 130:1dec54e4aec3 | 261 | } |
mbed_official | 130:1dec54e4aec3 | 262 | else |
mbed_official | 130:1dec54e4aec3 | 263 | { |
mbed_official | 130:1dec54e4aec3 | 264 | /* Disable the EWUPx pin */ |
mbed_official | 130:1dec54e4aec3 | 265 | PWR->CSR &= ~PWR_WakeUpPin; |
mbed_official | 130:1dec54e4aec3 | 266 | } |
mbed_official | 130:1dec54e4aec3 | 267 | } |
mbed_official | 130:1dec54e4aec3 | 268 | |
mbed_official | 130:1dec54e4aec3 | 269 | /** |
mbed_official | 130:1dec54e4aec3 | 270 | * @} |
mbed_official | 130:1dec54e4aec3 | 271 | */ |
mbed_official | 130:1dec54e4aec3 | 272 | |
mbed_official | 130:1dec54e4aec3 | 273 | |
mbed_official | 130:1dec54e4aec3 | 274 | /** @defgroup PWR_Group4 Low Power modes configuration functions |
mbed_official | 130:1dec54e4aec3 | 275 | * @brief Low Power modes configuration functions |
mbed_official | 130:1dec54e4aec3 | 276 | * |
mbed_official | 130:1dec54e4aec3 | 277 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 278 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 279 | ##### Low Power modes configuration functions ##### |
mbed_official | 130:1dec54e4aec3 | 280 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 281 | |
mbed_official | 130:1dec54e4aec3 | 282 | [..] The devices feature three low-power modes: |
mbed_official | 130:1dec54e4aec3 | 283 | (+) Sleep mode: Cortex-M0 core stopped, peripherals kept running. |
mbed_official | 130:1dec54e4aec3 | 284 | (+) Stop mode: all clocks are stopped, regulator running, regulator in low power mode |
mbed_official | 130:1dec54e4aec3 | 285 | (+) Standby mode: VCORE domain powered off |
mbed_official | 130:1dec54e4aec3 | 286 | |
mbed_official | 130:1dec54e4aec3 | 287 | *** Sleep mode *** |
mbed_official | 130:1dec54e4aec3 | 288 | ================== |
mbed_official | 130:1dec54e4aec3 | 289 | [..] |
mbed_official | 130:1dec54e4aec3 | 290 | (+) Entry: |
mbed_official | 130:1dec54e4aec3 | 291 | (++) The Sleep mode is entered by executing the WFE() or WFI() instructions. |
mbed_official | 130:1dec54e4aec3 | 292 | (+) Exit: |
mbed_official | 130:1dec54e4aec3 | 293 | (++) Any peripheral interrupt acknowledged by the nested vectored interrupt |
mbed_official | 130:1dec54e4aec3 | 294 | controller (NVIC) can wake up the device from Sleep mode. |
mbed_official | 130:1dec54e4aec3 | 295 | |
mbed_official | 130:1dec54e4aec3 | 296 | *** Stop mode *** |
mbed_official | 130:1dec54e4aec3 | 297 | ================= |
mbed_official | 130:1dec54e4aec3 | 298 | [..] In Stop mode, all clocks in the VCORE domain are stopped, the PLL, the HSI, |
mbed_official | 130:1dec54e4aec3 | 299 | the HSI14 and the HSE RC oscillators are disabled. Internal SRAM and register |
mbed_official | 130:1dec54e4aec3 | 300 | contents are preserved. |
mbed_official | 130:1dec54e4aec3 | 301 | The voltage regulator can be configured either in normal or low-power mode. |
mbed_official | 130:1dec54e4aec3 | 302 | |
mbed_official | 130:1dec54e4aec3 | 303 | (+) Entry: |
mbed_official | 130:1dec54e4aec3 | 304 | (++) The Stop mode is entered using the PWR_EnterSTOPMode(PWR_Regulator_LowPower,) |
mbed_official | 130:1dec54e4aec3 | 305 | function with regulator in LowPower or with Regulator ON. |
mbed_official | 130:1dec54e4aec3 | 306 | (+) Exit: |
mbed_official | 130:1dec54e4aec3 | 307 | (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode |
mbed_official | 130:1dec54e4aec3 | 308 | or any internal IPs (I2C, UASRT or CEC) wakeup event. |
mbed_official | 130:1dec54e4aec3 | 309 | |
mbed_official | 130:1dec54e4aec3 | 310 | *** Standby mode *** |
mbed_official | 130:1dec54e4aec3 | 311 | ==================== |
mbed_official | 130:1dec54e4aec3 | 312 | [..] The Standby mode allows to achieve the lowest power consumption. It is based |
mbed_official | 130:1dec54e4aec3 | 313 | on the Cortex-M0 deepsleep mode, with the voltage regulator disabled. |
mbed_official | 130:1dec54e4aec3 | 314 | The VCORE domain is consequently powered off. The PLL, the HSI, the HSI14 |
mbed_official | 130:1dec54e4aec3 | 315 | oscillator and the HSE oscillator are also switched off. SRAM and register |
mbed_official | 130:1dec54e4aec3 | 316 | contents are lost except for the Backup domain (RTC registers, RTC backup |
mbed_official | 130:1dec54e4aec3 | 317 | registers and Standby circuitry). |
mbed_official | 130:1dec54e4aec3 | 318 | |
mbed_official | 130:1dec54e4aec3 | 319 | [..] The voltage regulator is OFF. |
mbed_official | 130:1dec54e4aec3 | 320 | |
mbed_official | 130:1dec54e4aec3 | 321 | (+) Entry: |
mbed_official | 130:1dec54e4aec3 | 322 | (++) The Standby mode is entered using the PWR_EnterSTANDBYMode() function. |
mbed_official | 130:1dec54e4aec3 | 323 | (+) Exit: |
mbed_official | 130:1dec54e4aec3 | 324 | (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, |
mbed_official | 130:1dec54e4aec3 | 325 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset. |
mbed_official | 130:1dec54e4aec3 | 326 | |
mbed_official | 130:1dec54e4aec3 | 327 | *** Auto-wakeup (AWU) from low-power mode *** |
mbed_official | 130:1dec54e4aec3 | 328 | ============================================= |
mbed_official | 130:1dec54e4aec3 | 329 | [..] The MCU can be woken up from low-power mode by an RTC Alarm event, a tamper |
mbed_official | 130:1dec54e4aec3 | 330 | event, a time-stamp event, or a comparator event, without depending on an |
mbed_official | 130:1dec54e4aec3 | 331 | external interrupt (Auto-wakeup mode). |
mbed_official | 130:1dec54e4aec3 | 332 | |
mbed_official | 130:1dec54e4aec3 | 333 | (+) RTC auto-wakeup (AWU) from the Stop mode |
mbed_official | 130:1dec54e4aec3 | 334 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to: |
mbed_official | 130:1dec54e4aec3 | 335 | (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt |
mbed_official | 130:1dec54e4aec3 | 336 | or Event modes) using the EXTI_Init() function. |
mbed_official | 130:1dec54e4aec3 | 337 | (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function |
mbed_official | 130:1dec54e4aec3 | 338 | (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm() |
mbed_official | 130:1dec54e4aec3 | 339 | and RTC_AlarmCmd() functions. |
mbed_official | 130:1dec54e4aec3 | 340 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it |
mbed_official | 130:1dec54e4aec3 | 341 | is necessary to: |
mbed_official | 130:1dec54e4aec3 | 342 | (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt |
mbed_official | 130:1dec54e4aec3 | 343 | or Event modes) using the EXTI_Init() function. |
mbed_official | 130:1dec54e4aec3 | 344 | (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig() |
mbed_official | 130:1dec54e4aec3 | 345 | function. |
mbed_official | 130:1dec54e4aec3 | 346 | (+++) Configure the RTC to detect the tamper or time stamp event using the |
mbed_official | 130:1dec54e4aec3 | 347 | RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd() |
mbed_official | 130:1dec54e4aec3 | 348 | functions. |
mbed_official | 130:1dec54e4aec3 | 349 | |
mbed_official | 130:1dec54e4aec3 | 350 | (+) RTC auto-wakeup (AWU) from the Standby mode |
mbed_official | 130:1dec54e4aec3 | 351 | (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to: |
mbed_official | 130:1dec54e4aec3 | 352 | (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function. |
mbed_official | 130:1dec54e4aec3 | 353 | (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm() |
mbed_official | 130:1dec54e4aec3 | 354 | and RTC_AlarmCmd() functions. |
mbed_official | 130:1dec54e4aec3 | 355 | (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it |
mbed_official | 130:1dec54e4aec3 | 356 | is necessary to: |
mbed_official | 130:1dec54e4aec3 | 357 | (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig() |
mbed_official | 130:1dec54e4aec3 | 358 | function. |
mbed_official | 130:1dec54e4aec3 | 359 | (+++) Configure the RTC to detect the tamper or time stamp event using the |
mbed_official | 130:1dec54e4aec3 | 360 | RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd() |
mbed_official | 130:1dec54e4aec3 | 361 | functions. |
mbed_official | 130:1dec54e4aec3 | 362 | |
mbed_official | 130:1dec54e4aec3 | 363 | (+) Comparator auto-wakeup (AWU) from the Stop mode |
mbed_official | 130:1dec54e4aec3 | 364 | (++) To wake up from the Stop mode with an comparator 1 or comparator 2 wakeup |
mbed_official | 130:1dec54e4aec3 | 365 | event, it is necessary to: |
mbed_official | 130:1dec54e4aec3 | 366 | (+++) Configure the EXTI Line 21 for comparator 1 or EXTI Line 22 for comparator 2 |
mbed_official | 130:1dec54e4aec3 | 367 | to be sensitive to to the selected edges (falling, rising or falling |
mbed_official | 130:1dec54e4aec3 | 368 | and rising) (Interrupt or Event modes) using the EXTI_Init() function. |
mbed_official | 130:1dec54e4aec3 | 369 | (+++) Configure the comparator to generate the event. |
mbed_official | 130:1dec54e4aec3 | 370 | |
mbed_official | 130:1dec54e4aec3 | 371 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 372 | * @{ |
mbed_official | 130:1dec54e4aec3 | 373 | */ |
mbed_official | 130:1dec54e4aec3 | 374 | |
mbed_official | 130:1dec54e4aec3 | 375 | /** |
mbed_official | 130:1dec54e4aec3 | 376 | * @brief Enters Sleep mode. |
mbed_official | 130:1dec54e4aec3 | 377 | * @note In Sleep mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 130:1dec54e4aec3 | 378 | * @param PWR_SLEEPEntry: specifies if SLEEP mode in entered with WFI or WFE instruction. |
mbed_official | 130:1dec54e4aec3 | 379 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 380 | * @arg PWR_SLEEPEntry_WFI: enter SLEEP mode with WFI instruction |
mbed_official | 130:1dec54e4aec3 | 381 | * @arg PWR_SLEEPEntry_WFE: enter SLEEP mode with WFE instruction |
mbed_official | 130:1dec54e4aec3 | 382 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 383 | */ |
mbed_official | 130:1dec54e4aec3 | 384 | void PWR_EnterSleepMode(uint8_t PWR_SLEEPEntry) |
mbed_official | 130:1dec54e4aec3 | 385 | { |
mbed_official | 130:1dec54e4aec3 | 386 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 387 | assert_param(IS_PWR_SLEEP_ENTRY(PWR_SLEEPEntry)); |
mbed_official | 130:1dec54e4aec3 | 388 | |
mbed_official | 130:1dec54e4aec3 | 389 | /* Clear SLEEPDEEP bit of Cortex-M0 System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 390 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 130:1dec54e4aec3 | 391 | |
mbed_official | 130:1dec54e4aec3 | 392 | /* Select SLEEP mode entry -------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 393 | if(PWR_SLEEPEntry == PWR_SLEEPEntry_WFI) |
mbed_official | 130:1dec54e4aec3 | 394 | { |
mbed_official | 130:1dec54e4aec3 | 395 | /* Request Wait For Interrupt */ |
mbed_official | 130:1dec54e4aec3 | 396 | __WFI(); |
mbed_official | 130:1dec54e4aec3 | 397 | } |
mbed_official | 130:1dec54e4aec3 | 398 | else |
mbed_official | 130:1dec54e4aec3 | 399 | { |
mbed_official | 130:1dec54e4aec3 | 400 | /* Request Wait For Event */ |
mbed_official | 130:1dec54e4aec3 | 401 | __WFE(); |
mbed_official | 130:1dec54e4aec3 | 402 | } |
mbed_official | 130:1dec54e4aec3 | 403 | } |
mbed_official | 130:1dec54e4aec3 | 404 | |
mbed_official | 130:1dec54e4aec3 | 405 | /** |
mbed_official | 130:1dec54e4aec3 | 406 | * @brief Enters STOP mode. |
mbed_official | 130:1dec54e4aec3 | 407 | * @note In Stop mode, all I/O pins keep the same state as in Run mode. |
mbed_official | 130:1dec54e4aec3 | 408 | * @note When exiting Stop mode by issuing an interrupt or a wakeup event, |
mbed_official | 130:1dec54e4aec3 | 409 | * the HSI RC oscillator is selected as system clock. |
mbed_official | 130:1dec54e4aec3 | 410 | * @note When the voltage regulator operates in low power mode, an additional |
mbed_official | 130:1dec54e4aec3 | 411 | * startup delay is incurred when waking up from Stop mode. |
mbed_official | 130:1dec54e4aec3 | 412 | * By keeping the internal regulator ON during Stop mode, the consumption |
mbed_official | 130:1dec54e4aec3 | 413 | * is higher although the startup time is reduced. |
mbed_official | 130:1dec54e4aec3 | 414 | * @param PWR_Regulator: specifies the regulator state in STOP mode. |
mbed_official | 130:1dec54e4aec3 | 415 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 416 | * @arg PWR_Regulator_ON: STOP mode with regulator ON |
mbed_official | 130:1dec54e4aec3 | 417 | * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode |
mbed_official | 130:1dec54e4aec3 | 418 | * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction. |
mbed_official | 130:1dec54e4aec3 | 419 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 420 | * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction |
mbed_official | 130:1dec54e4aec3 | 421 | * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction |
mbed_official | 130:1dec54e4aec3 | 422 | @arg PWR_STOPEntry_SLEEPONEXIT: enter STOP mode with SLEEPONEXIT instruction |
mbed_official | 130:1dec54e4aec3 | 423 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 424 | */ |
mbed_official | 130:1dec54e4aec3 | 425 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry) |
mbed_official | 130:1dec54e4aec3 | 426 | { |
mbed_official | 130:1dec54e4aec3 | 427 | uint32_t tmpreg = 0; |
mbed_official | 130:1dec54e4aec3 | 428 | |
mbed_official | 130:1dec54e4aec3 | 429 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 430 | assert_param(IS_PWR_REGULATOR(PWR_Regulator)); |
mbed_official | 130:1dec54e4aec3 | 431 | assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry)); |
mbed_official | 130:1dec54e4aec3 | 432 | |
mbed_official | 130:1dec54e4aec3 | 433 | /* Select the regulator state in STOP mode ---------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 434 | tmpreg = PWR->CR; |
mbed_official | 130:1dec54e4aec3 | 435 | /* Clear PDDS and LPDSR bits */ |
mbed_official | 130:1dec54e4aec3 | 436 | tmpreg &= CR_DS_MASK; |
mbed_official | 130:1dec54e4aec3 | 437 | |
mbed_official | 130:1dec54e4aec3 | 438 | /* Set LPDSR bit according to PWR_Regulator value */ |
mbed_official | 130:1dec54e4aec3 | 439 | tmpreg |= PWR_Regulator; |
mbed_official | 130:1dec54e4aec3 | 440 | |
mbed_official | 130:1dec54e4aec3 | 441 | /* Store the new value */ |
mbed_official | 130:1dec54e4aec3 | 442 | PWR->CR = tmpreg; |
mbed_official | 130:1dec54e4aec3 | 443 | |
mbed_official | 130:1dec54e4aec3 | 444 | /* Set SLEEPDEEP bit of Cortex-M0 System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 445 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 130:1dec54e4aec3 | 446 | |
mbed_official | 130:1dec54e4aec3 | 447 | /* Select STOP mode entry --------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 448 | if(PWR_STOPEntry == PWR_STOPEntry_WFI) |
mbed_official | 130:1dec54e4aec3 | 449 | { |
mbed_official | 130:1dec54e4aec3 | 450 | /* Request Wait For Interrupt */ |
mbed_official | 130:1dec54e4aec3 | 451 | __WFI(); |
mbed_official | 130:1dec54e4aec3 | 452 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 453 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 130:1dec54e4aec3 | 454 | } |
mbed_official | 130:1dec54e4aec3 | 455 | else if (PWR_STOPEntry == PWR_STOPEntry_WFE) |
mbed_official | 130:1dec54e4aec3 | 456 | { |
mbed_official | 130:1dec54e4aec3 | 457 | /* Request Wait For Event */ |
mbed_official | 130:1dec54e4aec3 | 458 | __WFE(); |
mbed_official | 130:1dec54e4aec3 | 459 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 460 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
mbed_official | 130:1dec54e4aec3 | 461 | } |
mbed_official | 130:1dec54e4aec3 | 462 | else |
mbed_official | 130:1dec54e4aec3 | 463 | { |
mbed_official | 130:1dec54e4aec3 | 464 | /* Set SLEEP on exit bit of Cortex-M0 System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 465 | SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk; |
mbed_official | 130:1dec54e4aec3 | 466 | } |
mbed_official | 130:1dec54e4aec3 | 467 | } |
mbed_official | 130:1dec54e4aec3 | 468 | |
mbed_official | 130:1dec54e4aec3 | 469 | /** |
mbed_official | 130:1dec54e4aec3 | 470 | * @brief Enters STANDBY mode. |
mbed_official | 130:1dec54e4aec3 | 471 | * @note In Standby mode, all I/O pins are high impedance except for: |
mbed_official | 130:1dec54e4aec3 | 472 | * - Reset pad (still available) |
mbed_official | 130:1dec54e4aec3 | 473 | * - RTC_AF1 pin (PC13) if configured for Wakeup pin 2 (WKUP2), tamper, |
mbed_official | 130:1dec54e4aec3 | 474 | * time-stamp, RTC Alarm out, or RTC clock calibration out. |
mbed_official | 130:1dec54e4aec3 | 475 | * - WKUP pin 1 (PA0) if enabled. |
mbed_official | 130:1dec54e4aec3 | 476 | * @param None |
mbed_official | 130:1dec54e4aec3 | 477 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 478 | */ |
mbed_official | 130:1dec54e4aec3 | 479 | void PWR_EnterSTANDBYMode(void) |
mbed_official | 130:1dec54e4aec3 | 480 | { |
mbed_official | 130:1dec54e4aec3 | 481 | /* Clear Wakeup flag */ |
mbed_official | 130:1dec54e4aec3 | 482 | PWR->CR |= PWR_CR_CWUF; |
mbed_official | 130:1dec54e4aec3 | 483 | |
mbed_official | 130:1dec54e4aec3 | 484 | /* Select STANDBY mode */ |
mbed_official | 130:1dec54e4aec3 | 485 | PWR->CR |= PWR_CR_PDDS; |
mbed_official | 130:1dec54e4aec3 | 486 | |
mbed_official | 130:1dec54e4aec3 | 487 | /* Set SLEEPDEEP bit of Cortex-M0 System Control Register */ |
mbed_official | 130:1dec54e4aec3 | 488 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 130:1dec54e4aec3 | 489 | |
mbed_official | 130:1dec54e4aec3 | 490 | /* Request Wait For Interrupt */ |
mbed_official | 130:1dec54e4aec3 | 491 | __WFI(); |
mbed_official | 130:1dec54e4aec3 | 492 | } |
mbed_official | 130:1dec54e4aec3 | 493 | |
mbed_official | 130:1dec54e4aec3 | 494 | /** |
mbed_official | 130:1dec54e4aec3 | 495 | * @} |
mbed_official | 130:1dec54e4aec3 | 496 | */ |
mbed_official | 130:1dec54e4aec3 | 497 | |
mbed_official | 130:1dec54e4aec3 | 498 | /** @defgroup PWR_Group5 Flags management functions |
mbed_official | 130:1dec54e4aec3 | 499 | * @brief Flags management functions |
mbed_official | 130:1dec54e4aec3 | 500 | * |
mbed_official | 130:1dec54e4aec3 | 501 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 502 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 503 | ##### Flags management functions ##### |
mbed_official | 130:1dec54e4aec3 | 504 | ============================================================================== |
mbed_official | 130:1dec54e4aec3 | 505 | |
mbed_official | 130:1dec54e4aec3 | 506 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 507 | * @{ |
mbed_official | 130:1dec54e4aec3 | 508 | */ |
mbed_official | 130:1dec54e4aec3 | 509 | |
mbed_official | 130:1dec54e4aec3 | 510 | /** |
mbed_official | 130:1dec54e4aec3 | 511 | * @brief Checks whether the specified PWR flag is set or not. |
mbed_official | 130:1dec54e4aec3 | 512 | * @param PWR_FLAG: specifies the flag to check. |
mbed_official | 130:1dec54e4aec3 | 513 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 514 | * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup |
mbed_official | 130:1dec54e4aec3 | 515 | * event was received from the WKUP pin or from the RTC alarm |
mbed_official | 130:1dec54e4aec3 | 516 | * (Alarm A or Alarm B), RTC Tamper event or RTC TimeStamp event. |
mbed_official | 130:1dec54e4aec3 | 517 | * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the |
mbed_official | 130:1dec54e4aec3 | 518 | * system was resumed from StandBy mode. |
mbed_official | 130:1dec54e4aec3 | 519 | * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD |
mbed_official | 130:1dec54e4aec3 | 520 | * is enabled by the PWR_PVDCmd() function. |
mbed_official | 130:1dec54e4aec3 | 521 | * @arg PWR_FLAG_VREFINTRDY: Internal Voltage Reference Ready flag. |
mbed_official | 130:1dec54e4aec3 | 522 | * This flag indicates the state of the internal voltage |
mbed_official | 130:1dec54e4aec3 | 523 | * reference, VREFINT. |
mbed_official | 130:1dec54e4aec3 | 524 | * @retval The new state of PWR_FLAG (SET or RESET). |
mbed_official | 130:1dec54e4aec3 | 525 | */ |
mbed_official | 130:1dec54e4aec3 | 526 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG) |
mbed_official | 130:1dec54e4aec3 | 527 | { |
mbed_official | 130:1dec54e4aec3 | 528 | FlagStatus bitstatus = RESET; |
mbed_official | 130:1dec54e4aec3 | 529 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 530 | assert_param(IS_PWR_GET_FLAG(PWR_FLAG)); |
mbed_official | 130:1dec54e4aec3 | 531 | |
mbed_official | 130:1dec54e4aec3 | 532 | if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET) |
mbed_official | 130:1dec54e4aec3 | 533 | { |
mbed_official | 130:1dec54e4aec3 | 534 | bitstatus = SET; |
mbed_official | 130:1dec54e4aec3 | 535 | } |
mbed_official | 130:1dec54e4aec3 | 536 | else |
mbed_official | 130:1dec54e4aec3 | 537 | { |
mbed_official | 130:1dec54e4aec3 | 538 | bitstatus = RESET; |
mbed_official | 130:1dec54e4aec3 | 539 | } |
mbed_official | 130:1dec54e4aec3 | 540 | /* Return the flag status */ |
mbed_official | 130:1dec54e4aec3 | 541 | return bitstatus; |
mbed_official | 130:1dec54e4aec3 | 542 | } |
mbed_official | 130:1dec54e4aec3 | 543 | |
mbed_official | 130:1dec54e4aec3 | 544 | /** |
mbed_official | 130:1dec54e4aec3 | 545 | * @brief Clears the PWR's pending flags. |
mbed_official | 130:1dec54e4aec3 | 546 | * @param PWR_FLAG: specifies the flag to clear. |
mbed_official | 130:1dec54e4aec3 | 547 | * This parameter can be one of the following values: |
mbed_official | 130:1dec54e4aec3 | 548 | * @arg PWR_FLAG_WU: Wake Up flag |
mbed_official | 130:1dec54e4aec3 | 549 | * @arg PWR_FLAG_SB: StandBy flag |
mbed_official | 130:1dec54e4aec3 | 550 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 551 | */ |
mbed_official | 130:1dec54e4aec3 | 552 | void PWR_ClearFlag(uint32_t PWR_FLAG) |
mbed_official | 130:1dec54e4aec3 | 553 | { |
mbed_official | 130:1dec54e4aec3 | 554 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 555 | assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG)); |
mbed_official | 130:1dec54e4aec3 | 556 | |
mbed_official | 130:1dec54e4aec3 | 557 | PWR->CR |= PWR_FLAG << 2; |
mbed_official | 130:1dec54e4aec3 | 558 | } |
mbed_official | 130:1dec54e4aec3 | 559 | |
mbed_official | 130:1dec54e4aec3 | 560 | /** |
mbed_official | 130:1dec54e4aec3 | 561 | * @} |
mbed_official | 130:1dec54e4aec3 | 562 | */ |
mbed_official | 130:1dec54e4aec3 | 563 | |
mbed_official | 130:1dec54e4aec3 | 564 | /** |
mbed_official | 130:1dec54e4aec3 | 565 | * @} |
mbed_official | 130:1dec54e4aec3 | 566 | */ |
mbed_official | 130:1dec54e4aec3 | 567 | |
mbed_official | 130:1dec54e4aec3 | 568 | /** |
mbed_official | 130:1dec54e4aec3 | 569 | * @} |
mbed_official | 130:1dec54e4aec3 | 570 | */ |
mbed_official | 130:1dec54e4aec3 | 571 | |
mbed_official | 130:1dec54e4aec3 | 572 | /** |
mbed_official | 130:1dec54e4aec3 | 573 | * @} |
mbed_official | 130:1dec54e4aec3 | 574 | */ |
mbed_official | 130:1dec54e4aec3 | 575 | |
mbed_official | 130:1dec54e4aec3 | 576 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |