예제 #1
0
파일: main.c 프로젝트: Amna2013/stm32-test
/**
  * @brief  Configure the LCD Glass.
  * @param  None
  * @retval None
  */
void LCD_Glass_Config(void)
{  
  /* Enable PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /* LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /*Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}
  
  /* LCD Clock Source Selection */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  /* Init LCD Glass */
  LCD_GLASS_Init();
}
/****************************************************************************
* 名    称:void RTC_Configuration(void)
* 功    能:RTC配置函数
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:
****************************************************************************/
static void RTC_Configuration(void)
{ 
    /* Enable the PWR clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    /* Allow access to RTC */
    PWR_RTCAccessCmd(ENABLE);
     /*!< Reset RTC Domain */
    RCC_RTCResetCmd(ENABLE);
    RCC_RTCResetCmd(DISABLE);

#if defined (RTC_CLOCK_SOURCE_LSI)  /* LSI used as RTC source clock*/
    /* The RTC Clock may varies due to LSI frequency dispersion. */   
    /* Enable the LSI OSC */ 
    RCC_LSICmd(ENABLE);
    /* Wait till LSI is ready */  
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {}
    /* Select the RTC Clock Source */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
  
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock *///外部32.378K晶振
    /* Enable the LSE OSC */
    RCC_LSEConfig(RCC_LSE_ON);
    /* Wait till LSE is ready */  
    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { }
    /* Select the RTC Clock Source */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else
    #error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
  
    /* Enable the RTC Clock */
    RCC_RTCCLKCmd(ENABLE);
    /* Wait for RTC APB registers synchronisation */
    RTC_WaitForSynchro();
}
예제 #3
0
/**
  * @brief  Configures the LCD Glass. LSI is used as LCD clock source
  * @param  None
  * @retval None
  */
void LCD_Glass_Config(void)
{
  /* Enable PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /* LSI Enable */
  RCC_LSICmd(ENABLE);

  /* Wait till LSI is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {}

  /* LCD Clock Source Selection: LSI */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#ifdef USE_STM32L152_EVAL
  /* LCD GLASS Initialization */
  LCD_GLASS_Init();
#endif  
}
예제 #4
0
파일: timers.c 프로젝트: tomvdb/lifegadgets
void initClock(void)
{

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_SYSCFG , ENABLE);

  // divide HCLK / 2
  RCC_HCLKConfig(RCC_SYSCLK_Div2);

  // enable HSI
  RCC_HSICmd(ENABLE);
  RCC_PLLCmd(DISABLE);

  // wait for HSI to get ready
  while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

  // configure PLL - x4 /2 
  RCC_PLLConfig( RCC_PLLSource_HSI, RCC_PLLMul_8,  RCC_PLLDiv_4 );
  RCC_PLLCmd(ENABLE);

  while ( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET );

  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  RCC_ClocksTypeDef RCC_Clocks;
  RCC_GetClocksFreq(&RCC_Clocks);

  SysTick_Config((RCC_Clocks.SYSCLK_Frequency / 2) / 1000); // Cannot exceed 16,777,215

  /* Set SysTick Preemption Priority, it's a system handler rather than a regular interrupt */
  NVIC_SetPriority(SysTick_IRQn, 0x04);

  // setup lse for rtc
  PWR_RTCAccessCmd(ENABLE);  

  // Reset RTC Backup Domain 
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  // LSE Enable
  RCC_LSEConfig(RCC_LSE_ON);

  // Wait until LSE is ready 
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
  
  // RTC Clock Source Selection 
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); 
  
  // Enable the RTC 
  RCC_RTCCLKCmd(ENABLE); 

  RTC_WaitForSynchro();    

}
예제 #5
0
/**
  * @brief  Configures the RTC Wakeup.
  * @param  None
  * @retval None
  */
void RTC_Config(void)
{
  NVIC_InitTypeDef  NVIC_InitStructure;
  EXTI_InitTypeDef  EXTI_InitStructure;

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /*!< Allow access to RTC */
  PWR_RTCAccessCmd(ENABLE);

  /*!< Reset RTC Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /*!< LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /*!< Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}

  /*!< LCD Clock Source Selection */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  /*!< Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);

  /*!< Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();

  /* EXTI configuration *******************************************************/
  EXTI_ClearITPendingBit(EXTI_Line20);
  EXTI_InitStructure.EXTI_Line = EXTI_Line20;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable the RTC Wakeup Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
 
  /* RTC Wakeup Interrupt Generation: Clock Source: RTCDiv_16, Wakeup Time Base: 4s */
  RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);
  RTC_SetWakeUpCounter(0x1FFF);

  /* Enable the Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, ENABLE);  
}
예제 #6
0
파일: main.c 프로젝트: awalter3/General
/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{  
  
  /* Enable HSI Clock */
  RCC_HSICmd(ENABLE);
  
  /*!< Wait till HSI is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
  {}

  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
  
  RCC_MSIRangeConfig(RCC_MSIRange_6);
  
  /* Enable the GPIOs Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOD| RCC_AHBPeriph_GPIOE| RCC_AHBPeriph_GPIOH, ENABLE);     

  /* Enable  comparator clock LCD and PWR mngt */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP | RCC_APB1Periph_LCD | RCC_APB1Periph_PWR,ENABLE);
    
  /* Enable ADC clock & SYSCFG */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_SYSCFG , ENABLE);

  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /* LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}
  
  RCC_RTCCLKCmd(ENABLE);
   
  /* LCD Clock Source Selection */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  
  RCC_HSEConfig(RCC_HSE_OFF);
  
  if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET )
  {
    while(1);
  }

}
예제 #7
0
/**
* @brief  Configure the RTC peripheral by selecting the clock source.
* @param  None
* @retval None
*/
static void RTC_Config(void)
{
  RTC_InitTypeDef RTC_InitStructure;
  RTC_TimeTypeDef  RTC_TimeStruct;
  
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  
  /* Allow access to RTC */
  PWR_RTCAccessCmd(ENABLE);
  
  /* Reset RTC Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);
  
  /* Enable the LSE OSC */
  RCC_LSEConfig(RCC_LSE_ON);
  
  /* Wait till LSE is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {
  }
  
  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  
  
  /* Configure the RTC data register and RTC prescaler */
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv  = 0xFF;
  RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);
  
  /* Set the time to 00h 00mn 00s AM */
  RTC_TimeStruct.RTC_H12     = RTC_H12_AM;
  RTC_TimeStruct.RTC_Hours   = 0x00;
  RTC_TimeStruct.RTC_Minutes = 0x00;
  RTC_TimeStruct.RTC_Seconds = 0x00;  
  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
  
  
  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  
  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
}
예제 #8
0
파일: main.c 프로젝트: wynstroh/GSMSecure
void EnableClock()
{

  // divide HCLK / 2
  RCC_HCLKConfig(RCC_SYSCLK_Div2);

  // enable HSI
  RCC_HSICmd(ENABLE);
  RCC_PLLCmd(DISABLE);
  // wait for HSI to get ready
  while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

  // configure PLL - x4 /2
  RCC_PLLConfig( RCC_PLLSource_HSI, RCC_PLLMul_8,  RCC_PLLDiv_4 );
  RCC_PLLCmd(ENABLE);

  while ( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET );

  // set hsi as clock
  //RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

  // set pll as clock
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  // setup lse for rtc and lcd
  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset RTC Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /* LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /* Wait until LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);

   /* RTC Clock Source Selection */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  /* Enable the RTC */
  RCC_RTCCLKCmd(ENABLE);

  RTC_WaitForSynchro();

}
예제 #9
0
파일: main.c 프로젝트: Amna2013/stm32-test
/**
  * @brief  Configures the different system and peripherals clocks.
  * @param  None
  * @retval None
  */
void RCC_Config(void)
{   
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /*!< LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /*!< Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}
  /*!< LCD Clock Source Selection */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
}
예제 #10
0
void RCC_RTC_Configuration(void)
{  
  RCC_ClocksTypeDef RCC_Clocks;
  
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD | RCC_APB1Periph_PWR, ENABLE);
  
  PWR_RTCAccessCmd(ENABLE);					//Allow access to the RTC
  RCC_RTCResetCmd(ENABLE);					//Reset Backup Domain
  RCC_RTCResetCmd(DISABLE);
  RCC_RTCCLKCmd(ENABLE);
  
  RCC_LSICmd(ENABLE);
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); //Wait till LSI is ready  
  
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);	//LCD Clock Source Selection
  
  
  	/* Configure SysTick IRQ and SysTick Timer to generate interrupts */
	RCC_GetClocksFreq(&RCC_Clocks);
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 500);
  
}
예제 #11
0
void RTC_Configuration(void)
{

    /* Allow access to the RTC */
    PWR_RTCAccessCmd(ENABLE);

    /* Reset Backup Domain */
    RCC_RTCResetCmd(ENABLE);
    RCC_RTCResetCmd(DISABLE);

    /* LSE Enable */
    RCC_LSEConfig(RCC_LSE_ON);

    /* Wait till LSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
    {}

    RCC_RTCCLKCmd(ENABLE);

    /* LCD Clock Source Selection */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

}
예제 #12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */

  /* --------------------- System Clocks Configuration -----------------------*/
  /* Enable GPIOA clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  /* Enable PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to the RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset Backup Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);

  /*!< LSE Enable */
  RCC_LSEConfig(RCC_LSE_ON);

  /*!< Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}
  
  /* TIM9 Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);     

  /*--------------------- TIM Configuration ----------------------------------*/
  /* TIM9 pins configuration: PA2 */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Remap PA2 to TIM9 Channel 1 */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM9);

  /* Time base configuration: TIM9 */
  /* PWM frequency = 32.768 / (0x1F + 1) = 1KHz */
  TIM_TimeBaseStructure.TIM_Period = 0x1F;
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  
  TIM_TimeBaseInit(TIM9, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: TIM9 Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  
  /* Duty cycle = 0x08 / (0x1F + 1) * 100 = 25 % */
  TIM_OCInitStructure.TIM_Pulse = 0x08;
  
  TIM_OC1Init(TIM9, &TIM_OCInitStructure);

  /* External clock configuration TIM9(LSE(32.768KHz)) */
  TIM_ETRClockMode1Config(TIM9, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted, 0);

  /* Enable TIM counter */
  TIM_Cmd(TIM9, ENABLE);
  
  while (1)
  {
  }
}
예제 #13
0
/**
  * @brief  Configure the RTC peripheral by selecting the clock source.
  * @param  None
  * @retval None
  */
void RTC_Config(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  EXTI_InitTypeDef  EXTI_InitStructure;

  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset BKP Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);
      
#if defined (RTC_CLOCK_SOURCE_LSI)  /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
  /* Enable the LSI OSC */ 
  RCC_LSICmd(ENABLE);

  /* Wait till LSI is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {
  }

  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
  
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
  /* Enable the LSE OSC */
  RCC_LSEConfig(RCC_LSE_ON);

  /* Wait till LSE is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {
  }

  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  
#else
  #error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
  
  /* Enable The external line19 interrupt */
  EXTI_ClearITPendingBit(EXTI_Line19);
  EXTI_InitStructure.EXTI_Line = EXTI_Line19;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable TAMPER IRQChannel */
  NVIC_InitStructure.NVIC_IRQChannel = TAMPER_STAMP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Disable the Tamper 1 detection */
  RTC_TamperCmd(RTC_Tamper_1, DISABLE);

  /* Clear Tamper 1 pin Event(TAMP1F) pending flag */
  RTC_ClearFlag(RTC_FLAG_TAMP1F);

  /* Configure the Tamper 1 Trigger */
  RTC_TamperTriggerConfig(RTC_Tamper_1, RTC_TamperTrigger_FallingEdge);

  /* Enable the Tamper interrupt */
  RTC_ITConfig(RTC_IT_TAMP, ENABLE);

  /* Clear Tamper 1 pin interrupt pending bit */
  RTC_ClearITPendingBit(RTC_IT_TAMP1);

  /* Enable the Tamper 1 detection */
  RTC_TamperCmd(RTC_Tamper_1, ENABLE);
}
예제 #14
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */  

  /* Enable PWR APB1 Clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to RTC */
  PWR_RTCAccessCmd(ENABLE);

  /* Reset RTC Domain */
  RCC_RTCResetCmd(ENABLE);
  RCC_RTCResetCmd(DISABLE);
#ifdef BOR_MODIFY
  /* Get BOR Option Bytes */
  BOROptionBytes = FLASH_OB_GetBOR();

  if((BOROptionBytes & 0x0F) != BOR_LEVEL) 
  {
    /* Unlocks the option bytes block access */
    FLASH_OB_Unlock();

    /* Clears the FLASH pending flags */
    FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);

    /* Select the desired V(BOR) Level ---------------------------------------*/
    FLASH_OB_BORConfig(BOR_LEVEL); 

    /* Launch the option byte loading */
    FLASH_OB_Launch();  
  }
#endif  

#if defined (LP_RUN_SRAM_MODE)
  /* Low Power Run Mode Entry:
      - System Running at MSI (~32KHz)
      - Flash 0 wait state
      - Voltage Range 2
      - Code running from Internal SRAM
      - All peripherals OFF
      - FLASH switched OFF
      - VDD from 1.65V to 3.6V
      - Current Consumption ~10.5uA
      - Wakeup using Key Button PA.00
   */
  LowPowerRunMode_Measure();
#elif defined (LP_RUN_FLASH_MODE)
  /* Low Power Run Mode Entry:
      - System Running at MSI (~32KHz)
      - Flash 0 wait state
      - Voltage Range 2
      - Code running from Internal FLASH
      - All peripherals OFF
      - VDD from 1.65V to 3.6V
      - Current Consumption ~25uA
      - Wakeup using Key Button PA.00
   */
  LowPowerRunMode_Measure();  
#elif defined (SLEEP_MODE)
  /* Sleep Mode Entry 
      - System Running at HSI (16MHz)
      - Flash 1 wait state
      - Voltage Range 2
      - Code running from Internal FLASH
      - Current Consumption ~1mA
      - Wakeup using EXTI Line (Key Button PA.00)
   */
  SleepMode_Measure();
#elif defined (LP_SLEEP_MODE)
  /* Low Power Sleep Mode Entry 
      - System Running at MSI (~32KHz)
      - Flash 0 wait state
      - Voltage Range 2
      - Code running from Internal FLASH
      - All peripherals OFF
      - VDD from 1.65V to 3.6V
      - Current Consumption ~4.07uA
      - Wakeup using EXTI Line (Key Button PA.00)
   */
  LowPowerSleepMode_Measure();
#elif defined (STOP_MODE)
  /* STOP Mode Entry 
      - Regulator in LP mode
      - LSI, HSI and HSE OFF
      - No IWDG
      - Current Consumption ~0.5uA
      - Wakeup using EXTI Line (Key Button PA.00)
   */
  StopMode_Measure();
#elif defined (STOP_RTC_LSE_MODE)
  /* STOP Mode with RTC on LSE Entry 
      - RTC Clocked by LSE external Clock (32.768KHz)
      - Regulator in LP mode
      - LSI, HSI and HSE OFF
      - No IWDG
      - Current Consumption ~1.6uA
      - Automatic Wakeup using RTC on LSE (4s)
   */
  StopRTCLSEMode_Measure();
#elif defined (STOP_RTC_LSI_MODE)
  /* STOP Mode with RTC on LSI Entry 
      - RTC Clocked by LSI
      - Regulator in LP mode
      - HSI and HSE OFF
      - No IWDG   
      - Current Consumption ~1.3uA
      - Automatic Wakeup using RTC on LSI (after ~4s)
   */
  StopRTCLSIMode_Measure();
#elif defined (STANDBY_MODE)
  /* STANDBY Mode Entry 
      - IWDG and LSI OFF
      - Current Consumption ~0.3uA
      - Wakeup using WakeUp Pin 1 (PA.00)
   */
  StandbyMode_Measure();
#elif defined (STANDBY_RTC_LSE_MODE)
  /* STANDBY Mode with RTC on LSE Entry 
      - RTC Clocked by LSE external Clock (32.768KHz)
      - IWDG and LSI OFF
      - Current Consumption ~1.3uA
      - Automatic Wakeup using RTC on LSE (after 4s)
   */
  StandbyRTCLSEMode_Measure();
#elif defined (STANDBY_RTC_LSI_MODE)
  /* STANDBY Mode with RTC on LSI Entry 
      - RTC Clocked by LSI
      - IWDG OFF
      - Current Consumption ~1.1uA
      - Automatic Wakeup using RTC on LSI (after ~4s)
  */
  StandbyRTCLSIMode_Measure();
#else
  /* Initialize LED1 on STM32L152-EVAL board */
  STM_EVAL_LEDInit(LED1);
  
  /* Infinite loop */
  while (1)
  {
    /* Toggle The LED1 */
    STM_EVAL_LEDToggle(LED1);

    /* Inserted Delay */
    for(Counter = 0; Counter < 0x5FF; Counter++);
  }
#endif
}
void rtc_init_counter_mode() {
	NVIC_InitTypeDef NVIC_InitStructure;
	EXTI_InitTypeDef EXTI_InitStructure;
	RTC_InitTypeDef RTC_InitStructure;
	/* Enable the PWR clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

	/* Allow access to RTC */
    PWR_RTCAccessCmd(ENABLE);

	  /* Reset RTC Domain */
	  RCC_RTCResetCmd(ENABLE);
	  RCC_RTCResetCmd(DISABLE);

	/* Enable the LSE OSC */
	RCC_LSEConfig(RCC_LSE_ON );

	/* Wait till LSE is ready */
	while (RCC_GetFlagStatus(RCC_FLAG_LSERDY ) == RESET) {
	}

	/* Select the RTC Clock Source */
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE );
	/* Set the RTC time base to 1s */
	RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
	RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
	RTC_InitStructure.RTC_SynchPrediv = 0x00FF;
	RTC_Init(&RTC_InitStructure);

	/* Enable the RTC Clock */
	RCC_RTCCLKCmd(ENABLE);
	/* Wait for RTC APB registers synchronization */
	RTC_WaitForSynchro();

	/* EXTI configuration *******************************************************/
	EXTI_ClearITPendingBit(EXTI_Line20 );
	EXTI_InitStructure.EXTI_Line = EXTI_Line20;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);

	/* Enable the RTC Wakeup Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */
	RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits );
	RTC_SetWakeUpCounter(0x0);

	/* Enable the RTC Wakeup Interrupt */
	RTC_ITConfig(RTC_IT_WUT, ENABLE);

	rtc_disable_interrupt();
	/* Enable Wakeup Counter */
	RTC_WakeUpCmd(ENABLE);

}
예제 #16
0
/**
  * @brief  Enter the MCU selected low power modes.
  * @param  lpmode: selected MCU low power modes. This parameter can be one of the
  *         following values:
  *              @arg STM32L_RUN: Run mode at 32MHz.
  *              @arg STM32L_RUN_1M: Run mode at 1MHz.
  *              @arg STM32L_RUN_LP: Low power Run mode at 32KHz.  
  *              @arg STM32L_SLEEP: Sleep mode at 16MHz.
  *              @arg STM32L_SLEEP_LP: Low power Sleep mode at 32KHz.
  *              @arg STM32L_STOP: Stop mode with or without RTC.
  *              @arg STM32L_STANDBY: Standby mode with or without RTC.
  * @param  RTCState: RTC peripheral state during low power modes. This parameter
  *         is valid only for STM32L_RUN_LP, STM32L_SLEEP_LP, STM32L_STOP and
  *         STM32L_STANDBY. This parameter can be one of the following values:
  *              @arg RTC_STATE_ON: RTC peripheral is ON during low power modes.
  *              @arg RTC_STATE_OFF: RTC peripheral is OFF during low power modes.
  * @param  CalibrationState: Bias Calibration mode selection state during low 
  *         power modes. 
  *         This parameter can be one of the following values:
  *              @arg BIAS_CALIB_OFF: Bias Calibration mode is selected during 
  *                   low power modes.
  *              @arg BIAS_CALIB_ON: Bias Calibration mode isn't selected during 
  *                   low power modes.
  * @retval None
*/
void IDD_Measurement(uint32_t lpmode, uint8_t RTCState, uint8_t CalibrationState)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  uint16_t mode = STM32L_MODE_LP, adcdata, i;

  /* Disable the Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, DISABLE);

  /* Disable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(DISABLE);

  /* Disable Leds toggling */
  Demo_LedShow(DISABLE);

  /* Save the RCC configuration */
  RCC_AHBENR   = RCC->AHBENR;
  RCC_APB2ENR  = RCC->APB2ENR;
  RCC_APB1ENR  = RCC->APB1ENR;

  /* Disable PVD */
  PWR_PVDCmd(DISABLE);

  /* Wait until JoyStick is pressed */
  while (Menu_ReadKey() != NOKEY)
  {}

  /* Save the GPIO pins current configuration then put all GPIO pins in Analog
     Input mode ...*/
  IDD_Measurement_SaveContext();

  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);

  RCC->AHBENR = 0x05;
  RCC->APB2ENR = 0x00;
  RCC->APB1ENR = 0x10000000;  /* PWR APB1 Clock enable */
  
  switch(lpmode)
  {
    /*=========================================================================*
     *                        RUN MODE 32MHz (HSE + PLL)                       *
     *========================================================================*/
    case STM32L_RUN:
    {  
      mode = STM32L_MODE_RUN;
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      for (i = 0;i < 0xFFFF; i++) 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }
    }
    break;

    /*=========================================================================*
     *                        RUN MODE MSI 1MHz                                *
     *========================================================================*/
    case STM32L_RUN_1M:
    {      
      mode = STM32L_MODE_RUN;
      
      /* Reconfigure the System Clock at MSI 1 MHz */
      SetHCLKToMSI_1MHz();
        
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      for (i = 0;i < 0x3FFF; i++) 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }
    }
    break;

    /*=========================================================================*
     *                        RUN LOW POWER MODE MSI 32KHz                     *
     *========================================================================*/    
    case STM32L_RUN_LP:
    {                
      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      /* Configure the System Clock at MSI 32 KHz */
      SetHCLKToMSI_64KHz(); 
      RCC_HCLKConfig(RCC_SYSCLK_Div2); 
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Enter low power run mode */
      PWR_EnterLowPowerRunMode(ENABLE);
      
      /* Waiting wake-up interrupt */
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      do 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }while(LowPowerStatus == 0x00);

      /* Exit low power run mode before setting the clock to 32MHz */
      PWR_EnterLowPowerRunMode(DISABLE);
      while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET)
      {
      }  
    }       
    break;

    /*=========================================================================*
     *                        SLEEP MODE HSI 16MHz                             * 
     *========================================================================*/        
    case STM32L_SLEEP:
    {            
      mode = STM32L_MODE_RUN;      
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);
      
      /* Diable FLASH during SLeep LP */
      FLASH_SLEEPPowerDownCmd(ENABLE);
            
      RCC_APB2PeriphClockLPModeCmd(RCC_APB2Periph_CLOCK, ENABLE);
      RCC_APB1PeriphClockLPModeCmd(RCC_APB1Periph_CLOCK, ENABLE);
      RCC_AHBPeriphClockLPModeCmd(RCC_AHBPeriph_CLOCK, ENABLE);
      
      /* Configure the System Clock to 16MHz */
      SetHCLKToHSI();
      
      Demo_SysTickConfig();
      Demo_Delay(5);
      
      /* Request to enter SLEEP mode with regulator on */
      PWR_EnterSleepMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); 
    }   
    break;

    /*=========================================================================*
     *                      SLEEP LOW POWER MODE MSI 32KHz                     *
     *========================================================================*/     
    case STM32L_SLEEP_LP:
    {            
      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);
      
      /* Diable FLASH during SLeep LP */
      FLASH_SLEEPPowerDownCmd(ENABLE);
      
      /* Disable HSI clock before entering Sleep LP mode */ 
      RCC_HSICmd(DISABLE);
      /* Disable HSE clock */
      RCC_HSEConfig(RCC_HSE_OFF);
      /* Disable LSI clock */
      RCC_LSICmd(DISABLE);
      
      RCC_APB2PeriphClockLPModeCmd(RCC_APB2Periph_CLOCK, ENABLE);
      RCC_APB1PeriphClockLPModeCmd(RCC_APB1Periph_CLOCK, ENABLE);
      RCC_AHBPeriphClockLPModeCmd(RCC_AHBPeriph_CLOCK, ENABLE);
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Reconfigure the System Clock at MSI 64 KHz */
      SetHCLKToMSI_64KHz();
      RCC_HCLKConfig(RCC_SYSCLK_Div2); 
      
      /* Request to enter SLEEP mode with regulator low power */
      PWR_EnterSleepMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);        
    }
    break;
    
    /*=========================================================================*
     *                          STOP LOW POWER MODE                            *
     *========================================================================*/    
    case STM32L_STOP:
    {                 
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);

      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Request to enter STOP mode with regulator in low power */
      PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
      
      /* Reset the counter by programming IDD_CNT_EN High in less than 70ms after
      the wakeup to avoid 1Kohm to be connected later on VDD_MCU */
      GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL
         as system clock source (HSE and PLL are disabled in STOP mode) */
      IDD_Measurement_SYSCLKConfig_STOP();      
    }
    break;

    /*=========================================================================*
     *                          STANDBY LOW POWER MODE                         *
     *========================================================================*/        
    case STM32L_STANDBY:
    {      
      if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
      {
        /* RTC Configuration **************************************************/
        /* Reset RTC Domain */
        RCC_RTCResetCmd(ENABLE);
        RCC_RTCResetCmd(DISABLE);
        
        /* Enable the LSE OSC */
        RCC_LSEConfig(RCC_LSE_ON);
        
        /* Wait till LSE is ready */
        while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
        {}
        
        /* Select the RTC Clock Source */
        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
        
        /* Enable the RTC Clock */
        RCC_RTCCLKCmd(ENABLE);
        
        /* Wait for RTC APB registers synchronisation */
        RTC_WaitForSynchro();
      } 
      
      RTC_OutputTypeConfig(RTC_OutputType_PushPull);
      RTC_OutputConfig(RTC_Output_WakeUp, RTC_OutputPolarity_High);  
      
      /* To configure PC13 WakeUP output */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;  
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_Init(GPIOC, &GPIO_InitStructure); 
      GPIO_PinAFConfig(GPIOC, GPIO_PinSource13, GPIO_AF_RTC_AF1);
      
      PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
      
      PWR_UltraLowPowerCmd(ENABLE); 
      
      RTC_ClearFlag(RTC_FLAG_WUTF | RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_TAMP1F | RTC_FLAG_TSF); 
      RTC_ITConfig(RTC_IT_WUT, DISABLE);

      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      
      /* Clear Wake Up flag */
      PWR_ClearFlag(PWR_FLAG_WU);  
      
      /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
      PWR_EnterSTANDBYMode();
    }     
    break; 
  }

  /* Configure the System Clock to 32MHz */
  SetHCLKTo32();
      
  /* Reset lowpower status variable*/  
  LowPowerStatus = 0x00;
      
  RCC->AHBENR = RCC_AHBENR;
  RCC->APB2ENR = RCC_APB2ENR;
  RCC->APB1ENR = RCC_APB1ENR;
      
  /* Reset the counter by programming IDD_CNT_EN High in less than 70ms after
     the wakeup to avoid 1Kohm to be connected later on VDD_MCU */
  GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
  
  /* Measure the Voltage using the ADC */    
  adcdata = IDD_Measurement_ADC_ReadValue();
  
  /* Write the ADC converted value in the DATA EEPROM memory for Bias Measurement */
  if(CalibrationState == BIAS_CALIB_ON)
  {
    /* Unlock EEPROM write access*/
    DATA_EEPROM_Unlock();
  
    /* Store the value in EEPROM for application needs */
    DATA_EEPROM_ProgramHalfWord(DATA_EEPROM_BIAS_ADDR, adcdata);
  
    /* Lock back EEPROM write access */
    DATA_EEPROM_Lock(); 
  }

  IDD_Measurement_ADC_DisplayValue(adcdata, mode);
    
  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
      
  /* Enable PVD */
  PWR_PVDCmd(ENABLE);
      
  /* Restore Demonstration Context. */
  IDD_Measurement_RestoreContext();
  
  LCD_SetBackColor(LCD_COLOR_GREEN);  
  LCD_DisplayStringLine(LCD_LINE_6, "STM32L LowPower Mode");          
  LCD_DisplayStringLine(LCD_LINE_7, Str);

  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "continue.           ");  

  /* Wait until Joystick pressed. */
  while (Menu_ReadKey() == NOKEY)
  {} 
  
  /* Disable ADC1 */
  ADC_Cmd(ADC1, DISABLE);

  LCD_Clear(LCD_COLOR_WHITE);
  
  LCD_GLASS_DisplayString(" STM32L ");

  /* Enable the Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, ENABLE);

  /* Enable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(ENABLE);
  
  /* Display the previous menu */
  Menu_DisplayMenu(); 
}
예제 #17
0
void platform_init_periphclk() {
    /// 1. Enable AHB clocks
    /// AHB is set to whatever clock frequency the CPU is using.
    ///
    /// RCC_AHBPeriph_GPIOA (*), RCC_AHBPeriph_GPIOB (*), RCC_AHBPeriph_GPIOC (*),
    /// RCC_AHBPeriph_GPIOD, RCC_AHBPeriph_GPIOE, RCC_AHBPeriph_GPIOH,
    /// RCC_AHBPeriph_CRC, RCC_AHBPeriph_FLITF, RCC_AHBPeriph_SRAM,
    /// RCC_AHBPeriph_DMA1 (*)
    RCC_AHBPeriphClockCmd(  RCC_AHBPeriph_GPIOA     |   \
                            RCC_AHBPeriph_GPIOB     |   \
                            RCC_AHBPeriph_GPIOC     |   \
                            RCC_AHBPeriph_DMA1,         \
                            ENABLE);

#ifdef _STM32L152VBT6_ // STM32H152:
    RCC_AHBPeriphClockCmd(  RCC_AHBPeriph_GPIOE, ENABLE);
#endif

    /// Enable APB1 clocks (16 MHz)
    /// Available peripherals on APB1, (*) denotes known Platform usage:
    /// RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,
    /// RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7, RCC_APB1Periph_LCD,
    /// RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2 (*), RCC_APB1Periph_USART2,
    /// RCC_APB1Periph_USART3 (*), RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2 (*),
    /// RCC_APB1Periph_USB (*), RCC_APB1Periph_PWR (*), RCC_APB1Periph_DAC,
    /// RCC_APB1Periph_COMP
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2     |   \
                            RCC_APB1Periph_USART3   |   \
                            RCC_APB1Periph_I2C2     |   \
                            RCC_APB1Periph_USB      |   \
                            RCC_APB1Periph_PWR      |   \
                            RCC_APB1Periph_TIM3     |   \
                            RCC_APB1Periph_TIM4,
                            ENABLE);


    /************* XXX fixme: should this be here? ********************/
    /* Allow access to the RTC */
    PWR_RTCAccessCmd(ENABLE);

    /* Reset Backup Domain */
    RCC_RTCResetCmd(ENABLE);
    RCC_RTCResetCmd(DISABLE);

    /*!< LSE Enable */
    RCC_LSEConfig(RCC_LSE_ON);

    /*!< Wait till LSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
        {}
    /******************************************************************/


    /// Enable APB2 clocks (1 MHz)
    /// Available peripherals on APB2, (*) denotes OpenTag usage:
    /// RCC_APB2Periph_SYSCFG, RCC_APB2ENR_SYSCFGEN, RCC_APB2Periph_TIM9 (*),
    /// RCC_APB2Periph_TIM10 (*), RCC_APB2Periph_TIM11, RCC_APB2Periph_ADC1 (*),
    /// RCC_APB2Periph_SPI1, RCC_APB2Periph_USART1
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM9     |   \
                            RCC_APB2Periph_TIM10    |   \
                            RCC_APB2Periph_TIM11    |   \
                            RCC_APB2Periph_ADC1,        \
                            ENABLE );


}