Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more
stm32f30x_wwdg.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f30x_wwdg.c 00004 * @author MCD Application Team 00005 * @version V1.2.3 00006 * @date 10-July-2015 00007 * @brief This file provides firmware functions to manage the following 00008 * functionalities of the Window watchdog (WWDG) peripheral: 00009 * + Prescaler, Refresh window and Counter configuration 00010 * + WWDG activation 00011 * + Interrupts and flags management 00012 * 00013 * @verbatim 00014 * 00015 ============================================================================== 00016 ##### WWDG features ##### 00017 ============================================================================== 00018 00019 [..] Once enabled the WWDG generates a system reset on expiry of a programmed 00020 time period, unless the program refreshes the counter (downcounter) 00021 before to reach 0x3F value (i.e. a reset is generated when the counter 00022 value rolls over from 0x40 to 0x3F). 00023 [..] An MCU reset is also generated if the counter value is refreshed 00024 before the counter has reached the refresh window value. This 00025 implies that the counter must be refreshed in a limited window. 00026 00027 [..] Once enabled the WWDG cannot be disabled except by a system reset. 00028 00029 [..] WWDGRST flag in RCC_CSR register can be used to inform when a WWDG 00030 reset occurs. 00031 00032 [..] The WWDG counter input clock is derived from the APB clock divided 00033 by a programmable prescaler. 00034 00035 [..] WWDG counter clock = PCLK1 / Prescaler. 00036 [..] WWDG timeout = (WWDG counter clock) * (counter value). 00037 00038 [..] Min-max timeout value @36MHz (PCLK1): ~114us / ~58.3ms. 00039 00040 ##### How to use this driver ##### 00041 ============================================================================== 00042 [..] 00043 (#) Enable WWDG clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE) 00044 function. 00045 00046 (#) Configure the WWDG prescaler using WWDG_SetPrescaler() function. 00047 00048 (#) Configure the WWDG refresh window using WWDG_SetWindowValue() function. 00049 00050 (#) Set the WWDG counter value and start it using WWDG_Enable() function. 00051 When the WWDG is enabled the counter value should be configured to 00052 a value greater than 0x40 to prevent generating an immediate reset. 00053 00054 (#) Optionally you can enable the Early wakeup interrupt which is 00055 generated when the counter reach 0x40. 00056 Once enabled this interrupt cannot be disabled except by a system reset. 00057 00058 (#) Then the application program must refresh the WWDG counter at regular 00059 intervals during normal operation to prevent an MCU reset, using 00060 WWDG_SetCounter() function. This operation must occur only when 00061 the counter value is lower than the refresh window value, 00062 programmed using WWDG_SetWindowValue(). 00063 00064 @endverbatim 00065 00066 ****************************************************************************** 00067 * @attention 00068 * 00069 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 00070 * 00071 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00072 * You may not use this file except in compliance with the License. 00073 * You may obtain a copy of the License at: 00074 * 00075 * http://www.st.com/software_license_agreement_liberty_v2 00076 * 00077 * Unless required by applicable law or agreed to in writing, software 00078 * distributed under the License is distributed on an "AS IS" BASIS, 00079 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00080 * See the License for the specific language governing permissions and 00081 * limitations under the License. 00082 * 00083 ****************************************************************************** 00084 */ 00085 00086 /* Includes ------------------------------------------------------------------*/ 00087 #include "stm32f30x_wwdg.h" 00088 #include "stm32f30x_rcc.h" 00089 00090 /** @addtogroup STM32F30x_StdPeriph_Driver 00091 * @{ 00092 */ 00093 00094 /** @defgroup WWDG 00095 * @brief WWDG driver modules 00096 * @{ 00097 */ 00098 00099 /* Private typedef -----------------------------------------------------------*/ 00100 /* Private define ------------------------------------------------------------*/ 00101 /* --------------------- WWDG registers bit mask ---------------------------- */ 00102 /* CFR register bit mask */ 00103 #define CFR_WDGTB_MASK ((uint32_t)0xFFFFFE7F) 00104 #define CFR_W_MASK ((uint32_t)0xFFFFFF80) 00105 #define BIT_MASK ((uint8_t)0x7F) 00106 00107 /* Private macro -------------------------------------------------------------*/ 00108 /* Private variables ---------------------------------------------------------*/ 00109 /* Private function prototypes -----------------------------------------------*/ 00110 /* Private functions ---------------------------------------------------------*/ 00111 00112 /** @defgroup WWDG_Private_Functions 00113 * @{ 00114 */ 00115 00116 /** @defgroup WWDG_Group1 Prescaler, Refresh window and Counter configuration functions 00117 * @brief Prescaler, Refresh window and Counter configuration functions 00118 * 00119 @verbatim 00120 ============================================================================== 00121 ##### Prescaler, Refresh window and Counter configuration functions ##### 00122 ============================================================================== 00123 00124 @endverbatim 00125 * @{ 00126 */ 00127 00128 /** 00129 * @brief Deinitializes the WWDG peripheral registers to their default reset values. 00130 * @param None 00131 * @retval None 00132 */ 00133 void WWDG_DeInit(void) 00134 { 00135 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 00136 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 00137 } 00138 00139 /** 00140 * @brief Sets the WWDG Prescaler. 00141 * @param WWDG_Prescaler: specifies the WWDG Prescaler. 00142 * This parameter can be one of the following values: 00143 * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 00144 * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 00145 * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 00146 * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 00147 * @retval None 00148 */ 00149 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 00150 { 00151 uint32_t tmpreg = 0; 00152 /* Check the parameters */ 00153 assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 00154 /* Clear WDGTB[1:0] bits */ 00155 tmpreg = WWDG->CFR & CFR_WDGTB_MASK; 00156 /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 00157 tmpreg |= WWDG_Prescaler; 00158 /* Store the new value */ 00159 WWDG->CFR = tmpreg; 00160 } 00161 00162 /** 00163 * @brief Sets the WWDG window value. 00164 * @param WindowValue: specifies the window value to be compared to the downcounter. 00165 * This parameter value must be lower than 0x80. 00166 * @retval None 00167 */ 00168 void WWDG_SetWindowValue(uint8_t WindowValue) 00169 { 00170 __IO uint32_t tmpreg = 0; 00171 00172 /* Check the parameters */ 00173 assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 00174 /* Clear W[6:0] bits */ 00175 00176 tmpreg = WWDG->CFR & CFR_W_MASK; 00177 00178 /* Set W[6:0] bits according to WindowValue value */ 00179 tmpreg |= WindowValue & (uint32_t) BIT_MASK; 00180 00181 /* Store the new value */ 00182 WWDG->CFR = tmpreg; 00183 } 00184 00185 /** 00186 * @brief Enables the WWDG Early Wakeup interrupt(EWI). 00187 * @note Once enabled this interrupt cannot be disabled except by a system reset. 00188 * @param None 00189 * @retval None 00190 */ 00191 void WWDG_EnableIT(void) 00192 { 00193 WWDG->CFR |= WWDG_CFR_EWI; 00194 } 00195 00196 /** 00197 * @brief Sets the WWDG counter value. 00198 * @param Counter: specifies the watchdog counter value. 00199 * This parameter must be a number between 0x40 and 0x7F (to prevent generating 00200 * an immediate reset). 00201 * @retval None 00202 */ 00203 void WWDG_SetCounter(uint8_t Counter) 00204 { 00205 /* Check the parameters */ 00206 assert_param(IS_WWDG_COUNTER(Counter)); 00207 /* Write to T[6:0] bits to configure the counter value, no need to do 00208 a read-modify-write; writing a 0 to WDGA bit does nothing */ 00209 WWDG->CR = Counter & BIT_MASK; 00210 } 00211 00212 /** 00213 * @} 00214 */ 00215 00216 /** @defgroup WWDG_Group2 WWDG activation functions 00217 * @brief WWDG activation functions 00218 * 00219 @verbatim 00220 ============================================================================== 00221 ##### WWDG activation function ##### 00222 ============================================================================== 00223 00224 @endverbatim 00225 * @{ 00226 */ 00227 00228 /** 00229 * @brief Enables WWDG and load the counter value. 00230 * @param Counter: specifies the watchdog counter value. 00231 * This parameter must be a number between 0x40 and 0x7F (to prevent generating 00232 * an immediate reset). 00233 * @retval None 00234 */ 00235 void WWDG_Enable(uint8_t Counter) 00236 { 00237 /* Check the parameters */ 00238 assert_param(IS_WWDG_COUNTER(Counter)); 00239 WWDG->CR = WWDG_CR_WDGA | Counter; 00240 } 00241 00242 /** 00243 * @} 00244 */ 00245 00246 /** @defgroup WWDG_Group3 Interrupts and flags management functions 00247 * @brief Interrupts and flags management functions 00248 * 00249 @verbatim 00250 ============================================================================== 00251 ##### Interrupts and flags management functions ##### 00252 ============================================================================== 00253 00254 @endverbatim 00255 * @{ 00256 */ 00257 00258 /** 00259 * @brief Checks whether the Early Wakeup interrupt flag is set or not. 00260 * @param None 00261 * @retval The new state of the Early Wakeup interrupt flag (SET or RESET). 00262 */ 00263 FlagStatus WWDG_GetFlagStatus(void) 00264 { 00265 FlagStatus bitstatus = RESET; 00266 00267 if ((WWDG->SR) != (uint32_t)RESET) 00268 { 00269 bitstatus = SET; 00270 } 00271 else 00272 { 00273 bitstatus = RESET; 00274 } 00275 return bitstatus; 00276 } 00277 00278 /** 00279 * @brief Clears Early Wakeup interrupt flag. 00280 * @param None 00281 * @retval None 00282 */ 00283 void WWDG_ClearFlag(void) 00284 { 00285 WWDG->SR = (uint32_t)RESET; 00286 } 00287 00288 /** 00289 * @} 00290 */ 00291 00292 /** 00293 * @} 00294 */ 00295 00296 /** 00297 * @} 00298 */ 00299 00300 /** 00301 * @} 00302 */ 00303 00304 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:34:45 by
