Move telemetry displayport init and cms device registering
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F30x_StdPeriph_Driver / src / stm32f30x_iwdg.c
blobc82e3e8b0292e6fb280d9332a29dd8e062cec236
1 /**
2 ******************************************************************************
3 * @file stm32f30x_iwdg.c
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 04-April-2014
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the Independent watchdog (IWDG) peripheral:
9 * + Prescaler and Counter configuration
10 * + IWDG activation
11 * + Flag management
13 @verbatim
15 ===============================================================================
16 ##### IWDG features #####
17 ===============================================================================
18 [..] The IWDG can be started by either software or hardware (configurable
19 through option byte).
20 [..] The IWDG is clocked by its own dedicated low-speed clock (LSI) and
21 thus stays active even if the main clock fails.
22 Once the IWDG is started, the LSI is forced ON and cannot be disabled
23 (LSI cannot be disabled too), and the counter starts counting down from
24 the reset value of 0xFFF. When it reaches the end of count value (0x000)
25 a system reset is generated.
26 The IWDG counter should be reloaded at regular intervals to prevent
27 an MCU reset.
28 [..] The IWDG is implemented in the VDD voltage domain that is still functional
29 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
30 [..] IWDGRST flag in RCC_CSR register can be used to inform when a IWDG
31 reset occurs.
32 [..] Min-max timeout value @41KHz (LSI): ~0.1ms / ~25.5s
33 The IWDG timeout may vary due to LSI frequency dispersion. STM32F30x
34 devices provide the capability to measure the LSI frequency (LSI clock
35 connected internally to TIM16 CH1 input capture). The measured value
36 can be used to have an IWDG timeout with an acceptable accuracy.
37 For more information, please refer to the STM32F30x Reference manual.
39 ##### How to use this driver #####
40 ===============================================================================
41 [..] This driver allows to use IWDG peripheral with either window option enabled
42 or disabled. To do so follow one of the two procedures below.
43 (#) Window option is enabled:
44 (++) Start the IWDG using IWDG_Enable() function, when the IWDG is used
45 in software mode (no need to enable the LSI, it will be enabled
46 by hardware).
47 (++) Enable write access to IWDG_PR and IWDG_RLR registers using
48 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function.
49 (++) Configure the IWDG prescaler using IWDG_SetPrescaler() function.
50 (++) Configure the IWDG counter value using IWDG_SetReload() function.
51 This value will be loaded in the IWDG counter each time the counter
52 is reloaded, then the IWDG will start counting down from this value.
53 (++) Wait for the IWDG registers to be updated using IWDG_GetFlagStatus() function.
54 (++) Configure the IWDG refresh window using IWDG_SetWindowValue() function.
56 (#) Window option is disabled:
57 (++) Enable write access to IWDG_PR and IWDG_RLR registers using
58 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function.
59 (++) Configure the IWDG prescaler using IWDG_SetPrescaler() function.
60 (++) Configure the IWDG counter value using IWDG_SetReload() function.
61 This value will be loaded in the IWDG counter each time the counter
62 is reloaded, then the IWDG will start counting down from this value.
63 (++) Wait for the IWDG registers to be updated using IWDG_GetFlagStatus() function.
64 (++) reload the IWDG counter at regular intervals during normal operation
65 to prevent an MCU reset, using IWDG_ReloadCounter() function.
66 (++) Start the IWDG using IWDG_Enable() function, when the IWDG is used
67 in software mode (no need to enable the LSI, it will be enabled
68 by hardware).
70 @endverbatim
72 ******************************************************************************
73 * @attention
75 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
77 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
78 * You may not use this file except in compliance with the License.
79 * You may obtain a copy of the License at:
81 * http://www.st.com/software_license_agreement_liberty_v2
83 * Unless required by applicable law or agreed to in writing, software
84 * distributed under the License is distributed on an "AS IS" BASIS,
85 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86 * See the License for the specific language governing permissions and
87 * limitations under the License.
89 ******************************************************************************
92 /* Includes ------------------------------------------------------------------*/
93 #include "stm32f30x_iwdg.h"
95 /** @addtogroup STM32F30x_StdPeriph_Driver
96 * @{
99 /** @defgroup IWDG
100 * @brief IWDG driver modules
101 * @{
104 /* Private typedef -----------------------------------------------------------*/
105 /* Private define ------------------------------------------------------------*/
106 /* ---------------------- IWDG registers bit mask ----------------------------*/
107 /* KR register bit mask */
108 #define KR_KEY_RELOAD ((uint16_t)0xAAAA)
109 #define KR_KEY_ENABLE ((uint16_t)0xCCCC)
111 /* Private macro -------------------------------------------------------------*/
112 /* Private variables ---------------------------------------------------------*/
113 /* Private function prototypes -----------------------------------------------*/
114 /* Private functions ---------------------------------------------------------*/
116 /** @defgroup IWDG_Private_Functions
117 * @{
120 /** @defgroup IWDG_Group1 Prescaler and Counter configuration functions
121 * @brief Prescaler and Counter configuration functions
123 @verbatim
124 ===============================================================================
125 ##### Prescaler and Counter configuration functions #####
126 ===============================================================================
128 @endverbatim
129 * @{
133 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
134 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
135 * This parameter can be one of the following values:
136 * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
137 * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
138 * @retval None
140 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
142 /* Check the parameters */
143 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
144 IWDG->KR = IWDG_WriteAccess;
148 * @brief Sets IWDG Prescaler value.
149 * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
150 * This parameter can be one of the following values:
151 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
152 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
153 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
154 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
155 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
156 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
157 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
158 * @retval None
160 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
162 /* Check the parameters */
163 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
164 IWDG->PR = IWDG_Prescaler;
168 * @brief Sets IWDG Reload value.
169 * @param Reload: specifies the IWDG Reload value.
170 * This parameter must be a number between 0 and 0x0FFF.
171 * @retval None
173 void IWDG_SetReload(uint16_t Reload)
175 /* Check the parameters */
176 assert_param(IS_IWDG_RELOAD(Reload));
177 IWDG->RLR = Reload;
181 * @brief Reloads IWDG counter with value defined in the reload register
182 * (write access to IWDG_PR and IWDG_RLR registers disabled).
183 * @param None
184 * @retval None
186 void IWDG_ReloadCounter(void)
188 IWDG->KR = KR_KEY_RELOAD;
193 * @brief Sets the IWDG window value.
194 * @param WindowValue: specifies the window value to be compared to the downcounter.
195 * @retval None
197 void IWDG_SetWindowValue(uint16_t WindowValue)
199 /* Check the parameters */
200 assert_param(IS_IWDG_WINDOW_VALUE(WindowValue));
201 IWDG->WINR = WindowValue;
205 * @}
208 /** @defgroup IWDG_Group2 IWDG activation function
209 * @brief IWDG activation function
211 @verbatim
212 ===============================================================================
213 ##### IWDG activation function #####
214 ===============================================================================
216 @endverbatim
217 * @{
221 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
222 * @param None
223 * @retval None
225 void IWDG_Enable(void)
227 IWDG->KR = KR_KEY_ENABLE;
231 * @}
234 /** @defgroup IWDG_Group3 Flag management function
235 * @brief Flag management function
237 @verbatim
238 ===============================================================================
239 ##### Flag management function #####
240 ===============================================================================
242 @endverbatim
243 * @{
247 * @brief Checks whether the specified IWDG flag is set or not.
248 * @param IWDG_FLAG: specifies the flag to check.
249 * This parameter can be one of the following values:
250 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
251 * @arg IWDG_FLAG_RVU: Reload Value Update on going
252 * @arg IWDG_FLAG_WVU: Counter Window Value Update on going
253 * @retval The new state of IWDG_FLAG (SET or RESET).
255 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
257 FlagStatus bitstatus = RESET;
258 /* Check the parameters */
259 assert_param(IS_IWDG_FLAG(IWDG_FLAG));
260 if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
262 bitstatus = SET;
264 else
266 bitstatus = RESET;
268 /* Return the flag status */
269 return bitstatus;
273 * @}
277 * @}
281 * @}
285 * @}
288 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/