コード例 #1
0
/**
  * @brief  Get the RCC_ClkInitStruct according to the internal
  * RCC configuration registers.
  * @param  PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
  *         returns the configuration information for the Extended Peripherals clocks(USART1,USART2, LPUART1, 
  *         I2C1, RTC, USB/RNG  and LPTIM1 clocks).
  * @retval None
  */
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
{
   /* Set all possible values for the extended clock type parameter -----------*/
  /* Common part first */
  #if !defined(STM32L051xx) && !defined(STM32L061xx)  
  PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
                                        RCC_PERIPHCLK_I2C1   | RCC_PERIPHCLK_I2C2   | RCC_PERIPHCLK_RTC     | \
                                        RCC_PERIPHCLK_USB    | RCC_PERIPHCLK_LPTIM1;
  
 #else 
  PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | \
                                        RCC_PERIPHCLK_I2C1   | RCC_PERIPHCLK_I2C2   | RCC_PERIPHCLK_RTC     | \
                                        RCC_PERIPHCLK_LPTIM1;
  #endif /* !(STM32L051xx) && !(STM32L061xx) */
  
  /* Get the USART1 configuration --------------------------------------------*/
  PeriphClkInit->Usart1ClockSelection  = __HAL_RCC_GET_USART1_SOURCE();
  /* Get the USART2 clock source ---------------------------------------------*/
  PeriphClkInit->Usart2ClockSelection  = __HAL_RCC_GET_USART2_SOURCE();
   /* Get the LPUART1 clock source ---------------------------------------------*/
  PeriphClkInit->Lpuart1ClockSelection = __HAL_RCC_GET_LPUART1_SOURCE();
  /* Get the I2C1 clock source -----------------------------------------------*/
  PeriphClkInit->I2c1ClockSelection    = __HAL_RCC_GET_I2C1_SOURCE();
  /* Get the LPTIM1 clock source -----------------------------------------------*/
  PeriphClkInit->LptimClockSelection   = __HAL_RCC_GET_LPTIM1_SOURCE();
  /* Get the RTC clock source -----------------------------------------------*/
  PeriphClkInit->RTCClockSelection     = __HAL_RCC_GET_RTC_SOURCE();

#if !defined(STM32L051xx) && !defined(STM32L061xx)  
  /* Get the USB/RNG clock source -----------------------------------------------*/
  PeriphClkInit->UsbClockSelection  = __HAL_RCC_GET_USB_SOURCE();
#endif /* !(STM32L051xx) && !(STM32L061xx) */
}
コード例 #2
0
/**
  * @brief  Get the PeriphClkInit according to the internal
  * RCC configuration registers.
  * @param  PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
  *         returns the configuration information for the Extended Peripherals clocks(RTC/LCD clocks).
  * @retval None
  */
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
{
    uint32_t srcclk = 0;

    /* Set all possible values for the extended clock type parameter------------*/
    PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC;
#if defined(LCD)
    PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LCD;
#endif /* LCD */

    /* Get the RTC/LCD configuration -----------------------------------------------*/
    srcclk = __HAL_RCC_GET_RTC_SOURCE();
    if (srcclk != RCC_RTCCLKSOURCE_HSE_DIV2)
    {
        /* Source clock is LSE or LSI*/
        PeriphClkInit->RTCClockSelection = srcclk;
    }
    else
    {
        /* Source clock is HSE. Need to get the prescaler value*/
        PeriphClkInit->RTCClockSelection = srcclk | (READ_BIT(RCC->CR, RCC_CR_RTCPRE));
    }
#if defined(LCD)
    PeriphClkInit->LCDClockSelection = PeriphClkInit->RTCClockSelection;
#endif /* LCD */
}
コード例 #3
0
/**
  * @brief  Returns the peripheral clock frequency
  * @note   Returns 0 if peripheral clock is unknown
  * @param  PeriphClk Peripheral clock identifier
  *         This parameter can be one of the following values:
  *            @arg @ref RCC_PERIPHCLK_RTC  RTC peripheral clock
  *            @arg @ref RCC_PERIPHCLK_LCD  LCD peripheral clock (depends on devices)
  * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
  */
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
{
    uint32_t temp_reg = 0, clkprediv = 0, frequency = 0;
    uint32_t srcclk = 0;

    /* Check the parameters */
    assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));

    switch (PeriphClk)
    {
    case RCC_PERIPHCLK_RTC:
#if defined(LCD)
    case RCC_PERIPHCLK_LCD:
#endif /* LCD */
    {
        /* Get RCC CSR configuration ------------------------------------------------------*/
        temp_reg = RCC->CSR;

        /* Get the current RTC source */
        srcclk = __HAL_RCC_GET_RTC_SOURCE();

        /* Check if LSE is ready if RTC clock selection is LSE */
        if ((srcclk == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSERDY)))
        {
            frequency = LSE_VALUE;
        }
        /* Check if LSI is ready if RTC clock selection is LSI */
        else if ((srcclk == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSIRDY)))
        {
            frequency = LSI_VALUE;
        }
        /* Check if HSE is ready and if RTC clock selection is HSE */
        else if ((srcclk == RCC_RTCCLKSOURCE_HSE_DIVX) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
        {
            /* Get the current HSE clock divider */
            clkprediv = __HAL_RCC_GET_RTC_HSE_PRESCALER();

            switch (clkprediv)
            {
            case RCC_RTC_HSE_DIV_16:  /* HSE DIV16 has been selected */
            {
                frequency = HSE_VALUE / 16;
                break;
            }
            case RCC_RTC_HSE_DIV_8:   /* HSE DIV8 has been selected  */
            {
                frequency = HSE_VALUE / 8;
                break;
            }
            case RCC_RTC_HSE_DIV_4:   /* HSE DIV4 has been selected  */
            {
                frequency = HSE_VALUE / 4;
                break;
            }
            default:                  /* HSE DIV2 has been selected  */
            {
                frequency = HSE_VALUE / 2;
                break;
            }
            }
        }
        /* Clock not enabled for RTC */
        else
        {
            frequency = 0;
        }
        break;
    }
    default:
    {
        break;
    }
    }
    return(frequency);
}
コード例 #4
0
/**
  * @brief  Returns the peripheral clock frequency
  * @note   Returns 0 if peripheral clock is unknown
  * @param  PeriphClk Peripheral clock identifier
  *         This parameter can be one of the following values:
  *            @arg @ref RCC_PERIPHCLK_RTC  RTC peripheral clock
  *            @arg @ref RCC_PERIPHCLK_LCD  LCD peripheral clock (depends on devices)
  * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
  */
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
{
  uint32_t temp_reg = 0, frequency = 0;
  uint32_t srcclk = 0;

  /* Check the parameters */
  assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
  
  switch (PeriphClk)
  {
  case RCC_PERIPHCLK_RTC:
#if defined(STM32L100xB) || defined(STM32L100xBA) || defined(STM32L100xC)\
 || defined(STM32L152xB) || defined(STM32L152xBA) || defined(STM32L152xC)\
 || defined(STM32L162xC) || defined(STM32L152xCA) || defined(STM32L152xD)\
 || defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L152xE) || defined(STM32L152xDX)\
 || defined(STM32L162xE) || defined(STM32L162xDX)
  case RCC_PERIPHCLK_LCD:
#endif /* STM32L100xB || STM32L152xBA || ... || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
    {
      /* Get RCC CSR configuration ------------------------------------------------------*/
      temp_reg = RCC->CSR;

      /* Get the current RTC source */
      srcclk = __HAL_RCC_GET_RTC_SOURCE();

      /* Check if LSE is ready if RTC clock selection is LSE */
      if ((srcclk == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSERDY)))
      {
        frequency = LSE_VALUE;
      }
      /* Check if LSI is ready if RTC clock selection is LSI */
      else if ((srcclk == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSIRDY)))
      {
        frequency = LSI_VALUE;
      }
      /* Check if HSE is ready */
      else if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
      {
        switch (READ_BIT(RCC->CR, RCC_CR_RTCPRE))
        {
          case RCC_CR_RTCPRE:     /* HSE DIV16 has been selected */
          {
            frequency = HSE_VALUE / 16;
            break;
          }
          case RCC_CR_RTCPRE_1:   /* HSE DIV8 has been selected */
          {
            frequency = HSE_VALUE / 8;
            break;
          }
          case RCC_CR_RTCPRE_0:   /* HSE DIV4 has been selected */
          {
            frequency = HSE_VALUE / 4;
            break;
          }
          default:
          {
            frequency = HSE_VALUE / 2;
            break;
          }
        }
      }
      /* Clock not enabled for RTC*/
      else
      {
        frequency = 0;
      }
      break;
    }
  default: 
    {
      break;
    }
  }
  return(frequency);
}