mbed library sources

Fork of mbed-src by mbed official

Committer:
todotani
Date:
Fri Sep 05 14:20:33 2014 +0000
Revision:
308:59cc78a25982
Parent:
157:90e3acc479a2
BLE_Health_Thermometer for mbed HRM1017 with BLE library 0.1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 157:90e3acc479a2 1 /**
mbed_official 157:90e3acc479a2 2 ******************************************************************************
mbed_official 157:90e3acc479a2 3 * @file stm32f30x_iwdg.c
mbed_official 157:90e3acc479a2 4 * @author MCD Application Team
mbed_official 157:90e3acc479a2 5 * @version V1.1.0
mbed_official 157:90e3acc479a2 6 * @date 27-February-2014
mbed_official 157:90e3acc479a2 7 * @brief This file provides firmware functions to manage the following
mbed_official 157:90e3acc479a2 8 * functionalities of the Independent watchdog (IWDG) peripheral:
mbed_official 157:90e3acc479a2 9 * + Prescaler and Counter configuration
mbed_official 157:90e3acc479a2 10 * + IWDG activation
mbed_official 157:90e3acc479a2 11 * + Flag management
mbed_official 157:90e3acc479a2 12 *
mbed_official 157:90e3acc479a2 13 @verbatim
mbed_official 157:90e3acc479a2 14
mbed_official 157:90e3acc479a2 15 ===============================================================================
mbed_official 157:90e3acc479a2 16 ##### IWDG features #####
mbed_official 157:90e3acc479a2 17 ===============================================================================
mbed_official 157:90e3acc479a2 18 [..] The IWDG can be started by either software or hardware (configurable
mbed_official 157:90e3acc479a2 19 through option byte).
mbed_official 157:90e3acc479a2 20 [..] The IWDG is clocked by its own dedicated low-speed clock (LSI) and
mbed_official 157:90e3acc479a2 21 thus stays active even if the main clock fails.
mbed_official 157:90e3acc479a2 22 Once the IWDG is started, the LSI is forced ON and cannot be disabled
mbed_official 157:90e3acc479a2 23 (LSI cannot be disabled too), and the counter starts counting down from
mbed_official 157:90e3acc479a2 24 the reset value of 0xFFF. When it reaches the end of count value (0x000)
mbed_official 157:90e3acc479a2 25 a system reset is generated.
mbed_official 157:90e3acc479a2 26 The IWDG counter should be reloaded at regular intervals to prevent
mbed_official 157:90e3acc479a2 27 an MCU reset.
mbed_official 157:90e3acc479a2 28 [..] The IWDG is implemented in the VDD voltage domain that is still functional
mbed_official 157:90e3acc479a2 29 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
mbed_official 157:90e3acc479a2 30 [..] IWDGRST flag in RCC_CSR register can be used to inform when a IWDG
mbed_official 157:90e3acc479a2 31 reset occurs.
mbed_official 157:90e3acc479a2 32 [..] Min-max timeout value @41KHz (LSI): ~0.1ms / ~25.5s
mbed_official 157:90e3acc479a2 33 The IWDG timeout may vary due to LSI frequency dispersion. STM32F30x
mbed_official 157:90e3acc479a2 34 devices provide the capability to measure the LSI frequency (LSI clock
mbed_official 157:90e3acc479a2 35 connected internally to TIM16 CH1 input capture). The measured value
mbed_official 157:90e3acc479a2 36 can be used to have an IWDG timeout with an acceptable accuracy.
mbed_official 157:90e3acc479a2 37 For more information, please refer to the STM32F30x Reference manual.
mbed_official 157:90e3acc479a2 38
mbed_official 157:90e3acc479a2 39 ##### How to use this driver #####
mbed_official 157:90e3acc479a2 40 ===============================================================================
mbed_official 157:90e3acc479a2 41 [..] This driver allows to use IWDG peripheral with either window option enabled
mbed_official 157:90e3acc479a2 42 or disabled. To do so follow one of the two procedures below.
mbed_official 157:90e3acc479a2 43 (#) Window option is enabled:
mbed_official 157:90e3acc479a2 44 (++) Start the IWDG using IWDG_Enable() function, when the IWDG is used
mbed_official 157:90e3acc479a2 45 in software mode (no need to enable the LSI, it will be enabled
mbed_official 157:90e3acc479a2 46 by hardware).
mbed_official 157:90e3acc479a2 47 (++) Enable write access to IWDG_PR and IWDG_RLR registers using
mbed_official 157:90e3acc479a2 48 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function.
mbed_official 157:90e3acc479a2 49 (++) Configure the IWDG prescaler using IWDG_SetPrescaler() function.
mbed_official 157:90e3acc479a2 50 (++) Configure the IWDG counter value using IWDG_SetReload() function.
mbed_official 157:90e3acc479a2 51 This value will be loaded in the IWDG counter each time the counter
mbed_official 157:90e3acc479a2 52 is reloaded, then the IWDG will start counting down from this value.
mbed_official 157:90e3acc479a2 53 (++) Wait for the IWDG registers to be updated using IWDG_GetFlagStatus() function.
mbed_official 157:90e3acc479a2 54 (++) Configure the IWDG refresh window using IWDG_SetWindowValue() function.
mbed_official 157:90e3acc479a2 55
mbed_official 157:90e3acc479a2 56 (#) Window option is disabled:
mbed_official 157:90e3acc479a2 57 (++) Enable write access to IWDG_PR and IWDG_RLR registers using
mbed_official 157:90e3acc479a2 58 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function.
mbed_official 157:90e3acc479a2 59 (++) Configure the IWDG prescaler using IWDG_SetPrescaler() function.
mbed_official 157:90e3acc479a2 60 (++) Configure the IWDG counter value using IWDG_SetReload() function.
mbed_official 157:90e3acc479a2 61 This value will be loaded in the IWDG counter each time the counter
mbed_official 157:90e3acc479a2 62 is reloaded, then the IWDG will start counting down from this value.
mbed_official 157:90e3acc479a2 63 (++) Wait for the IWDG registers to be updated using IWDG_GetFlagStatus() function.
mbed_official 157:90e3acc479a2 64 (++) reload the IWDG counter at regular intervals during normal operation
mbed_official 157:90e3acc479a2 65 to prevent an MCU reset, using IWDG_ReloadCounter() function.
mbed_official 157:90e3acc479a2 66 (++) Start the IWDG using IWDG_Enable() function, when the IWDG is used
mbed_official 157:90e3acc479a2 67 in software mode (no need to enable the LSI, it will be enabled
mbed_official 157:90e3acc479a2 68 by hardware).
mbed_official 157:90e3acc479a2 69
mbed_official 157:90e3acc479a2 70 @endverbatim
mbed_official 157:90e3acc479a2 71
mbed_official 157:90e3acc479a2 72 ******************************************************************************
mbed_official 157:90e3acc479a2 73 * @attention
mbed_official 157:90e3acc479a2 74 *
mbed_official 157:90e3acc479a2 75 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 157:90e3acc479a2 76 *
mbed_official 157:90e3acc479a2 77 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 157:90e3acc479a2 78 * are permitted provided that the following conditions are met:
mbed_official 157:90e3acc479a2 79 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 157:90e3acc479a2 80 * this list of conditions and the following disclaimer.
mbed_official 157:90e3acc479a2 81 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 157:90e3acc479a2 82 * this list of conditions and the following disclaimer in the documentation
mbed_official 157:90e3acc479a2 83 * and/or other materials provided with the distribution.
mbed_official 157:90e3acc479a2 84 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 157:90e3acc479a2 85 * may be used to endorse or promote products derived from this software
mbed_official 157:90e3acc479a2 86 * without specific prior written permission.
mbed_official 157:90e3acc479a2 87 *
mbed_official 157:90e3acc479a2 88 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 157:90e3acc479a2 89 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 157:90e3acc479a2 90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 157:90e3acc479a2 91 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 157:90e3acc479a2 92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 157:90e3acc479a2 93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 157:90e3acc479a2 94 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 157:90e3acc479a2 95 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 157:90e3acc479a2 96 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 157:90e3acc479a2 97 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 157:90e3acc479a2 98 *
mbed_official 157:90e3acc479a2 99 ******************************************************************************
mbed_official 157:90e3acc479a2 100 */
mbed_official 157:90e3acc479a2 101
mbed_official 157:90e3acc479a2 102 /* Includes ------------------------------------------------------------------*/
mbed_official 157:90e3acc479a2 103 #include "stm32f30x_iwdg.h"
mbed_official 157:90e3acc479a2 104
mbed_official 157:90e3acc479a2 105 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 157:90e3acc479a2 106 * @{
mbed_official 157:90e3acc479a2 107 */
mbed_official 157:90e3acc479a2 108
mbed_official 157:90e3acc479a2 109 /** @defgroup IWDG
mbed_official 157:90e3acc479a2 110 * @brief IWDG driver modules
mbed_official 157:90e3acc479a2 111 * @{
mbed_official 157:90e3acc479a2 112 */
mbed_official 157:90e3acc479a2 113
mbed_official 157:90e3acc479a2 114 /* Private typedef -----------------------------------------------------------*/
mbed_official 157:90e3acc479a2 115 /* Private define ------------------------------------------------------------*/
mbed_official 157:90e3acc479a2 116 /* ---------------------- IWDG registers bit mask ----------------------------*/
mbed_official 157:90e3acc479a2 117 /* KR register bit mask */
mbed_official 157:90e3acc479a2 118 #define KR_KEY_RELOAD ((uint16_t)0xAAAA)
mbed_official 157:90e3acc479a2 119 #define KR_KEY_ENABLE ((uint16_t)0xCCCC)
mbed_official 157:90e3acc479a2 120
mbed_official 157:90e3acc479a2 121 /* Private macro -------------------------------------------------------------*/
mbed_official 157:90e3acc479a2 122 /* Private variables ---------------------------------------------------------*/
mbed_official 157:90e3acc479a2 123 /* Private function prototypes -----------------------------------------------*/
mbed_official 157:90e3acc479a2 124 /* Private functions ---------------------------------------------------------*/
mbed_official 157:90e3acc479a2 125
mbed_official 157:90e3acc479a2 126 /** @defgroup IWDG_Private_Functions
mbed_official 157:90e3acc479a2 127 * @{
mbed_official 157:90e3acc479a2 128 */
mbed_official 157:90e3acc479a2 129
mbed_official 157:90e3acc479a2 130 /** @defgroup IWDG_Group1 Prescaler and Counter configuration functions
mbed_official 157:90e3acc479a2 131 * @brief Prescaler and Counter configuration functions
mbed_official 157:90e3acc479a2 132 *
mbed_official 157:90e3acc479a2 133 @verbatim
mbed_official 157:90e3acc479a2 134 ===============================================================================
mbed_official 157:90e3acc479a2 135 ##### Prescaler and Counter configuration functions #####
mbed_official 157:90e3acc479a2 136 ===============================================================================
mbed_official 157:90e3acc479a2 137
mbed_official 157:90e3acc479a2 138 @endverbatim
mbed_official 157:90e3acc479a2 139 * @{
mbed_official 157:90e3acc479a2 140 */
mbed_official 157:90e3acc479a2 141
mbed_official 157:90e3acc479a2 142 /**
mbed_official 157:90e3acc479a2 143 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
mbed_official 157:90e3acc479a2 144 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
mbed_official 157:90e3acc479a2 145 * This parameter can be one of the following values:
mbed_official 157:90e3acc479a2 146 * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
mbed_official 157:90e3acc479a2 147 * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
mbed_official 157:90e3acc479a2 148 * @retval None
mbed_official 157:90e3acc479a2 149 */
mbed_official 157:90e3acc479a2 150 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
mbed_official 157:90e3acc479a2 151 {
mbed_official 157:90e3acc479a2 152 /* Check the parameters */
mbed_official 157:90e3acc479a2 153 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
mbed_official 157:90e3acc479a2 154 IWDG->KR = IWDG_WriteAccess;
mbed_official 157:90e3acc479a2 155 }
mbed_official 157:90e3acc479a2 156
mbed_official 157:90e3acc479a2 157 /**
mbed_official 157:90e3acc479a2 158 * @brief Sets IWDG Prescaler value.
mbed_official 157:90e3acc479a2 159 * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
mbed_official 157:90e3acc479a2 160 * This parameter can be one of the following values:
mbed_official 157:90e3acc479a2 161 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
mbed_official 157:90e3acc479a2 162 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
mbed_official 157:90e3acc479a2 163 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
mbed_official 157:90e3acc479a2 164 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
mbed_official 157:90e3acc479a2 165 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
mbed_official 157:90e3acc479a2 166 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
mbed_official 157:90e3acc479a2 167 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
mbed_official 157:90e3acc479a2 168 * @retval None
mbed_official 157:90e3acc479a2 169 */
mbed_official 157:90e3acc479a2 170 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
mbed_official 157:90e3acc479a2 171 {
mbed_official 157:90e3acc479a2 172 /* Check the parameters */
mbed_official 157:90e3acc479a2 173 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
mbed_official 157:90e3acc479a2 174 IWDG->PR = IWDG_Prescaler;
mbed_official 157:90e3acc479a2 175 }
mbed_official 157:90e3acc479a2 176
mbed_official 157:90e3acc479a2 177 /**
mbed_official 157:90e3acc479a2 178 * @brief Sets IWDG Reload value.
mbed_official 157:90e3acc479a2 179 * @param Reload: specifies the IWDG Reload value.
mbed_official 157:90e3acc479a2 180 * This parameter must be a number between 0 and 0x0FFF.
mbed_official 157:90e3acc479a2 181 * @retval None
mbed_official 157:90e3acc479a2 182 */
mbed_official 157:90e3acc479a2 183 void IWDG_SetReload(uint16_t Reload)
mbed_official 157:90e3acc479a2 184 {
mbed_official 157:90e3acc479a2 185 /* Check the parameters */
mbed_official 157:90e3acc479a2 186 assert_param(IS_IWDG_RELOAD(Reload));
mbed_official 157:90e3acc479a2 187 IWDG->RLR = Reload;
mbed_official 157:90e3acc479a2 188 }
mbed_official 157:90e3acc479a2 189
mbed_official 157:90e3acc479a2 190 /**
mbed_official 157:90e3acc479a2 191 * @brief Reloads IWDG counter with value defined in the reload register
mbed_official 157:90e3acc479a2 192 * (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 157:90e3acc479a2 193 * @param None
mbed_official 157:90e3acc479a2 194 * @retval None
mbed_official 157:90e3acc479a2 195 */
mbed_official 157:90e3acc479a2 196 void IWDG_ReloadCounter(void)
mbed_official 157:90e3acc479a2 197 {
mbed_official 157:90e3acc479a2 198 IWDG->KR = KR_KEY_RELOAD;
mbed_official 157:90e3acc479a2 199 }
mbed_official 157:90e3acc479a2 200
mbed_official 157:90e3acc479a2 201
mbed_official 157:90e3acc479a2 202 /**
mbed_official 157:90e3acc479a2 203 * @brief Sets the IWDG window value.
mbed_official 157:90e3acc479a2 204 * @param WindowValue: specifies the window value to be compared to the downcounter.
mbed_official 157:90e3acc479a2 205 * @retval None
mbed_official 157:90e3acc479a2 206 */
mbed_official 157:90e3acc479a2 207 void IWDG_SetWindowValue(uint16_t WindowValue)
mbed_official 157:90e3acc479a2 208 {
mbed_official 157:90e3acc479a2 209 /* Check the parameters */
mbed_official 157:90e3acc479a2 210 assert_param(IS_IWDG_WINDOW_VALUE(WindowValue));
mbed_official 157:90e3acc479a2 211 IWDG->WINR = WindowValue;
mbed_official 157:90e3acc479a2 212 }
mbed_official 157:90e3acc479a2 213
mbed_official 157:90e3acc479a2 214 /**
mbed_official 157:90e3acc479a2 215 * @}
mbed_official 157:90e3acc479a2 216 */
mbed_official 157:90e3acc479a2 217
mbed_official 157:90e3acc479a2 218 /** @defgroup IWDG_Group2 IWDG activation function
mbed_official 157:90e3acc479a2 219 * @brief IWDG activation function
mbed_official 157:90e3acc479a2 220 *
mbed_official 157:90e3acc479a2 221 @verbatim
mbed_official 157:90e3acc479a2 222 ===============================================================================
mbed_official 157:90e3acc479a2 223 ##### IWDG activation function #####
mbed_official 157:90e3acc479a2 224 ===============================================================================
mbed_official 157:90e3acc479a2 225
mbed_official 157:90e3acc479a2 226 @endverbatim
mbed_official 157:90e3acc479a2 227 * @{
mbed_official 157:90e3acc479a2 228 */
mbed_official 157:90e3acc479a2 229
mbed_official 157:90e3acc479a2 230 /**
mbed_official 157:90e3acc479a2 231 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 157:90e3acc479a2 232 * @param None
mbed_official 157:90e3acc479a2 233 * @retval None
mbed_official 157:90e3acc479a2 234 */
mbed_official 157:90e3acc479a2 235 void IWDG_Enable(void)
mbed_official 157:90e3acc479a2 236 {
mbed_official 157:90e3acc479a2 237 IWDG->KR = KR_KEY_ENABLE;
mbed_official 157:90e3acc479a2 238 }
mbed_official 157:90e3acc479a2 239
mbed_official 157:90e3acc479a2 240 /**
mbed_official 157:90e3acc479a2 241 * @}
mbed_official 157:90e3acc479a2 242 */
mbed_official 157:90e3acc479a2 243
mbed_official 157:90e3acc479a2 244 /** @defgroup IWDG_Group3 Flag management function
mbed_official 157:90e3acc479a2 245 * @brief Flag management function
mbed_official 157:90e3acc479a2 246 *
mbed_official 157:90e3acc479a2 247 @verbatim
mbed_official 157:90e3acc479a2 248 ===============================================================================
mbed_official 157:90e3acc479a2 249 ##### Flag management function #####
mbed_official 157:90e3acc479a2 250 ===============================================================================
mbed_official 157:90e3acc479a2 251
mbed_official 157:90e3acc479a2 252 @endverbatim
mbed_official 157:90e3acc479a2 253 * @{
mbed_official 157:90e3acc479a2 254 */
mbed_official 157:90e3acc479a2 255
mbed_official 157:90e3acc479a2 256 /**
mbed_official 157:90e3acc479a2 257 * @brief Checks whether the specified IWDG flag is set or not.
mbed_official 157:90e3acc479a2 258 * @param IWDG_FLAG: specifies the flag to check.
mbed_official 157:90e3acc479a2 259 * This parameter can be one of the following values:
mbed_official 157:90e3acc479a2 260 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
mbed_official 157:90e3acc479a2 261 * @arg IWDG_FLAG_RVU: Reload Value Update on going
mbed_official 157:90e3acc479a2 262 * @arg IWDG_FLAG_WVU: Counter Window Value Update on going
mbed_official 157:90e3acc479a2 263 * @retval The new state of IWDG_FLAG (SET or RESET).
mbed_official 157:90e3acc479a2 264 */
mbed_official 157:90e3acc479a2 265 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
mbed_official 157:90e3acc479a2 266 {
mbed_official 157:90e3acc479a2 267 FlagStatus bitstatus = RESET;
mbed_official 157:90e3acc479a2 268 /* Check the parameters */
mbed_official 157:90e3acc479a2 269 assert_param(IS_IWDG_FLAG(IWDG_FLAG));
mbed_official 157:90e3acc479a2 270 if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
mbed_official 157:90e3acc479a2 271 {
mbed_official 157:90e3acc479a2 272 bitstatus = SET;
mbed_official 157:90e3acc479a2 273 }
mbed_official 157:90e3acc479a2 274 else
mbed_official 157:90e3acc479a2 275 {
mbed_official 157:90e3acc479a2 276 bitstatus = RESET;
mbed_official 157:90e3acc479a2 277 }
mbed_official 157:90e3acc479a2 278 /* Return the flag status */
mbed_official 157:90e3acc479a2 279 return bitstatus;
mbed_official 157:90e3acc479a2 280 }
mbed_official 157:90e3acc479a2 281
mbed_official 157:90e3acc479a2 282 /**
mbed_official 157:90e3acc479a2 283 * @}
mbed_official 157:90e3acc479a2 284 */
mbed_official 157:90e3acc479a2 285
mbed_official 157:90e3acc479a2 286 /**
mbed_official 157:90e3acc479a2 287 * @}
mbed_official 157:90e3acc479a2 288 */
mbed_official 157:90e3acc479a2 289
mbed_official 157:90e3acc479a2 290 /**
mbed_official 157:90e3acc479a2 291 * @}
mbed_official 157:90e3acc479a2 292 */
mbed_official 157:90e3acc479a2 293
mbed_official 157:90e3acc479a2 294 /**
mbed_official 157:90e3acc479a2 295 * @}
mbed_official 157:90e3acc479a2 296 */
mbed_official 157:90e3acc479a2 297
mbed_official 157:90e3acc479a2 298 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/