STM32F4xx HAL Driver
master
STM32CubeF4 HAL / LL Drivers API Reference
Toggle main menu visibility
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
164
HAL_StatusTypeDef
HAL_IWDG_Init
(
IWDG_HandleTypeDef
*hiwdg)
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
));
176
assert_param
(
IS_IWDG_PRESCALER
(hiwdg->
Init
.
Prescaler
));
177
assert_param
(
IS_IWDG_RELOAD
(hiwdg->
Init
.
Reload
));
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 */
184
IWDG_ENABLE_WRITE_ACCESS
(hiwdg);
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 */
206
__HAL_IWDG_RELOAD_COUNTER
(hiwdg);
207
208
/* Return function status */
209
return
HAL_OK
;
210
}
211
212
216
217
231
238
HAL_StatusTypeDef
HAL_IWDG_Refresh
(
IWDG_HandleTypeDef
*hiwdg)
239
{
240
/* Reload IWDG counter with value defined in the reload register */
241
__HAL_IWDG_RELOAD_COUNTER
(hiwdg);
242
243
/* Return function status */
244
return
HAL_OK
;
245
}
246
247
251
255
256
#endif
/* HAL_IWDG_MODULE_ENABLED */
260
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition
stm32f4xx_hal.c:323
HAL_IWDG_Init
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
HAL_IWDG_Refresh
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
__HAL_IWDG_START
#define __HAL_IWDG_START(__HANDLE__)
Enable the IWDG peripheral.
Definition
stm32f4xx_hal_iwdg.h:104
__HAL_IWDG_RELOAD_COUNTER
#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...
Definition
stm32f4xx_hal_iwdg.h:112
IS_IWDG_PRESCALER
#define IS_IWDG_PRESCALER(__PRESCALER__)
Check IWDG prescaler value.
Definition
stm32f4xx_hal_iwdg.h:186
IWDG_ENABLE_WRITE_ACCESS
#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)
Enable write access to IWDG_PR and IWDG_RLR registers.
Definition
stm32f4xx_hal_iwdg.h:172
IS_IWDG_RELOAD
#define IS_IWDG_RELOAD(__RELOAD__)
Check IWDG reload value.
Definition
stm32f4xx_hal_iwdg.h:199
assert_param
#define assert_param(expr)
Definition
stm32_assert_template.h:46
stm32f4xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition.
Definition
stm32f4xx_hal_def.h:39
HAL_TIMEOUT
@ HAL_TIMEOUT
Definition
stm32f4xx_hal_def.h:43
HAL_ERROR
@ HAL_ERROR
Definition
stm32f4xx_hal_def.h:41
HAL_OK
@ HAL_OK
Definition
stm32f4xx_hal_def.h:40
IWDG_HandleTypeDef
IWDG Handle Structure definition.
Definition
stm32f4xx_hal_iwdg.h:60
IWDG_HandleTypeDef::Instance
IWDG_TypeDef * Instance
Definition
stm32f4xx_hal_iwdg.h:61
IWDG_HandleTypeDef::Init
IWDG_InitTypeDef Init
Definition
stm32f4xx_hal_iwdg.h:63
IWDG_InitTypeDef::Prescaler
uint32_t Prescaler
Definition
stm32f4xx_hal_iwdg.h:48
IWDG_InitTypeDef::Reload
uint32_t Reload
Definition
stm32f4xx_hal_iwdg.h:51
hal-driver
Src
stm32f4xx_hal_iwdg.c
Generated by
1.17.0