STM32L4xx_HAL_Driver  1.14.0
Initialization and Start functions

Initialization and Start functions. More...

Functions

HAL_StatusTypeDef HAL_IWDG_Init (IWDG_HandleTypeDef *hiwdg)
 Initialize the IWDG according to the specified parameters in the IWDG_InitTypeDef and start watchdog. Before exiting function, watchdog is refreshed in order to have correct time base. More...
 

Detailed Description

Initialization and Start functions.

 ===============================================================================
          ##### Initialization and Start functions #####
 ===============================================================================
 [..]  This section provides functions allowing to:
      (+) Initialize the IWDG according to the specified parameters in the
          IWDG_InitTypeDef of associated handle.
      (+) Manage Window option.
      (+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
          is reloaded in order to exit function with correct time base.

Function Documentation

◆ HAL_IWDG_Init()

HAL_StatusTypeDef HAL_IWDG_Init ( IWDG_HandleTypeDef hiwdg)

Initialize the IWDG according to the specified parameters in the IWDG_InitTypeDef and start watchdog. Before exiting function, watchdog is refreshed in order to have correct time base.

Parameters
hiwdgpointer to a IWDG_HandleTypeDef structure that contains the configuration information for the specified IWDG module.
Return values
HALstatus

Definition at line 154 of file stm32l4xx_hal_iwdg.c.

155 {
156  uint32_t tickstart;
157 
158  /* Check the IWDG handle allocation */
159  if (hiwdg == NULL)
160  {
161  return HAL_ERROR;
162  }
163 
164  /* Check the parameters */
165  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
166  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
167  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
168  assert_param(IS_IWDG_WINDOW(hiwdg->Init.Window));
169 
170  /* Enable IWDG. LSI is turned on automaticaly */
171  __HAL_IWDG_START(hiwdg);
172 
173  /* Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers by writing
174  0x5555 in KR */
175  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
176 
177  /* Write to IWDG registers the Prescaler & Reload values to work with */
178  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
179  hiwdg->Instance->RLR = hiwdg->Init.Reload;
180 
181  /* Check pending flag, if previous update not done, return timeout */
182  tickstart = HAL_GetTick();
183 
184  /* Wait for register to be updated */
185  while (hiwdg->Instance->SR != 0x00u)
186  {
187  if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
188  {
189  return HAL_TIMEOUT;
190  }
191  }
192 
193  /* If window parameter is different than current value, modify window
194  register */
195  if (hiwdg->Instance->WINR != hiwdg->Init.Window)
196  {
197  /* Write to IWDG WINR the IWDG_Window value to compare with. In any case,
198  even if window feature is disabled, Watchdog will be reloaded by writing
199  windows register */
200  hiwdg->Instance->WINR = hiwdg->Init.Window;
201  }
202  else
203  {
204  /* Reload IWDG counter with value defined in the reload register */
205  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
206  }
207 
208  /* Return function status */
209  return HAL_OK;
210 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
IWDG_InitTypeDef Init
return HAL_OK
IWDG_TypeDef * Instance
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))