STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_hal_iwdg.c
Go to the documentation of this file.
1
95
96/* Includes ------------------------------------------------------------------*/
97#include "stm32f4xx_hal.h"
98
102
103#ifdef HAL_IWDG_MODULE_ENABLED
108
109/* Private typedef -----------------------------------------------------------*/
110/* Private define ------------------------------------------------------------*/
114/* Status register needs up to 5 LSI clock periods divided by the clock
115 prescaler to be updated. The number of LSI clock periods is upper-rounded to
116 6 for the timeout value calculation.
117 The timeout value is calculated using the highest prescaler (256) and
118 the LSI_VALUE constant. The value of this constant can be changed by the user
119 to take into account possible LSI clock period variations.
120 The timeout value is multiplied by 1000 to be converted in milliseconds.
121 LSI startup time is also considered here by adding LSI_STARTUP_TIME
122 converted in milliseconds. */
123#define HAL_IWDG_DEFAULT_TIMEOUT (((6UL * 256UL * 1000UL) / (LSI_VALUE / 128U)) + \
124 ((LSI_STARTUP_TIME / 1000UL) + 1UL))
125#define IWDG_KERNEL_UPDATE_FLAGS (IWDG_SR_RVU | IWDG_SR_PVU)
129
130/* Private macro -------------------------------------------------------------*/
131/* Private variables ---------------------------------------------------------*/
132/* Private function prototypes -----------------------------------------------*/
133/* Exported functions --------------------------------------------------------*/
134
138
155
165{
166 uint32_t tickstart;
167
168 /* Check the IWDG handle allocation */
169 if (hiwdg == NULL)
170 {
171 return HAL_ERROR;
172 }
173
174 /* Check the parameters */
175 assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
178
179 /* Enable IWDG. LSI is turned on automatically */
180 __HAL_IWDG_START(hiwdg);
181
182 /* Enable write access to IWDG_PR and IWDG_RLR registers by writing
183 0x5555 in KR */
185
186 /* Write to IWDG registers the Prescaler & Reload values to work with */
187 hiwdg->Instance->PR = hiwdg->Init.Prescaler;
188 hiwdg->Instance->RLR = hiwdg->Init.Reload;
189
190 /* Check pending flag, if previous update not done, return timeout */
191 tickstart = HAL_GetTick();
192
193 /* Wait for register to be updated */
194 while ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
195 {
196 if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
197 {
198 if ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
199 {
200 return HAL_TIMEOUT;
201 }
202 }
203 }
204
205 /* Reload IWDG counter with value defined in the reload register */
207
208 /* Return function status */
209 return HAL_OK;
210}
211
212
216
217
231
239{
240 /* Reload IWDG counter with value defined in the reload register */
242
243 /* Return function status */
244 return HAL_OK;
245}
246
247
251
255
256#endif /* HAL_IWDG_MODULE_ENABLED */
260
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
#define __HAL_IWDG_START(__HANDLE__)
Enable the IWDG peripheral.
#define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__)
Reload IWDG counter with value defined in the reload register (write access to IWDG_PR and IWDG_RLR r...
#define IS_IWDG_PRESCALER(__PRESCALER__)
Check IWDG prescaler value.
#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)
Enable write access to IWDG_PR and IWDG_RLR registers.
#define IS_IWDG_RELOAD(__RELOAD__)
Check IWDG reload value.
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
IWDG Handle Structure definition.
IWDG_TypeDef * Instance
IWDG_InitTypeDef Init