Exemplo n.º 1
0
/**
  * @brief  Initialize the WWDG according to the specified.
  *         parameters in the WWDG_InitTypeDef of  associated handle.
  * @param  hwwdg  pointer to a WWDG_HandleTypeDef structure that contains
  *                the configuration information for the specified WWDG module.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
{
  /* Check the WWDG handle allocation */
  if(hwwdg == NULL)
  {
    return HAL_ERROR;
  }

  /* Check the parameters */
  assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
  assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
  assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
  assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
  assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));

  /* Init the low level hardware */
  HAL_WWDG_MspInit(hwwdg);

  /* Set WWDG Counter */
  WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));

  /* Set WWDG Prescaler and Window */
  WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));

  /* Return function status */
  return HAL_OK;
}
Exemplo n.º 2
0
/**
  * @brief  Initializes the WWDG according to the specified
  *         parameters in the WWDG_InitTypeDef and creates the associated handle.
  * @param  hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
  *              the configuration information for the specified WWDG module.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
{
  /* Check the WWDG handle allocation */
  if(hwwdg == HAL_NULL)
  {
    return HAL_ERROR;
  }
  
  /* Check the parameters */
  assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
  assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
  assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window)); 
  assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter)); 
  
  if(hwwdg->State == HAL_WWDG_STATE_RESET)
  {
    /* Init the low level hardware */
    HAL_WWDG_MspInit(hwwdg);
  }
  
  /* Change WWDG peripheral state */
  hwwdg->State = HAL_WWDG_STATE_BUSY;

  /* Set WWDG Prescaler and Window */
  MODIFY_REG(hwwdg->Instance->CFR, (WWDG_CFR_WDGTB | WWDG_CFR_W), (hwwdg->Init.Prescaler | hwwdg->Init.Window));

  /* Set WWDG Counter */
  MODIFY_REG(hwwdg->Instance->CR, WWDG_CR_T, hwwdg->Init.Counter);
   
  /* Change WWDG peripheral state */
  hwwdg->State = HAL_WWDG_STATE_READY;
  
  /* Return function status */
  return HAL_OK;
}
Exemplo n.º 3
0
/**
  * @brief  Initializes the WWDG according to the specified
  *         parameters in the WWDG_InitTypeDef and creates the associated handle.
  * @param  hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
  *              the configuration information for the specified WWDG module.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
{
    uint32_t tmp = 0;

    /* Check the WWDG handle allocation */
    if(hwwdg == NULL)
    {
        return HAL_ERROR;
    }

    /* Check the parameters */
    assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
    assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
    assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
    assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));

    if(hwwdg->State == HAL_WWDG_STATE_RESET)
    {
        /* Init the low level hardware */
        HAL_WWDG_MspInit(hwwdg);
    }

    /* Change WWDG peripheral state */
    hwwdg->State = HAL_WWDG_STATE_BUSY;

    /* Set WWDG Prescaler and Window */
    /* Get the CFR register value */
    tmp = hwwdg->Instance->CFR;

    /* Clear WDGTB[1:0] and W[6:0] bits */
    tmp &= ((uint32_t)~(WWDG_CFR_WDGTB | WWDG_CFR_W));

    /* Prepare the WWDG Prescaler and Window parameters */
    tmp |= hwwdg->Init.Prescaler | hwwdg->Init.Window;

    /* Write to WWDG CFR */
    hwwdg->Instance->CFR = tmp;

    /* Set WWDG Counter */
    /* Get the CR register value */
    tmp = hwwdg->Instance->CR;

    /* Clear T[6:0] bits */
    tmp &= (uint32_t)~((uint32_t)WWDG_CR_T);

    /* Prepare the WWDG Counter parameter */
    tmp |= (hwwdg->Init.Counter);

    /* Write to WWDG CR */
    hwwdg->Instance->CR = tmp;

    /* Change WWDG peripheral state */
    hwwdg->State = HAL_WWDG_STATE_READY;

    /* Return function status */
    return HAL_OK;
}
Exemplo n.º 4
0
/**
 * @brief  Sets the WWDG Prescaler.
 * @param  WWDG_Prescaler: specifies the WWDG Prescaler.
 *   This parameter can be one of the following values:
 *     @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
 *     @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
 *     @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
 *     @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
 * @retval None
 */
void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) {
    uint32_t tmpreg = 0;
    /* Check the parameters */
    assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
    /* Clear WDGTB[1:0] bits */
    tmpreg = WWDG->CFR & CFR_WDGTB_MASK;
    /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
    tmpreg |= WWDG_Prescaler;
    /* Store the new value */
    WWDG->CFR = tmpreg;
}
Exemplo n.º 5
0
/**
  * @简述  设置 WWDG 预分频值.
  * @参数  WWDG_Prescaler: 指定 WWDG 预分频值.
  *                        这个参数可以是下面的值之一:
  *                        WWDG_Prescaler_1: WWDG 计数器时钟 = (PCLK1/4096)/1
  *                        WWDG_Prescaler_2: WWDG 计数器时钟 = (PCLK1/4096)/2
  *                        WWDG_Prescaler_4: WWDG 计数器时钟 = (PCLK1/4096)/4
  *                        WWDG_Prescaler_8: WWDG 计数器时钟 = (PCLK1/4096)/8
  * @返回  没有
  */
void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
{
  uint32_t tmpreg = 0;
  /* 检查参数 */
  assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
  /* 清除 WDGTB[1:0] 位 */
  tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
  /* 设置 WDGTB[1:0] 位,按照 WWDG_Prescaler 的值 */
  tmpreg |= WWDG_Prescaler;
  /* 存储新值 */
  WWDG->CFR = tmpreg;
}
Exemplo n.º 6
0
/*******************************************************************************
* Function Name  : WWDG_SetPrescaler
* Description    : Sets the WWDG Prescaler.
* Input          : - WWDG_Prescaler: specifies the WWDG Prescaler.
*                    This parameter can be one of the following values:
*                       - WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
*                       - WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
*                       - WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
*                       - WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
* Output         : None
* Return         : None
*******************************************************************************/
void WWDG_SetPrescaler(u32 WWDG_Prescaler)
{
  u32 tmpreg = 0;

  /* Check the parameters */
  assert(IS_WWDG_PRESCALER(WWDG_Prescaler));

  /* Clear WDGTB[8:7] bits */
  tmpreg = WWDG->CFR & CFR_WDGTB_Mask;

  /* Set WDGTB[8:7] bits according to WWDG_Prescaler value */
  tmpreg |= WWDG_Prescaler;

  /* Store the new value */
  WWDG->CFR = tmpreg;
}
/**
  * @brief  Initializes the WWDG according to the specified
  *         parameters in the WWDG_InitTypeDef and creates the associated handle.
  * @param  hwwdg : pointer to a WWDG_HandleTypeDef structure that contains
  *              the configuration information for the specified WWDG module.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
{

  /* Check the WWDG handle allocation */
  if(hwwdg == NULL)
  {
    return HAL_ERROR;
  }

  /* Check the parameters */
  assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
  assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
  assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
  assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
  
  if(hwwdg->State == HAL_WWDG_STATE_RESET)
  {
    /* Allocate lock resource and initialize it */
    hwwdg->Lock = HAL_UNLOCKED;

    /* Init the low level hardware */
    HAL_WWDG_MspInit(hwwdg);
  }

  /* Take lock  and change peripheral state */
   __HAL_LOCK(hwwdg);
  hwwdg->State = HAL_WWDG_STATE_BUSY;

   /* Set WWDG Prescaler and Window  and Counter*/
  MODIFY_REG(hwwdg->Instance->CFR, (WWDG_CFR_WDGTB | WWDG_CFR_W), (hwwdg->Init.Prescaler | hwwdg->Init.Window));
  MODIFY_REG(hwwdg->Instance->CR, WWDG_CR_T, hwwdg->Init.Counter);

  /* Change peripheral state and release lock*/
  hwwdg->State = HAL_WWDG_STATE_READY;
  __HAL_UNLOCK(hwwdg);

  /* Return function status */
  return HAL_OK;
}