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_bkp.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 BKP 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_bkp.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 BKP
mbed_official 52:a51c77007319 31 * @brief BKP driver modules
mbed_official 52:a51c77007319 32 * @{
mbed_official 52:a51c77007319 33 */
mbed_official 52:a51c77007319 34
mbed_official 52:a51c77007319 35 /** @defgroup BKP_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 BKP_Private_Defines
mbed_official 52:a51c77007319 44 * @{
mbed_official 52:a51c77007319 45 */
mbed_official 52:a51c77007319 46
mbed_official 52:a51c77007319 47 /* ------------ BKP registers bit address in the alias region --------------- */
mbed_official 52:a51c77007319 48 #define BKP_OFFSET (BKP_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 TPAL bit */
mbed_official 52:a51c77007319 53 #define CR_OFFSET (BKP_OFFSET + 0x30)
mbed_official 52:a51c77007319 54 #define TPAL_BitNumber 0x01
mbed_official 52:a51c77007319 55 #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
mbed_official 52:a51c77007319 56
mbed_official 52:a51c77007319 57 /* Alias word address of TPE bit */
mbed_official 52:a51c77007319 58 #define TPE_BitNumber 0x00
mbed_official 52:a51c77007319 59 #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_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 TPIE bit */
mbed_official 52:a51c77007319 64 #define CSR_OFFSET (BKP_OFFSET + 0x34)
mbed_official 52:a51c77007319 65 #define TPIE_BitNumber 0x02
mbed_official 52:a51c77007319 66 #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
mbed_official 52:a51c77007319 67
mbed_official 52:a51c77007319 68 /* Alias word address of TIF bit */
mbed_official 52:a51c77007319 69 #define TIF_BitNumber 0x09
mbed_official 52:a51c77007319 70 #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
mbed_official 52:a51c77007319 71
mbed_official 52:a51c77007319 72 /* Alias word address of TEF bit */
mbed_official 52:a51c77007319 73 #define TEF_BitNumber 0x08
mbed_official 52:a51c77007319 74 #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
mbed_official 52:a51c77007319 75
mbed_official 52:a51c77007319 76 /* ---------------------- BKP registers bit mask ------------------------ */
mbed_official 52:a51c77007319 77
mbed_official 52:a51c77007319 78 /* RTCCR register bit mask */
mbed_official 52:a51c77007319 79 #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
mbed_official 52:a51c77007319 80 #define RTCCR_MASK ((uint16_t)0xFC7F)
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 BKP_Private_Macros
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 BKP_Private_Variables
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 BKP_Private_FunctionPrototypes
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 * @}
mbed_official 52:a51c77007319 109 */
mbed_official 52:a51c77007319 110
mbed_official 52:a51c77007319 111 /** @defgroup BKP_Private_Functions
mbed_official 52:a51c77007319 112 * @{
mbed_official 52:a51c77007319 113 */
mbed_official 52:a51c77007319 114
mbed_official 52:a51c77007319 115 /**
mbed_official 52:a51c77007319 116 * @brief Deinitializes the BKP peripheral registers to their default reset values.
mbed_official 52:a51c77007319 117 * @param None
mbed_official 52:a51c77007319 118 * @retval None
mbed_official 52:a51c77007319 119 */
mbed_official 52:a51c77007319 120 void BKP_DeInit(void)
mbed_official 52:a51c77007319 121 {
mbed_official 52:a51c77007319 122 RCC_BackupResetCmd(ENABLE);
mbed_official 52:a51c77007319 123 RCC_BackupResetCmd(DISABLE);
mbed_official 52:a51c77007319 124 }
mbed_official 52:a51c77007319 125
mbed_official 52:a51c77007319 126 /**
mbed_official 52:a51c77007319 127 * @brief Configures the Tamper Pin active level.
mbed_official 52:a51c77007319 128 * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
mbed_official 52:a51c77007319 129 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 130 * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
mbed_official 52:a51c77007319 131 * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
mbed_official 52:a51c77007319 132 * @retval None
mbed_official 52:a51c77007319 133 */
mbed_official 52:a51c77007319 134 void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
mbed_official 52:a51c77007319 135 {
mbed_official 52:a51c77007319 136 /* Check the parameters */
mbed_official 52:a51c77007319 137 assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
mbed_official 52:a51c77007319 138 *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
mbed_official 52:a51c77007319 139 }
mbed_official 52:a51c77007319 140
mbed_official 52:a51c77007319 141 /**
mbed_official 52:a51c77007319 142 * @brief Enables or disables the Tamper Pin activation.
mbed_official 52:a51c77007319 143 * @param NewState: new state of the Tamper Pin activation.
mbed_official 52:a51c77007319 144 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 145 * @retval None
mbed_official 52:a51c77007319 146 */
mbed_official 52:a51c77007319 147 void BKP_TamperPinCmd(FunctionalState NewState)
mbed_official 52:a51c77007319 148 {
mbed_official 52:a51c77007319 149 /* Check the parameters */
mbed_official 52:a51c77007319 150 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 151 *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
mbed_official 52:a51c77007319 152 }
mbed_official 52:a51c77007319 153
mbed_official 52:a51c77007319 154 /**
mbed_official 52:a51c77007319 155 * @brief Enables or disables the Tamper Pin Interrupt.
mbed_official 52:a51c77007319 156 * @param NewState: new state of the Tamper Pin Interrupt.
mbed_official 52:a51c77007319 157 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 158 * @retval None
mbed_official 52:a51c77007319 159 */
mbed_official 52:a51c77007319 160 void BKP_ITConfig(FunctionalState NewState)
mbed_official 52:a51c77007319 161 {
mbed_official 52:a51c77007319 162 /* Check the parameters */
mbed_official 52:a51c77007319 163 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 164 *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
mbed_official 52:a51c77007319 165 }
mbed_official 52:a51c77007319 166
mbed_official 52:a51c77007319 167 /**
mbed_official 52:a51c77007319 168 * @brief Select the RTC output source to output on the Tamper pin.
mbed_official 52:a51c77007319 169 * @param BKP_RTCOutputSource: specifies the RTC output source.
mbed_official 52:a51c77007319 170 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 171 * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
mbed_official 52:a51c77007319 172 * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
mbed_official 52:a51c77007319 173 * divided by 64 on the Tamper pin.
mbed_official 52:a51c77007319 174 * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
mbed_official 52:a51c77007319 175 * the Tamper pin.
mbed_official 52:a51c77007319 176 * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
mbed_official 52:a51c77007319 177 * the Tamper pin.
mbed_official 52:a51c77007319 178 * @retval None
mbed_official 52:a51c77007319 179 */
mbed_official 52:a51c77007319 180 void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
mbed_official 52:a51c77007319 181 {
mbed_official 52:a51c77007319 182 uint16_t tmpreg = 0;
mbed_official 52:a51c77007319 183 /* Check the parameters */
mbed_official 52:a51c77007319 184 assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
mbed_official 52:a51c77007319 185 tmpreg = BKP->RTCCR;
mbed_official 52:a51c77007319 186 /* Clear CCO, ASOE and ASOS bits */
mbed_official 52:a51c77007319 187 tmpreg &= RTCCR_MASK;
mbed_official 52:a51c77007319 188
mbed_official 52:a51c77007319 189 /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
mbed_official 52:a51c77007319 190 tmpreg |= BKP_RTCOutputSource;
mbed_official 52:a51c77007319 191 /* Store the new value */
mbed_official 52:a51c77007319 192 BKP->RTCCR = tmpreg;
mbed_official 52:a51c77007319 193 }
mbed_official 52:a51c77007319 194
mbed_official 52:a51c77007319 195 /**
mbed_official 52:a51c77007319 196 * @brief Sets RTC Clock Calibration value.
mbed_official 52:a51c77007319 197 * @param CalibrationValue: specifies the RTC Clock Calibration value.
mbed_official 52:a51c77007319 198 * This parameter must be a number between 0 and 0x7F.
mbed_official 52:a51c77007319 199 * @retval None
mbed_official 52:a51c77007319 200 */
mbed_official 52:a51c77007319 201 void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
mbed_official 52:a51c77007319 202 {
mbed_official 52:a51c77007319 203 uint16_t tmpreg = 0;
mbed_official 52:a51c77007319 204 /* Check the parameters */
mbed_official 52:a51c77007319 205 assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
mbed_official 52:a51c77007319 206 tmpreg = BKP->RTCCR;
mbed_official 52:a51c77007319 207 /* Clear CAL[6:0] bits */
mbed_official 52:a51c77007319 208 tmpreg &= RTCCR_CAL_MASK;
mbed_official 52:a51c77007319 209 /* Set CAL[6:0] bits according to CalibrationValue value */
mbed_official 52:a51c77007319 210 tmpreg |= CalibrationValue;
mbed_official 52:a51c77007319 211 /* Store the new value */
mbed_official 52:a51c77007319 212 BKP->RTCCR = tmpreg;
mbed_official 52:a51c77007319 213 }
mbed_official 52:a51c77007319 214
mbed_official 52:a51c77007319 215 /**
mbed_official 52:a51c77007319 216 * @brief Writes user data to the specified Data Backup Register.
mbed_official 52:a51c77007319 217 * @param BKP_DR: specifies the Data Backup Register.
mbed_official 52:a51c77007319 218 * This parameter can be BKP_DRx where x:[1, 42]
mbed_official 52:a51c77007319 219 * @param Data: data to write
mbed_official 52:a51c77007319 220 * @retval None
mbed_official 52:a51c77007319 221 */
mbed_official 52:a51c77007319 222 void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
mbed_official 52:a51c77007319 223 {
mbed_official 52:a51c77007319 224 __IO uint32_t tmp = 0;
mbed_official 52:a51c77007319 225
mbed_official 52:a51c77007319 226 /* Check the parameters */
mbed_official 52:a51c77007319 227 assert_param(IS_BKP_DR(BKP_DR));
mbed_official 52:a51c77007319 228
mbed_official 52:a51c77007319 229 tmp = (uint32_t)BKP_BASE;
mbed_official 52:a51c77007319 230 tmp += BKP_DR;
mbed_official 52:a51c77007319 231
mbed_official 52:a51c77007319 232 *(__IO uint32_t *) tmp = Data;
mbed_official 52:a51c77007319 233 }
mbed_official 52:a51c77007319 234
mbed_official 52:a51c77007319 235 /**
mbed_official 52:a51c77007319 236 * @brief Reads data from the specified Data Backup Register.
mbed_official 52:a51c77007319 237 * @param BKP_DR: specifies the Data Backup Register.
mbed_official 52:a51c77007319 238 * This parameter can be BKP_DRx where x:[1, 42]
mbed_official 52:a51c77007319 239 * @retval The content of the specified Data Backup Register
mbed_official 52:a51c77007319 240 */
mbed_official 52:a51c77007319 241 uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
mbed_official 52:a51c77007319 242 {
mbed_official 52:a51c77007319 243 __IO uint32_t tmp = 0;
mbed_official 52:a51c77007319 244
mbed_official 52:a51c77007319 245 /* Check the parameters */
mbed_official 52:a51c77007319 246 assert_param(IS_BKP_DR(BKP_DR));
mbed_official 52:a51c77007319 247
mbed_official 52:a51c77007319 248 tmp = (uint32_t)BKP_BASE;
mbed_official 52:a51c77007319 249 tmp += BKP_DR;
mbed_official 52:a51c77007319 250
mbed_official 52:a51c77007319 251 return (*(__IO uint16_t *) tmp);
mbed_official 52:a51c77007319 252 }
mbed_official 52:a51c77007319 253
mbed_official 52:a51c77007319 254 /**
mbed_official 52:a51c77007319 255 * @brief Checks whether the Tamper Pin Event flag is set or not.
mbed_official 52:a51c77007319 256 * @param None
mbed_official 52:a51c77007319 257 * @retval The new state of the Tamper Pin Event flag (SET or RESET).
mbed_official 52:a51c77007319 258 */
mbed_official 52:a51c77007319 259 FlagStatus BKP_GetFlagStatus(void)
mbed_official 52:a51c77007319 260 {
mbed_official 52:a51c77007319 261 return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
mbed_official 52:a51c77007319 262 }
mbed_official 52:a51c77007319 263
mbed_official 52:a51c77007319 264 /**
mbed_official 52:a51c77007319 265 * @brief Clears Tamper Pin Event pending flag.
mbed_official 52:a51c77007319 266 * @param None
mbed_official 52:a51c77007319 267 * @retval None
mbed_official 52:a51c77007319 268 */
mbed_official 52:a51c77007319 269 void BKP_ClearFlag(void)
mbed_official 52:a51c77007319 270 {
mbed_official 52:a51c77007319 271 /* Set CTE bit to clear Tamper Pin Event flag */
mbed_official 52:a51c77007319 272 BKP->CSR |= BKP_CSR_CTE;
mbed_official 52:a51c77007319 273 }
mbed_official 52:a51c77007319 274
mbed_official 52:a51c77007319 275 /**
mbed_official 52:a51c77007319 276 * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
mbed_official 52:a51c77007319 277 * @param None
mbed_official 52:a51c77007319 278 * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
mbed_official 52:a51c77007319 279 */
mbed_official 52:a51c77007319 280 ITStatus BKP_GetITStatus(void)
mbed_official 52:a51c77007319 281 {
mbed_official 52:a51c77007319 282 return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
mbed_official 52:a51c77007319 283 }
mbed_official 52:a51c77007319 284
mbed_official 52:a51c77007319 285 /**
mbed_official 52:a51c77007319 286 * @brief Clears Tamper Pin Interrupt pending bit.
mbed_official 52:a51c77007319 287 * @param None
mbed_official 52:a51c77007319 288 * @retval None
mbed_official 52:a51c77007319 289 */
mbed_official 52:a51c77007319 290 void BKP_ClearITPendingBit(void)
mbed_official 52:a51c77007319 291 {
mbed_official 52:a51c77007319 292 /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
mbed_official 52:a51c77007319 293 BKP->CSR |= BKP_CSR_CTI;
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
mbed_official 52:a51c77007319 308 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/