annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_iwdg.c @ 116:b848056057ce FlipDisplay

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