mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Oct 09 08:15:07 2014 +0100
Revision:
340:28d1f895c6fe
Synchronized with git revision b5a4c8e80393336b2656fb29ab46d405d3068602

Full URL: https://github.com/mbedmicro/mbed/commit/b5a4c8e80393336b2656fb29ab46d405d3068602/

HAL: nrf51822 - Few fixes for PWM and Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 340:28d1f895c6fe 1 /**
mbed_official 340:28d1f895c6fe 2 ******************************************************************************
mbed_official 340:28d1f895c6fe 3 * @file stm32f0xx_hal_iwdg.c
mbed_official 340:28d1f895c6fe 4 * @author MCD Application Team
mbed_official 340:28d1f895c6fe 5 * @version V1.1.0
mbed_official 340:28d1f895c6fe 6 * @date 03-Oct-2014
mbed_official 340:28d1f895c6fe 7 * @brief IWDG HAL module driver.
mbed_official 340:28d1f895c6fe 8 * This file provides firmware functions to manage the following
mbed_official 340:28d1f895c6fe 9 * functionalities of the IWDG peripheral:
mbed_official 340:28d1f895c6fe 10 * + Initialization and Configuration functions
mbed_official 340:28d1f895c6fe 11 * + IO operation functions
mbed_official 340:28d1f895c6fe 12 * + Peripheral State functions
mbed_official 340:28d1f895c6fe 13 *
mbed_official 340:28d1f895c6fe 14 @verbatim
mbed_official 340:28d1f895c6fe 15 ===============================================================================
mbed_official 340:28d1f895c6fe 16 ##### IWDG Specific features #####
mbed_official 340:28d1f895c6fe 17 ===============================================================================
mbed_official 340:28d1f895c6fe 18 [..]
mbed_official 340:28d1f895c6fe 19 (+) The IWDG can be started by either software or hardware (configurable
mbed_official 340:28d1f895c6fe 20 through option byte).
mbed_official 340:28d1f895c6fe 21 (+) The IWDG is clocked by its own dedicated Low-Speed clock (LSI) and
mbed_official 340:28d1f895c6fe 22 thus stays active even if the main clock fails.
mbed_official 340:28d1f895c6fe 23 (+) Once the IWDG is started, the LSI is forced ON and cannot be disabled
mbed_official 340:28d1f895c6fe 24 (LSI cannot be disabled too), and the counter starts counting down from
mbed_official 340:28d1f895c6fe 25 the reset value of 0xFFF. When it reaches the end of count value (0x000)
mbed_official 340:28d1f895c6fe 26 a system reset is generated.
mbed_official 340:28d1f895c6fe 27 (+) The IWDG counter should be refreshed at regular intervals, otherwise the
mbed_official 340:28d1f895c6fe 28 watchdog generates an MCU reset when the counter reaches 0.
mbed_official 340:28d1f895c6fe 29 (+) The IWDG is implemented in the VDD voltage domain that is still functional
mbed_official 340:28d1f895c6fe 30 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
mbed_official 340:28d1f895c6fe 31 (+) IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
mbed_official 340:28d1f895c6fe 32 reset occurs.
mbed_official 340:28d1f895c6fe 33 (+) Min-max timeout value @41KHz (LSI): ~0.1ms / ~25.5s
mbed_official 340:28d1f895c6fe 34 The IWDG timeout may vary due to LSI frequency dispersion. STM32F0x
mbed_official 340:28d1f895c6fe 35 devices provide the capability to measure the LSI frequency (LSI clock
mbed_official 340:28d1f895c6fe 36 connected internally to TIM16 CH1 input capture). The measured value
mbed_official 340:28d1f895c6fe 37 can be used to have an IWDG timeout with an acceptable accuracy.
mbed_official 340:28d1f895c6fe 38 For more information, please refer to the STM32F0x Reference manual.
mbed_official 340:28d1f895c6fe 39
mbed_official 340:28d1f895c6fe 40 ===============================================================================
mbed_official 340:28d1f895c6fe 41 ##### How to use this driver #####
mbed_official 340:28d1f895c6fe 42 ===============================================================================
mbed_official 340:28d1f895c6fe 43 [..]
mbed_official 340:28d1f895c6fe 44 (#) if Window option is disabled
mbed_official 340:28d1f895c6fe 45 (++) Use IWDG using HAL_IWDG_Init() function to :
mbed_official 340:28d1f895c6fe 46 (+++) Enable write access to IWDG_PR, IWDG_RLR.
mbed_official 340:28d1f895c6fe 47 (+++) Configure the IWDG prescaler, counter reload value.
mbed_official 340:28d1f895c6fe 48 This reload value will be loaded in the IWDG counter each time the counter
mbed_official 340:28d1f895c6fe 49 is reloaded, then the IWDG will start counting down from this value.
mbed_official 340:28d1f895c6fe 50 (++) Use IWDG using HAL_IWDG_Start() function to :
mbed_official 340:28d1f895c6fe 51 (+++) Reload IWDG counter with value defined in the IWDG_RLR register.
mbed_official 340:28d1f895c6fe 52 (+++) Start the IWDG, when the IWDG is used in software mode (no need
mbed_official 340:28d1f895c6fe 53 to enable the LSI, it will be enabled by hardware).
mbed_official 340:28d1f895c6fe 54 (++) Then the application program must refresh the IWDG counter at regular
mbed_official 340:28d1f895c6fe 55 intervals during normal operation to prevent an MCU reset, using
mbed_official 340:28d1f895c6fe 56 HAL_IWDG_Refresh() function.
mbed_official 340:28d1f895c6fe 57 (#) if Window option is enabled:
mbed_official 340:28d1f895c6fe 58 (++) Use IWDG using HAL_IWDG_Start() function to enable IWDG downcounter
mbed_official 340:28d1f895c6fe 59 (++) Use IWDG using HAL_IWDG_Init() function to :
mbed_official 340:28d1f895c6fe 60 (+++) Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
mbed_official 340:28d1f895c6fe 61 (+++) Configure the IWDG prescaler, reload value and window value.
mbed_official 340:28d1f895c6fe 62 (++) Then the application program must refresh the IWDG counter at regular
mbed_official 340:28d1f895c6fe 63 intervals during normal operation to prevent an MCU reset, using
mbed_official 340:28d1f895c6fe 64 HAL_IWDG_Refresh() function.
mbed_official 340:28d1f895c6fe 65
mbed_official 340:28d1f895c6fe 66 *** IWDG HAL driver macros list ***
mbed_official 340:28d1f895c6fe 67 ====================================
mbed_official 340:28d1f895c6fe 68 [..]
mbed_official 340:28d1f895c6fe 69 Below the list of most used macros in IWDG HAL driver.
mbed_official 340:28d1f895c6fe 70
mbed_official 340:28d1f895c6fe 71 (+) __HAL_IWDG_START: Enable the IWDG peripheral
mbed_official 340:28d1f895c6fe 72 (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in the reload register
mbed_official 340:28d1f895c6fe 73 (+) __HAL_IWDG_ENABLE_WRITE_ACCESS : Enable write access to IWDG_PR and IWDG_RLR registers
mbed_official 340:28d1f895c6fe 74 (+) __HAL_IWDG_DISABLE_WRITE_ACCESS : Disable write access to IWDG_PR and IWDG_RLR registers
mbed_official 340:28d1f895c6fe 75 (+) __HAL_IWDG_GET_FLAG: Get the selected IWDG's flag status
mbed_official 340:28d1f895c6fe 76
mbed_official 340:28d1f895c6fe 77 @endverbatim
mbed_official 340:28d1f895c6fe 78 ******************************************************************************
mbed_official 340:28d1f895c6fe 79 * @attention
mbed_official 340:28d1f895c6fe 80 *
mbed_official 340:28d1f895c6fe 81 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 340:28d1f895c6fe 82 *
mbed_official 340:28d1f895c6fe 83 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 340:28d1f895c6fe 84 * are permitted provided that the following conditions are met:
mbed_official 340:28d1f895c6fe 85 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 340:28d1f895c6fe 86 * this list of conditions and the following disclaimer.
mbed_official 340:28d1f895c6fe 87 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 340:28d1f895c6fe 88 * this list of conditions and the following disclaimer in the documentation
mbed_official 340:28d1f895c6fe 89 * and/or other materials provided with the distribution.
mbed_official 340:28d1f895c6fe 90 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 340:28d1f895c6fe 91 * may be used to endorse or promote products derived from this software
mbed_official 340:28d1f895c6fe 92 * without specific prior written permission.
mbed_official 340:28d1f895c6fe 93 *
mbed_official 340:28d1f895c6fe 94 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 340:28d1f895c6fe 95 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 340:28d1f895c6fe 96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 340:28d1f895c6fe 97 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 340:28d1f895c6fe 98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 340:28d1f895c6fe 99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 340:28d1f895c6fe 100 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 340:28d1f895c6fe 101 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 340:28d1f895c6fe 102 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 340:28d1f895c6fe 103 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 340:28d1f895c6fe 104 *
mbed_official 340:28d1f895c6fe 105 ******************************************************************************
mbed_official 340:28d1f895c6fe 106 */
mbed_official 340:28d1f895c6fe 107
mbed_official 340:28d1f895c6fe 108 /* Includes ------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 109 #include "stm32f0xx_hal.h"
mbed_official 340:28d1f895c6fe 110
mbed_official 340:28d1f895c6fe 111 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 340:28d1f895c6fe 112 * @{
mbed_official 340:28d1f895c6fe 113 */
mbed_official 340:28d1f895c6fe 114
mbed_official 340:28d1f895c6fe 115 /** @defgroup IWDG IWDG HAL module driver
mbed_official 340:28d1f895c6fe 116 * @brief IWDG HAL module driver.
mbed_official 340:28d1f895c6fe 117 * @{
mbed_official 340:28d1f895c6fe 118 */
mbed_official 340:28d1f895c6fe 119
mbed_official 340:28d1f895c6fe 120 #ifdef HAL_IWDG_MODULE_ENABLED
mbed_official 340:28d1f895c6fe 121
mbed_official 340:28d1f895c6fe 122 /* Private typedef -----------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 123 /* Private define ------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 124
mbed_official 340:28d1f895c6fe 125 /** @defgroup IWDG_Private_Defines IWDG Private Defines
mbed_official 340:28d1f895c6fe 126 * @{
mbed_official 340:28d1f895c6fe 127 */
mbed_official 340:28d1f895c6fe 128
mbed_official 340:28d1f895c6fe 129 #define HAL_IWDG_DEFAULT_TIMEOUT (uint32_t)1000
mbed_official 340:28d1f895c6fe 130
mbed_official 340:28d1f895c6fe 131 /**
mbed_official 340:28d1f895c6fe 132 * @}
mbed_official 340:28d1f895c6fe 133 */
mbed_official 340:28d1f895c6fe 134
mbed_official 340:28d1f895c6fe 135 /* Private macro -------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 136 /* Private variables ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 137 /* Private function prototypes -----------------------------------------------*/
mbed_official 340:28d1f895c6fe 138 /* Private functions ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 139
mbed_official 340:28d1f895c6fe 140 /** @defgroup IWDG_Exported_Functions IWDG Exported Functions
mbed_official 340:28d1f895c6fe 141 * @{
mbed_official 340:28d1f895c6fe 142 */
mbed_official 340:28d1f895c6fe 143
mbed_official 340:28d1f895c6fe 144 /** @defgroup IWDG_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 340:28d1f895c6fe 145 * @brief Initialization and Configuration functions.
mbed_official 340:28d1f895c6fe 146 *
mbed_official 340:28d1f895c6fe 147 @verbatim
mbed_official 340:28d1f895c6fe 148 ===============================================================================
mbed_official 340:28d1f895c6fe 149 ##### Initialization functions #####
mbed_official 340:28d1f895c6fe 150 ===============================================================================
mbed_official 340:28d1f895c6fe 151 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 152 (+) Initialize the IWDG according to the specified parameters
mbed_official 340:28d1f895c6fe 153 in the IWDG_InitTypeDef and create the associated handle
mbed_official 340:28d1f895c6fe 154 (+) Manage Window option
mbed_official 340:28d1f895c6fe 155 (+) Initialize the IWDG MSP
mbed_official 340:28d1f895c6fe 156 (+) DeInitialize IWDG MSP
mbed_official 340:28d1f895c6fe 157
mbed_official 340:28d1f895c6fe 158 @endverbatim
mbed_official 340:28d1f895c6fe 159 * @{
mbed_official 340:28d1f895c6fe 160 */
mbed_official 340:28d1f895c6fe 161
mbed_official 340:28d1f895c6fe 162 /**
mbed_official 340:28d1f895c6fe 163 * @brief Initializes the IWDG according to the specified
mbed_official 340:28d1f895c6fe 164 * parameters in the IWDG_InitTypeDef and creates the associated handle.
mbed_official 340:28d1f895c6fe 165 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 166 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 167 * @retval HAL status
mbed_official 340:28d1f895c6fe 168 */
mbed_official 340:28d1f895c6fe 169 HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 170 {
mbed_official 340:28d1f895c6fe 171 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 172
mbed_official 340:28d1f895c6fe 173 /* Check the IWDG handle allocation */
mbed_official 340:28d1f895c6fe 174 if(hiwdg == HAL_NULL)
mbed_official 340:28d1f895c6fe 175 {
mbed_official 340:28d1f895c6fe 176 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 177 }
mbed_official 340:28d1f895c6fe 178
mbed_official 340:28d1f895c6fe 179 /* Check the parameters */
mbed_official 340:28d1f895c6fe 180 assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
mbed_official 340:28d1f895c6fe 181 assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
mbed_official 340:28d1f895c6fe 182 assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
mbed_official 340:28d1f895c6fe 183 assert_param(IS_IWDG_WINDOW(hiwdg->Init.Window));
mbed_official 340:28d1f895c6fe 184
mbed_official 340:28d1f895c6fe 185 /* Check pending flag, if previous update not done, return error */
mbed_official 340:28d1f895c6fe 186 if((__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_PVU) != RESET)
mbed_official 340:28d1f895c6fe 187 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 188 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_WVU) != RESET))
mbed_official 340:28d1f895c6fe 189 {
mbed_official 340:28d1f895c6fe 190 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 191 }
mbed_official 340:28d1f895c6fe 192
mbed_official 340:28d1f895c6fe 193 if(hiwdg->State == HAL_IWDG_STATE_RESET)
mbed_official 340:28d1f895c6fe 194 {
mbed_official 340:28d1f895c6fe 195 /* Init the low level hardware */
mbed_official 340:28d1f895c6fe 196 HAL_IWDG_MspInit(hiwdg);
mbed_official 340:28d1f895c6fe 197 }
mbed_official 340:28d1f895c6fe 198
mbed_official 340:28d1f895c6fe 199 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 200 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 201
mbed_official 340:28d1f895c6fe 202 /* Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers */
mbed_official 340:28d1f895c6fe 203 /* by writing 0x5555 in KR */
mbed_official 340:28d1f895c6fe 204 __HAL_IWDG_ENABLE_WRITE_ACCESS(hiwdg);
mbed_official 340:28d1f895c6fe 205
mbed_official 340:28d1f895c6fe 206 /* Write to IWDG registers the IWDG_Prescaler & IWDG_Reload values to work with */
mbed_official 340:28d1f895c6fe 207 MODIFY_REG(hiwdg->Instance->PR, IWDG_PR_PR, hiwdg->Init.Prescaler);
mbed_official 340:28d1f895c6fe 208 MODIFY_REG(hiwdg->Instance->RLR, IWDG_RLR_RL, hiwdg->Init.Reload);
mbed_official 340:28d1f895c6fe 209
mbed_official 340:28d1f895c6fe 210 /* check if window option is enabled */
mbed_official 340:28d1f895c6fe 211 if (((hiwdg->Init.Window) != IWDG_WINDOW_DISABLE) || ((hiwdg->Instance->WINR) != IWDG_WINDOW_DISABLE))
mbed_official 340:28d1f895c6fe 212 {
mbed_official 340:28d1f895c6fe 213 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 214
mbed_official 340:28d1f895c6fe 215 /* Wait for register to be updated */
mbed_official 340:28d1f895c6fe 216 while((uint32_t)(hiwdg->Instance->SR) != RESET)
mbed_official 340:28d1f895c6fe 217 {
mbed_official 340:28d1f895c6fe 218 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 219 {
mbed_official 340:28d1f895c6fe 220 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 221 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 222 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 223 }
mbed_official 340:28d1f895c6fe 224 }
mbed_official 340:28d1f895c6fe 225
mbed_official 340:28d1f895c6fe 226 /* Write to IWDG WINR the IWDG_Window value to compare with */
mbed_official 340:28d1f895c6fe 227 MODIFY_REG(hiwdg->Instance->WINR, IWDG_WINR_WIN, hiwdg->Init.Window);
mbed_official 340:28d1f895c6fe 228
mbed_official 340:28d1f895c6fe 229 }
mbed_official 340:28d1f895c6fe 230 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 231 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 232
mbed_official 340:28d1f895c6fe 233 /* Return function status */
mbed_official 340:28d1f895c6fe 234 return HAL_OK;
mbed_official 340:28d1f895c6fe 235 }
mbed_official 340:28d1f895c6fe 236
mbed_official 340:28d1f895c6fe 237 /**
mbed_official 340:28d1f895c6fe 238 * @brief Initializes the IWDG MSP.
mbed_official 340:28d1f895c6fe 239 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 240 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 241 * @retval None
mbed_official 340:28d1f895c6fe 242 */
mbed_official 340:28d1f895c6fe 243 __weak void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 244 {
mbed_official 340:28d1f895c6fe 245 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 246 the HAL_IWDG_MspInit could be implemented in the user file
mbed_official 340:28d1f895c6fe 247 */
mbed_official 340:28d1f895c6fe 248 }
mbed_official 340:28d1f895c6fe 249
mbed_official 340:28d1f895c6fe 250 /**
mbed_official 340:28d1f895c6fe 251 * @}
mbed_official 340:28d1f895c6fe 252 */
mbed_official 340:28d1f895c6fe 253
mbed_official 340:28d1f895c6fe 254 /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
mbed_official 340:28d1f895c6fe 255 * @brief IO operation functions
mbed_official 340:28d1f895c6fe 256 *
mbed_official 340:28d1f895c6fe 257 @verbatim
mbed_official 340:28d1f895c6fe 258 ===============================================================================
mbed_official 340:28d1f895c6fe 259 ##### IO operation functions #####
mbed_official 340:28d1f895c6fe 260 ===============================================================================
mbed_official 340:28d1f895c6fe 261 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 262 (+) Start the IWDG.
mbed_official 340:28d1f895c6fe 263 (+) Refresh the IWDG.
mbed_official 340:28d1f895c6fe 264
mbed_official 340:28d1f895c6fe 265 @endverbatim
mbed_official 340:28d1f895c6fe 266 * @{
mbed_official 340:28d1f895c6fe 267 */
mbed_official 340:28d1f895c6fe 268
mbed_official 340:28d1f895c6fe 269 /**
mbed_official 340:28d1f895c6fe 270 * @brief Starts the IWDG.
mbed_official 340:28d1f895c6fe 271 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 272 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 273 * @retval HAL status
mbed_official 340:28d1f895c6fe 274 */
mbed_official 340:28d1f895c6fe 275 HAL_StatusTypeDef HAL_IWDG_Start(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 276 {
mbed_official 340:28d1f895c6fe 277 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 278
mbed_official 340:28d1f895c6fe 279 /* Process Locked */
mbed_official 340:28d1f895c6fe 280 __HAL_LOCK(hiwdg);
mbed_official 340:28d1f895c6fe 281
mbed_official 340:28d1f895c6fe 282 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 283 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 284
mbed_official 340:28d1f895c6fe 285 /* Reload IWDG counter with value defined in the RLR register */
mbed_official 340:28d1f895c6fe 286 if ((hiwdg->Init.Window) == IWDG_WINDOW_DISABLE)
mbed_official 340:28d1f895c6fe 287 {
mbed_official 340:28d1f895c6fe 288 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
mbed_official 340:28d1f895c6fe 289 }
mbed_official 340:28d1f895c6fe 290
mbed_official 340:28d1f895c6fe 291 /* Enable the IWDG peripheral */
mbed_official 340:28d1f895c6fe 292 __HAL_IWDG_START(hiwdg);
mbed_official 340:28d1f895c6fe 293
mbed_official 340:28d1f895c6fe 294 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 295
mbed_official 340:28d1f895c6fe 296 /* Wait until PVU, RVU, WVU flag are RESET */
mbed_official 340:28d1f895c6fe 297 while( (__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_PVU) != RESET)
mbed_official 340:28d1f895c6fe 298 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 299 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_WVU) != RESET) )
mbed_official 340:28d1f895c6fe 300 {
mbed_official 340:28d1f895c6fe 301 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 302 {
mbed_official 340:28d1f895c6fe 303 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 304 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 305
mbed_official 340:28d1f895c6fe 306 /* Process unlocked */
mbed_official 340:28d1f895c6fe 307 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 308
mbed_official 340:28d1f895c6fe 309 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 310 }
mbed_official 340:28d1f895c6fe 311 }
mbed_official 340:28d1f895c6fe 312
mbed_official 340:28d1f895c6fe 313 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 314 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 315
mbed_official 340:28d1f895c6fe 316 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 317 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 318
mbed_official 340:28d1f895c6fe 319 /* Return function status */
mbed_official 340:28d1f895c6fe 320 return HAL_OK;
mbed_official 340:28d1f895c6fe 321 }
mbed_official 340:28d1f895c6fe 322
mbed_official 340:28d1f895c6fe 323 /**
mbed_official 340:28d1f895c6fe 324 * @brief Refreshes the IWDG.
mbed_official 340:28d1f895c6fe 325 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 326 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 327 * @retval HAL status
mbed_official 340:28d1f895c6fe 328 */
mbed_official 340:28d1f895c6fe 329 HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 330 {
mbed_official 340:28d1f895c6fe 331 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 332
mbed_official 340:28d1f895c6fe 333 /* Process Locked */
mbed_official 340:28d1f895c6fe 334 __HAL_LOCK(hiwdg);
mbed_official 340:28d1f895c6fe 335
mbed_official 340:28d1f895c6fe 336 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 337 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 338
mbed_official 340:28d1f895c6fe 339 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 340
mbed_official 340:28d1f895c6fe 341 /* Wait until RVU flag is RESET */
mbed_official 340:28d1f895c6fe 342 while(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 343 {
mbed_official 340:28d1f895c6fe 344 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 345 {
mbed_official 340:28d1f895c6fe 346 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 347 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 348
mbed_official 340:28d1f895c6fe 349 /* Process unlocked */
mbed_official 340:28d1f895c6fe 350 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 351
mbed_official 340:28d1f895c6fe 352 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 353 }
mbed_official 340:28d1f895c6fe 354 }
mbed_official 340:28d1f895c6fe 355
mbed_official 340:28d1f895c6fe 356 /* Reload IWDG counter with value defined in the reload register */
mbed_official 340:28d1f895c6fe 357 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
mbed_official 340:28d1f895c6fe 358
mbed_official 340:28d1f895c6fe 359 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 360 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 361
mbed_official 340:28d1f895c6fe 362 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 363 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 364
mbed_official 340:28d1f895c6fe 365 /* Return function status */
mbed_official 340:28d1f895c6fe 366 return HAL_OK;
mbed_official 340:28d1f895c6fe 367 }
mbed_official 340:28d1f895c6fe 368
mbed_official 340:28d1f895c6fe 369 /**
mbed_official 340:28d1f895c6fe 370 * @}
mbed_official 340:28d1f895c6fe 371 */
mbed_official 340:28d1f895c6fe 372
mbed_official 340:28d1f895c6fe 373 /** @defgroup IWDG_Exported_Functions_Group3 Peripheral State functions
mbed_official 340:28d1f895c6fe 374 * @brief Peripheral State functions.
mbed_official 340:28d1f895c6fe 375 *
mbed_official 340:28d1f895c6fe 376 @verbatim
mbed_official 340:28d1f895c6fe 377 ===============================================================================
mbed_official 340:28d1f895c6fe 378 ##### Peripheral State functions #####
mbed_official 340:28d1f895c6fe 379 ===============================================================================
mbed_official 340:28d1f895c6fe 380 [..]
mbed_official 340:28d1f895c6fe 381 This subsection permits to get in run-time the status of the peripheral
mbed_official 340:28d1f895c6fe 382 and the data flow.
mbed_official 340:28d1f895c6fe 383
mbed_official 340:28d1f895c6fe 384 @endverbatim
mbed_official 340:28d1f895c6fe 385 * @{
mbed_official 340:28d1f895c6fe 386 */
mbed_official 340:28d1f895c6fe 387
mbed_official 340:28d1f895c6fe 388 /**
mbed_official 340:28d1f895c6fe 389 * @brief Returns the IWDG state.
mbed_official 340:28d1f895c6fe 390 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 391 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 392 * @retval HAL state
mbed_official 340:28d1f895c6fe 393 */
mbed_official 340:28d1f895c6fe 394 HAL_IWDG_StateTypeDef HAL_IWDG_GetState(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 395 {
mbed_official 340:28d1f895c6fe 396 return hiwdg->State;
mbed_official 340:28d1f895c6fe 397 }
mbed_official 340:28d1f895c6fe 398
mbed_official 340:28d1f895c6fe 399 /**
mbed_official 340:28d1f895c6fe 400 * @}
mbed_official 340:28d1f895c6fe 401 */
mbed_official 340:28d1f895c6fe 402
mbed_official 340:28d1f895c6fe 403 /**
mbed_official 340:28d1f895c6fe 404 * @}
mbed_official 340:28d1f895c6fe 405 */
mbed_official 340:28d1f895c6fe 406
mbed_official 340:28d1f895c6fe 407 #endif /* HAL_IWDG_MODULE_ENABLED */
mbed_official 340:28d1f895c6fe 408 /**
mbed_official 340:28d1f895c6fe 409 * @}
mbed_official 340:28d1f895c6fe 410 */
mbed_official 340:28d1f895c6fe 411
mbed_official 340:28d1f895c6fe 412 /**
mbed_official 340:28d1f895c6fe 413 * @}
mbed_official 340:28d1f895c6fe 414 */
mbed_official 340:28d1f895c6fe 415
mbed_official 340:28d1f895c6fe 416 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/