mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Dec 02 11:30:05 2013 +0000
Revision:
52:a51c77007319
Child:
70:c1fbde68b492
Synchronized with git revision 49df530ae72ce97ccc773d1f2c13b38e868e6abd

Full URL: https://github.com/mbedmicro/mbed/commit/49df530ae72ce97ccc773d1f2c13b38e868e6abd/

Add STMicroelectronics NUCLEO_F103RB target

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /**
mbed_official 52:a51c77007319 2 ******************************************************************************
mbed_official 52:a51c77007319 3 * @file stm32f10x_pwr.c
mbed_official 52:a51c77007319 4 * @author MCD Application Team
mbed_official 52:a51c77007319 5 * @version V3.5.0
mbed_official 52:a51c77007319 6 * @date 11-March-2011
mbed_official 52:a51c77007319 7 * @brief This file provides all the PWR firmware functions.
mbed_official 52:a51c77007319 8 ******************************************************************************
mbed_official 52:a51c77007319 9 * @attention
mbed_official 52:a51c77007319 10 *
mbed_official 52:a51c77007319 11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
mbed_official 52:a51c77007319 12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
mbed_official 52:a51c77007319 13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
mbed_official 52:a51c77007319 14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
mbed_official 52:a51c77007319 15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
mbed_official 52:a51c77007319 16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
mbed_official 52:a51c77007319 17 *
mbed_official 52:a51c77007319 18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
mbed_official 52:a51c77007319 19 ******************************************************************************
mbed_official 52:a51c77007319 20 */
mbed_official 52:a51c77007319 21
mbed_official 52:a51c77007319 22 /* Includes ------------------------------------------------------------------*/
mbed_official 52:a51c77007319 23 #include "stm32f10x_pwr.h"
mbed_official 52:a51c77007319 24 #include "stm32f10x_rcc.h"
mbed_official 52:a51c77007319 25
mbed_official 52:a51c77007319 26 /** @addtogroup STM32F10x_StdPeriph_Driver
mbed_official 52:a51c77007319 27 * @{
mbed_official 52:a51c77007319 28 */
mbed_official 52:a51c77007319 29
mbed_official 52:a51c77007319 30 /** @defgroup PWR
mbed_official 52:a51c77007319 31 * @brief PWR driver modules
mbed_official 52:a51c77007319 32 * @{
mbed_official 52:a51c77007319 33 */
mbed_official 52:a51c77007319 34
mbed_official 52:a51c77007319 35 /** @defgroup PWR_Private_TypesDefinitions
mbed_official 52:a51c77007319 36 * @{
mbed_official 52:a51c77007319 37 */
mbed_official 52:a51c77007319 38
mbed_official 52:a51c77007319 39 /**
mbed_official 52:a51c77007319 40 * @}
mbed_official 52:a51c77007319 41 */
mbed_official 52:a51c77007319 42
mbed_official 52:a51c77007319 43 /** @defgroup PWR_Private_Defines
mbed_official 52:a51c77007319 44 * @{
mbed_official 52:a51c77007319 45 */
mbed_official 52:a51c77007319 46
mbed_official 52:a51c77007319 47 /* --------- PWR registers bit address in the alias region ---------- */
mbed_official 52:a51c77007319 48 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
mbed_official 52:a51c77007319 49
mbed_official 52:a51c77007319 50 /* --- CR Register ---*/
mbed_official 52:a51c77007319 51
mbed_official 52:a51c77007319 52 /* Alias word address of DBP bit */
mbed_official 52:a51c77007319 53 #define CR_OFFSET (PWR_OFFSET + 0x00)
mbed_official 52:a51c77007319 54 #define DBP_BitNumber 0x08
mbed_official 52:a51c77007319 55 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
mbed_official 52:a51c77007319 56
mbed_official 52:a51c77007319 57 /* Alias word address of PVDE bit */
mbed_official 52:a51c77007319 58 #define PVDE_BitNumber 0x04
mbed_official 52:a51c77007319 59 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
mbed_official 52:a51c77007319 60
mbed_official 52:a51c77007319 61 /* --- CSR Register ---*/
mbed_official 52:a51c77007319 62
mbed_official 52:a51c77007319 63 /* Alias word address of EWUP bit */
mbed_official 52:a51c77007319 64 #define CSR_OFFSET (PWR_OFFSET + 0x04)
mbed_official 52:a51c77007319 65 #define EWUP_BitNumber 0x08
mbed_official 52:a51c77007319 66 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
mbed_official 52:a51c77007319 67
mbed_official 52:a51c77007319 68 /* ------------------ PWR registers bit mask ------------------------ */
mbed_official 52:a51c77007319 69
mbed_official 52:a51c77007319 70 /* CR register bit mask */
mbed_official 52:a51c77007319 71 #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
mbed_official 52:a51c77007319 72 #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
mbed_official 52:a51c77007319 73
mbed_official 52:a51c77007319 74
mbed_official 52:a51c77007319 75 /**
mbed_official 52:a51c77007319 76 * @}
mbed_official 52:a51c77007319 77 */
mbed_official 52:a51c77007319 78
mbed_official 52:a51c77007319 79 /** @defgroup PWR_Private_Macros
mbed_official 52:a51c77007319 80 * @{
mbed_official 52:a51c77007319 81 */
mbed_official 52:a51c77007319 82
mbed_official 52:a51c77007319 83 /**
mbed_official 52:a51c77007319 84 * @}
mbed_official 52:a51c77007319 85 */
mbed_official 52:a51c77007319 86
mbed_official 52:a51c77007319 87 /** @defgroup PWR_Private_Variables
mbed_official 52:a51c77007319 88 * @{
mbed_official 52:a51c77007319 89 */
mbed_official 52:a51c77007319 90
mbed_official 52:a51c77007319 91 /**
mbed_official 52:a51c77007319 92 * @}
mbed_official 52:a51c77007319 93 */
mbed_official 52:a51c77007319 94
mbed_official 52:a51c77007319 95 /** @defgroup PWR_Private_FunctionPrototypes
mbed_official 52:a51c77007319 96 * @{
mbed_official 52:a51c77007319 97 */
mbed_official 52:a51c77007319 98
mbed_official 52:a51c77007319 99 /**
mbed_official 52:a51c77007319 100 * @}
mbed_official 52:a51c77007319 101 */
mbed_official 52:a51c77007319 102
mbed_official 52:a51c77007319 103 /** @defgroup PWR_Private_Functions
mbed_official 52:a51c77007319 104 * @{
mbed_official 52:a51c77007319 105 */
mbed_official 52:a51c77007319 106
mbed_official 52:a51c77007319 107 /**
mbed_official 52:a51c77007319 108 * @brief Deinitializes the PWR peripheral registers to their default reset values.
mbed_official 52:a51c77007319 109 * @param None
mbed_official 52:a51c77007319 110 * @retval None
mbed_official 52:a51c77007319 111 */
mbed_official 52:a51c77007319 112 void PWR_DeInit(void)
mbed_official 52:a51c77007319 113 {
mbed_official 52:a51c77007319 114 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
mbed_official 52:a51c77007319 115 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
mbed_official 52:a51c77007319 116 }
mbed_official 52:a51c77007319 117
mbed_official 52:a51c77007319 118 /**
mbed_official 52:a51c77007319 119 * @brief Enables or disables access to the RTC and backup registers.
mbed_official 52:a51c77007319 120 * @param NewState: new state of the access to the RTC and backup registers.
mbed_official 52:a51c77007319 121 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 122 * @retval None
mbed_official 52:a51c77007319 123 */
mbed_official 52:a51c77007319 124 void PWR_BackupAccessCmd(FunctionalState NewState)
mbed_official 52:a51c77007319 125 {
mbed_official 52:a51c77007319 126 /* Check the parameters */
mbed_official 52:a51c77007319 127 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 128 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
mbed_official 52:a51c77007319 129 }
mbed_official 52:a51c77007319 130
mbed_official 52:a51c77007319 131 /**
mbed_official 52:a51c77007319 132 * @brief Enables or disables the Power Voltage Detector(PVD).
mbed_official 52:a51c77007319 133 * @param NewState: new state of the PVD.
mbed_official 52:a51c77007319 134 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 135 * @retval None
mbed_official 52:a51c77007319 136 */
mbed_official 52:a51c77007319 137 void PWR_PVDCmd(FunctionalState NewState)
mbed_official 52:a51c77007319 138 {
mbed_official 52:a51c77007319 139 /* Check the parameters */
mbed_official 52:a51c77007319 140 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 141 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
mbed_official 52:a51c77007319 142 }
mbed_official 52:a51c77007319 143
mbed_official 52:a51c77007319 144 /**
mbed_official 52:a51c77007319 145 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 52:a51c77007319 146 * @param PWR_PVDLevel: specifies the PVD detection level
mbed_official 52:a51c77007319 147 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 148 * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V
mbed_official 52:a51c77007319 149 * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V
mbed_official 52:a51c77007319 150 * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V
mbed_official 52:a51c77007319 151 * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V
mbed_official 52:a51c77007319 152 * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V
mbed_official 52:a51c77007319 153 * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V
mbed_official 52:a51c77007319 154 * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V
mbed_official 52:a51c77007319 155 * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V
mbed_official 52:a51c77007319 156 * @retval None
mbed_official 52:a51c77007319 157 */
mbed_official 52:a51c77007319 158 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
mbed_official 52:a51c77007319 159 {
mbed_official 52:a51c77007319 160 uint32_t tmpreg = 0;
mbed_official 52:a51c77007319 161 /* Check the parameters */
mbed_official 52:a51c77007319 162 assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
mbed_official 52:a51c77007319 163 tmpreg = PWR->CR;
mbed_official 52:a51c77007319 164 /* Clear PLS[7:5] bits */
mbed_official 52:a51c77007319 165 tmpreg &= CR_PLS_MASK;
mbed_official 52:a51c77007319 166 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
mbed_official 52:a51c77007319 167 tmpreg |= PWR_PVDLevel;
mbed_official 52:a51c77007319 168 /* Store the new value */
mbed_official 52:a51c77007319 169 PWR->CR = tmpreg;
mbed_official 52:a51c77007319 170 }
mbed_official 52:a51c77007319 171
mbed_official 52:a51c77007319 172 /**
mbed_official 52:a51c77007319 173 * @brief Enables or disables the WakeUp Pin functionality.
mbed_official 52:a51c77007319 174 * @param NewState: new state of the WakeUp Pin functionality.
mbed_official 52:a51c77007319 175 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 176 * @retval None
mbed_official 52:a51c77007319 177 */
mbed_official 52:a51c77007319 178 void PWR_WakeUpPinCmd(FunctionalState NewState)
mbed_official 52:a51c77007319 179 {
mbed_official 52:a51c77007319 180 /* Check the parameters */
mbed_official 52:a51c77007319 181 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 182 *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
mbed_official 52:a51c77007319 183 }
mbed_official 52:a51c77007319 184
mbed_official 52:a51c77007319 185 /**
mbed_official 52:a51c77007319 186 * @brief Enters STOP mode.
mbed_official 52:a51c77007319 187 * @param PWR_Regulator: specifies the regulator state in STOP mode.
mbed_official 52:a51c77007319 188 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 189 * @arg PWR_Regulator_ON: STOP mode with regulator ON
mbed_official 52:a51c77007319 190 * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
mbed_official 52:a51c77007319 191 * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
mbed_official 52:a51c77007319 192 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 193 * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
mbed_official 52:a51c77007319 194 * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
mbed_official 52:a51c77007319 195 * @retval None
mbed_official 52:a51c77007319 196 */
mbed_official 52:a51c77007319 197 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
mbed_official 52:a51c77007319 198 {
mbed_official 52:a51c77007319 199 uint32_t tmpreg = 0;
mbed_official 52:a51c77007319 200 /* Check the parameters */
mbed_official 52:a51c77007319 201 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
mbed_official 52:a51c77007319 202 assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
mbed_official 52:a51c77007319 203
mbed_official 52:a51c77007319 204 /* Select the regulator state in STOP mode ---------------------------------*/
mbed_official 52:a51c77007319 205 tmpreg = PWR->CR;
mbed_official 52:a51c77007319 206 /* Clear PDDS and LPDS bits */
mbed_official 52:a51c77007319 207 tmpreg &= CR_DS_MASK;
mbed_official 52:a51c77007319 208 /* Set LPDS bit according to PWR_Regulator value */
mbed_official 52:a51c77007319 209 tmpreg |= PWR_Regulator;
mbed_official 52:a51c77007319 210 /* Store the new value */
mbed_official 52:a51c77007319 211 PWR->CR = tmpreg;
mbed_official 52:a51c77007319 212 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 52:a51c77007319 213 SCB->SCR |= SCB_SCR_SLEEPDEEP;
mbed_official 52:a51c77007319 214
mbed_official 52:a51c77007319 215 /* Select STOP mode entry --------------------------------------------------*/
mbed_official 52:a51c77007319 216 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
mbed_official 52:a51c77007319 217 {
mbed_official 52:a51c77007319 218 /* Request Wait For Interrupt */
mbed_official 52:a51c77007319 219 __WFI();
mbed_official 52:a51c77007319 220 }
mbed_official 52:a51c77007319 221 else
mbed_official 52:a51c77007319 222 {
mbed_official 52:a51c77007319 223 /* Request Wait For Event */
mbed_official 52:a51c77007319 224 __WFE();
mbed_official 52:a51c77007319 225 }
mbed_official 52:a51c77007319 226
mbed_official 52:a51c77007319 227 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 52:a51c77007319 228 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
mbed_official 52:a51c77007319 229 }
mbed_official 52:a51c77007319 230
mbed_official 52:a51c77007319 231 /**
mbed_official 52:a51c77007319 232 * @brief Enters STANDBY mode.
mbed_official 52:a51c77007319 233 * @param None
mbed_official 52:a51c77007319 234 * @retval None
mbed_official 52:a51c77007319 235 */
mbed_official 52:a51c77007319 236 void PWR_EnterSTANDBYMode(void)
mbed_official 52:a51c77007319 237 {
mbed_official 52:a51c77007319 238 /* Clear Wake-up flag */
mbed_official 52:a51c77007319 239 PWR->CR |= PWR_CR_CWUF;
mbed_official 52:a51c77007319 240 /* Select STANDBY mode */
mbed_official 52:a51c77007319 241 PWR->CR |= PWR_CR_PDDS;
mbed_official 52:a51c77007319 242 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 52:a51c77007319 243 SCB->SCR |= SCB_SCR_SLEEPDEEP;
mbed_official 52:a51c77007319 244 /* This option is used to ensure that store operations are completed */
mbed_official 52:a51c77007319 245 #if defined ( __CC_ARM )
mbed_official 52:a51c77007319 246 __force_stores();
mbed_official 52:a51c77007319 247 #endif
mbed_official 52:a51c77007319 248 /* Request Wait For Interrupt */
mbed_official 52:a51c77007319 249 __WFI();
mbed_official 52:a51c77007319 250 }
mbed_official 52:a51c77007319 251
mbed_official 52:a51c77007319 252 /**
mbed_official 52:a51c77007319 253 * @brief Checks whether the specified PWR flag is set or not.
mbed_official 52:a51c77007319 254 * @param PWR_FLAG: specifies the flag to check.
mbed_official 52:a51c77007319 255 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 256 * @arg PWR_FLAG_WU: Wake Up flag
mbed_official 52:a51c77007319 257 * @arg PWR_FLAG_SB: StandBy flag
mbed_official 52:a51c77007319 258 * @arg PWR_FLAG_PVDO: PVD Output
mbed_official 52:a51c77007319 259 * @retval The new state of PWR_FLAG (SET or RESET).
mbed_official 52:a51c77007319 260 */
mbed_official 52:a51c77007319 261 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
mbed_official 52:a51c77007319 262 {
mbed_official 52:a51c77007319 263 FlagStatus bitstatus = RESET;
mbed_official 52:a51c77007319 264 /* Check the parameters */
mbed_official 52:a51c77007319 265 assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
mbed_official 52:a51c77007319 266
mbed_official 52:a51c77007319 267 if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
mbed_official 52:a51c77007319 268 {
mbed_official 52:a51c77007319 269 bitstatus = SET;
mbed_official 52:a51c77007319 270 }
mbed_official 52:a51c77007319 271 else
mbed_official 52:a51c77007319 272 {
mbed_official 52:a51c77007319 273 bitstatus = RESET;
mbed_official 52:a51c77007319 274 }
mbed_official 52:a51c77007319 275 /* Return the flag status */
mbed_official 52:a51c77007319 276 return bitstatus;
mbed_official 52:a51c77007319 277 }
mbed_official 52:a51c77007319 278
mbed_official 52:a51c77007319 279 /**
mbed_official 52:a51c77007319 280 * @brief Clears the PWR's pending flags.
mbed_official 52:a51c77007319 281 * @param PWR_FLAG: specifies the flag to clear.
mbed_official 52:a51c77007319 282 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 283 * @arg PWR_FLAG_WU: Wake Up flag
mbed_official 52:a51c77007319 284 * @arg PWR_FLAG_SB: StandBy flag
mbed_official 52:a51c77007319 285 * @retval None
mbed_official 52:a51c77007319 286 */
mbed_official 52:a51c77007319 287 void PWR_ClearFlag(uint32_t PWR_FLAG)
mbed_official 52:a51c77007319 288 {
mbed_official 52:a51c77007319 289 /* Check the parameters */
mbed_official 52:a51c77007319 290 assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
mbed_official 52:a51c77007319 291
mbed_official 52:a51c77007319 292 PWR->CR |= PWR_FLAG << 2;
mbed_official 52:a51c77007319 293 }
mbed_official 52:a51c77007319 294
mbed_official 52:a51c77007319 295 /**
mbed_official 52:a51c77007319 296 * @}
mbed_official 52:a51c77007319 297 */
mbed_official 52:a51c77007319 298
mbed_official 52:a51c77007319 299 /**
mbed_official 52:a51c77007319 300 * @}
mbed_official 52:a51c77007319 301 */
mbed_official 52:a51c77007319 302
mbed_official 52:a51c77007319 303 /**
mbed_official 52:a51c77007319 304 * @}
mbed_official 52:a51c77007319 305 */
mbed_official 52:a51c77007319 306
mbed_official 52:a51c77007319 307 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/