mbed w/ spi bug fig

Dependents:   display-puck

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jun 27 07:30:09 2014 +0100
Revision:
242:7074e42da0b2
Parent:
133:d4dda5c437f0
Synchronized with git revision 124ef5e3add9e74a3221347a3fbeea7c8b3cf353

Full URL: https://github.com/mbedmicro/mbed/commit/124ef5e3add9e74a3221347a3fbeea7c8b3cf353/

[DISCO_F407VG] HAL update.

Who changed what in which revision?

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