Пример #1
0
/**
  * @brief  Selects HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
  * @param  None
  * @retval None
  */
void SetHCLKTo8(void)
{
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if (HSEStartUpStatus == SUCCESS)
  {
    /* Flash 0 wait state */
    FLASH_SetLatency(FLASH_Latency_0);

    /* Disable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(DISABLE);

    /* Disable 64-bit access */
    FLASH_ReadAccess64Cmd(DISABLE);

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

    /* Select the Voltage Range 2 (1.5V) */
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);

    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
    {}

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK */
    RCC_PCLK1Config(RCC_HCLK_Div1);

    /* Select HSE as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

    /* Wait till HSE is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x08)
    {}
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock configuration.
                           User can add here some code to deal with this error */

    /* Go to infinite loop */
    while (1)
    {}
  }
}
Пример #2
0
/**
  * @brief  To select MSI as System clock source 
  * @caller ADC_Icc_Test
  * @param Frequence, DIV by 2 ot not , With or without RTC
  * @retval None
  */
void SetHSICLKToMSI(uint32_t freq,bool div2,bool With_RTC)
{
  
  /* RCC system reset */
  RCC_DeInit();

  /* Flash 1 wait state */
  FLASH_SetLatency(FLASH_Latency_0);
  
  /* Disable Prefetch Buffer */
  FLASH_PrefetchBufferCmd(DISABLE);

  /* Disable 64-bit access */
  FLASH_ReadAccess64Cmd(DISABLE);
         
  /* Disable FLASH during SLeep  */
  FLASH_SLEEPPowerDownCmd(ENABLE);
 
  /* Enable the PWR APB1 Clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Select the Voltage Range 3 (1.2V) */
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);

  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
  {}

  /* To configure the MSI frequency */
  RCC_MSIRangeConfig(freq);
  
  /* Select MSI as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);

  /* Wait till MSI is used as system clock source */
  while (RCC_GetSYSCLKSource() != 0x00)
  {}
  
  if (div2)
  {
    RCC_HCLKConfig(RCC_SYSCLK_Div2);    
  }

  RCC_HSICmd(DISABLE);

  /* Disable HSE clock */
  RCC_HSEConfig(RCC_HSE_OFF);

  /* Disable LSE clock */
  if (! With_RTC)
    RCC_LSEConfig(RCC_LSE_OFF);

  /* Disable LSI clock */
  RCC_LSICmd(DISABLE);  

}
Пример #3
0
void powerStateCheck() {
    if (unlikely(current_power_state != new_power_state)) {
        switch (new_power_state) {
        case POWER_STATE_HI_SPEED:
            // Для более быстрого изменения напряжения питания ядра
            if (current_power_state == POWER_STATE_LOW_SPEED) {
                RCC_MSIRangeConfig(RCC_MSIRange_4);
            }

            PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
            RCC_MSIRangeConfig(RCC_MSIRange_6);
            currentCPU_HZ = powerStateClockFrequency(new_power_state);
            SysTick_Config(currentCPU_HZ / configTICK_RATE_HZ);
            break;
        case POWER_STATE_MED_SPEED:
            RCC_MSIRangeConfig(RCC_MSIRange_4);
            currentCPU_HZ = powerStateClockFrequency(new_power_state);
            SysTick_Config(currentCPU_HZ / configTICK_RATE_HZ);

            if (current_power_state == POWER_STATE_HI_SPEED) {
                PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
            }

            break;
        case POWER_STATE_LOW_SPEED:
            if (current_power_state == POWER_STATE_HI_SPEED) {
                // Для более быстрого изменения питания ядра
                RCC_MSIRangeConfig(RCC_MSIRange_4);
                PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
            }

            // Окончательный переход на другую частоту
            RCC_MSIRangeConfig(RCC_MSIRange_1);
            currentCPU_HZ = powerStateClockFrequency(new_power_state);
            SysTick_Config(currentCPU_HZ / configTICK_RATE_HZ);
            break;
        }

        // Установка нового состояния энергосбережения
        current_power_state = new_power_state;
    }
}
Пример #4
0
void initPowerSubsystem() {
    RCC_MSIRangeConfig(RCC_MSIRange_4);
    new_power_state = POWER_STATE_MED_SPEED;
    currentCPU_HZ = powerStateClockFrequency(new_power_state);
    SysTick_Config(powerStateClockFrequency(new_power_state) / configTICK_RATE_HZ);
    current_power_state = new_power_state;
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);
    FLASH_SetLatency(FLASH_Latency_0);
    FLASH_PrefetchBufferCmd(DISABLE);
    FLASH_ReadAccess64Cmd(DISABLE);
}
Пример #5
0
/**
  * @brief  Selects MSI (64KHz) as System clock source and configure
  *         HCLK, PCLK2 and PCLK1 prescalers.
  * @param  None
  * @retval None
  */
void SetHCLKToMSI_64KHz(void)
{
  /* RCC system reset */
  RCC_DeInit();

  /* Flash 0 wait state */
  FLASH_SetLatency(FLASH_Latency_0);

  /* Disable Prefetch Buffer */
  FLASH_PrefetchBufferCmd(DISABLE);

  /* Disable 64-bit access */
  FLASH_ReadAccess64Cmd(DISABLE);

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

  /* Select the Voltage Range 3 (1.2V) */
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);

  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
  {}
  /* HCLK = SYSCLK */
  RCC_HCLKConfig(RCC_SYSCLK_Div1);

  /* PCLK2 = HCLK */
  RCC_PCLK2Config(RCC_HCLK_Div1);

  /* PCLK1 = HCLK */
  RCC_PCLK1Config(RCC_HCLK_Div1);

  /* Set MSI clock range to 64KHz */
  RCC_MSIRangeConfig(RCC_MSIRange_0);

  /* Select MSI as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);

  /* Wait till PLL is used as system clock source */
  while (RCC_GetSYSCLKSource() != 0x00)
  {}
}
Пример #6
0
/**
  * @brief  Selects MSI (Default Value, 2MHz) as System clock source and configure
  *         HCLK, PCLK2 and PCLK1 prescalers.
  * @param  None
  * @retval None
  */
void SetHCLKToMSI_2MHz(void)
{
  /* RCC system reset */
  RCC_DeInit();

  /* Flash 0 wait state */
  FLASH_SetLatency(FLASH_Latency_0);

  /* Disable Prefetch Buffer */
  FLASH_PrefetchBufferCmd(DISABLE);

  /* Disable 64-bit access */
  FLASH_ReadAccess64Cmd(DISABLE);

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

  /* Select the Voltage Range 3 (1.2V) */
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3);

  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
  {}
}
Пример #7
0
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
      
      while (1)
    {
        
        switch( State ) 
        {
            case 0:
                //LED3 off and LED4 off
                blink = 0;
                GPIOB_ODR_value = 0x00000000;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 1:
                //LED3 on and LED4 off
                blink = 0;
                GPIOB_ODR_value = 0x00000080;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 2:
                //LED3 off and LED4 on
                blink = 0;
                GPIOB_ODR_value = 0x00000040;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 3:
                //LED3 and LED4 blink with 2 second period
                blink = 1;
                break;
        }    
        
        if(blink == 1)
        {
          GPIOB_ODR_value = 0x000000C0;
          ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
          Delay(100);
          GPIOB_ODR_value = 0x00000000;
          ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
          Delay(100);
          
        }
        
    }
    
    
    return(0);
}		
Пример #8
0
/**
  * @brief  Selects HSI as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
  * @param  None
  * @retval None
  */
void SetHCLKToHSI(void)
{
  __IO uint32_t StartUpCounter = 0, HSIStatus = 0;

  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSI */
  RCC_HSICmd(ENABLE);

  /* Wait till HSI is ready and if Time out is reached exit */
  do
  {
    HSIStatus = RCC_GetFlagStatus(RCC_FLAG_HSIRDY);
    StartUpCounter++;
  }
  while ((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));


  if (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != RESET)
  {
    HSIStatus = (uint32_t)0x01;
  }
  else
  {
    HSIStatus = (uint32_t)0x00;
  }

  if (HSIStatus == 0x01)
  {
    /* Flash 0 wait state */
    FLASH_SetLatency(FLASH_Latency_0);

    /* Disable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(DISABLE);

    /* Disable 64-bit access */
    FLASH_ReadAccess64Cmd(DISABLE);

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

    /* Select the Voltage Range 1 (1.8V) */
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);

    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
    {}

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK */
    RCC_PCLK1Config(RCC_HCLK_Div1);

    /* Select HSI as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

    /* Wait till HSI is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x04)
    {}
  }
  else
  { /* If HSI fails to start-up, the application will have wrong clock configuration.
                           User can add here some code to deal with this error */

    /* Go to infinite loop */
    while (1)
    {}
  }
}
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_md.s) before to branch to application main.
          To reconfigure the default setting of SystemInit() function, refer to
          system_stm32l1xx.c file
        */

    /* Configure Clocks for Application need */
    RCC_Configuration();

    /* Configure RTC Clocks */
    RTC_Configuration();

    /* Set internal voltage regulator to 1.8V */
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);

    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

    /* Enable debug features in low power modes (Sleep, STOP and STANDBY) */
#ifdef  DEBUG_SWD_PIN
    DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
#endif

    /* Configure SysTick IRQ and SysTick Timer to generate interrupts */
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 500);

    /* Init I/O ports */
    Init_GPIOs();

    /* Initializes the LCD glass */
    LCD_GLASS_Configure_GPIO();
    LCD_GLASS_Init();

    /* Display Welcome message */

    LCD_GLASS_ScrollSentence("   ** TEMPERATURE SENSOR EXAMPLE **    ",1,SCROLL_SPEED);

    /* Disable SysTick IRQ and SysTick Timer */
    SysTick->CTRL  &= ~ ( SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk );

    /* Test user or factory temperature sensor calibration value */
    if ( testFactoryCalibData() == SUCCESS ) getFactoryTSCalibData(&calibdata);
    else if ( testUserCalibData() == SUCCESS ) calibdata = *USER_CALIB_DATA;
    else {
        /* User calibration or factory calibration TS data are not available */
        calibdata.TS_CAL_1 = DEFAULT_COLD_VAL;
        calibdata.TS_CAL_2 = DEFAULT_HOT_VAL;
        writeCalibData(&calibdata);
        calibdata = *USER_CALIB_DATA;
    }

    /* Configure Wakeup from sleep using RTC event*/
    configureWakeup();

    /* Configure direct memory access for ADC usage*/
    configureDMA();

    /* Configure ADC for temperature sensor value conversion */
    configureADC_Temp();


    while(1) {

        /* Re-enable DMA and ADC conf and start Temperature Data acquisition */
        acquireTemperatureData();

        /* Stay in SLEEP mode untill the data are acquired by ADC */
        __WFI();

        /* for DEBUG purpose uncomment the following line and comment the __WFI call to do not enter STOP mode */
        // while (!flag_ADCDMA_TransferComplete);

        /* Disable ADC, DMA and clock*/
        powerDownADC_Temper();

        /* Process mesured Temperature data - calculate average temperature value in °C */
        processTempData();

        if (flag_UserButton == TRUE) {
            clearUserButtonFlag();
            if (CurrentlyDisplayed == Display_TemperatureDegC)
                CurrentlyDisplayed = Display_ADCval;
            else
                CurrentlyDisplayed = Display_TemperatureDegC;
        }

        if (CurrentlyDisplayed == Display_TemperatureDegC) {
            /* print average temperature value in °C  */
            sprintf(strDisp, "%d °C", temperature_C );
        } else {
            /* print result of ADC conversion  */
            sprintf(strDisp, "> %d", tempAVG );
        }

        LCD_GLASS_Clear();
        LCD_GLASS_DisplayString( (unsigned char *) strDisp );

        /* Enable RTC Wakeup */
        RTC_WakeUpCmd(ENABLE);

        /* Clear WakeUp flag */
        PWR_ClearFlag(PWR_FLAG_WU);

        /* Enter in wait for interrupt stop mode*/
        PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

        RCC_Configuration();  // reinitialize clock

        /* After Wake up : Disable Wake up from RTC*/
        RTC_WakeUpCmd(DISABLE);
    }

}
Пример #10
0
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
    // EECE 337 Code -- Start
    int N;
    int f;
    
    char str[8];   
    
    N = 10;
    
    // Call to original factorial algorithm in C - for debugging
    //f = factorial_orig( N );
    
    factorial(&f, N);
    
    // Copy result to f
    sprintf (str, "%X", f);
    
    //printf( "factorial of %i is %i\n", N, f);
    LCD_GLASS_DisplayString(str);
    
    // EECE 337 Code -- End
    
    return(0);
}		
Пример #11
0
/**
  * @brief Current measurement in different MCU modes:
  * RUN/SLEEP/LowPower/STANDBY with/without RTC
  * @caller main and ADC_Icc_Test
  * @param MCU state
  * @retval ADC value.
  */
uint16_t ADC_Icc_Test(uint8_t Mcu_State)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  uint16_t adc_measure;
  uint32_t i;
  RCC_TypeDef SavRCC;
  /* Reset UserButton State */
  UserButton = FALSE;
  /* Start counter */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  /* Disable the RTC Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, DISABLE);
  /* Disable LCD */
  LCD_Cmd(DISABLE);
  /* wait until LCD disable */
  while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET);
  /*Reset Idd-WakeUP flag*/
  Idd_WakeUP = FALSE;
  /* Set IO in lowpower configuration*/
  GPIO_LowPower_Config(); 
  /*Disable fast wakeUp*/
  PWR_FastWakeUpCmd(DISABLE);
  
/* Test MCU state for configuration */
  switch (Mcu_State)
  {
    /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/	
    case MCU_RUN:
        /* switch on MSI clock */
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        /* shitch on MSI clock */
        Config_RCC(&SavRCC);    
        SysTick->CTRL = 0;     
        RCC->APB1ENR = 0;

        /* To run nops during measurement:
        it's the best case for low current */     

        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;

    /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/
    case MCU_SLEEP:
         
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        Config_RCC(&SavRCC);  
        Config_Systick_50ms();
        Delay(1);

       /* Request Wait For Interrupt */
        PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI);   
           
        break;    

   /* RUN LOW POWER mode :   Measurement performed with MSI 32 Khz without RTC */
    case MCU_LP_RUN:
      
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);

        /* Enable The ultra Low Power Mode */
        PWR_UltraLowPowerCmd(ENABLE);         

        /* Save the RCC configuration registers */
        Config_RCC(&SavRCC);      
        
        /* Stop the sys tick in order to avoid IT */
        SysTick->CTRL = 0; 
        
#ifdef TESTINRAM        
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; 
        
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;  

        DisableInterrupts();
        EnterLPRUNModeRAM();
        EnableInterrupts();        
#else         
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ;    
                
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;              
        
        /* Launch the counter */
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);           
           
        /* To run the nop during measurement:
        it's the best case for low current
        until counter reach detected by IT --> Idd_WakeUP */
        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();            
        }  while (Idd_WakeUP == FALSE );       
#endif        
        
        PWR_EnterLowPowerRunMode(DISABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ;  
    
        break; 
      
      /* SLEEP LOW POWER mode
         Measurement done to MSI 32 Khz without RTC
      */	
      case MCU_LP_SLEEP:
        
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);   
        
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);

                
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);     
        
        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
        
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;

#ifdef TESTINRAM
        DisableInterrupts();
        EnterLPSLEEPModeRAM();
        EnableInterrupts();
#else        
        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

        /* Request Wait For Interrupt */    
        PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI);
#endif              
        break;   
        
      /* STOP modes
       Measurement done to MSI 32 Khz without or with RTC
       */		
      case MCU_STOP_NoRTC:
      case MCU_STOP_RTC:

        /* Disable PVD */
        PWR_PVDCmd(DISABLE);
          
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);           
        
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);  

        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
               
       /* Swith in MSI 32KHz */
        if( Mcu_State == MCU_STOP_NoRTC )
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;
        else
         SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ;          

        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
        
        /* Request Wait For Interrupt */    
        PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);              

        break;        
          
        /* Standby mode without RTC
          Measurement done to MSI 32 Khz without RTC
        */
        case MCU_STBY:
          
          /* Disable PVD */
          PWR_PVDCmd(DISABLE);
          
          /* Enable Ultra low power mode */
          PWR_UltraLowPowerCmd(ENABLE);
          
          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_Pin = GPIO_Pin_0  ;
          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_Init( GPIOA, &GPIO_InitStructure);
          
         GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ;
          //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ;
          Config_RCC(&SavRCC);  
          
          SysTick->CTRL = 0; 
                  
          /* Swith in MSI 32KHz */
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;     
          
          PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);
          
          PWR_UltraLowPowerCmd(ENABLE); 
          
           PWR_EnterSTANDBYMode();
          /* Stop here WakeUp EXIT on RESET */
        
        break;
      }
  
  SetHSICLK();  

  Config_Systick(); 
  RCC->AHBENR = SavRCC.AHBENR;	
         
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

   /* Read ADC for current measurmeent */
   adc_measure = Current_Measurement();
    
  /* ICC_CNT_EN Hi */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  UserButton = TRUE;

  /* To restore RCC registers */
  RCC->APB1ENR = SavRCC.APB1ENR;
  RCC->APB2ENR = SavRCC.APB2ENR; 
  RCC->AHBLPENR = SavRCC.AHBLPENR;	
  RCC->APB1LPENR = SavRCC.APB1LPENR;
  RCC->APB2LPENR = SavRCC.APB2LPENR;
  
  /* Need to reinit RCC for LCD*/
  RCC_Configuration();

  PWR_EnterLowPowerRunMode(DISABLE);
  
  /* Disable Ultra low power mode */
  PWR_UltraLowPowerCmd(DISABLE);
  
  /* Disable FLASH during SLeep LP */
  FLASH_SLEEPPowerDownCmd(DISABLE);
  
  Restore_GPIO_Config();  
 
  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
  
  /* Enable PVD */
  PWR_PVDCmd(ENABLE);

  LCD_GLASS_Init();
   
  return (adc_measure);
}
Пример #12
0
/**
  * @brief  This function configures the system to enter Low Power Run mode for
  *         current consumption measurement purpose.
  *         The maximum clock when the system is in Low Power Run mode is ~128KHz.
  *         This mode can only be entered when Voltage Range 2 is selected. 
  *         Low Power Run Mode from SRAM:
  *         =============================
  *           - 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  
  *         Low Power Run Mode from FLASH:
  *         ==============================
  *           - 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   
  * @param  None
  * @retval None
  */
void LowPowerRunMode_Measure(void)
{
  /* Configure the System Clock to MSI Range 0 (65KHz). ----------------------*/

  /* RCC system reset */
  RCC_DeInit();
  
  /* Flash 0 wait state */
  FLASH_SetLatency(FLASH_Latency_0);
    
  /* Disable Prefetch Buffer */
  FLASH_PrefetchBufferCmd(DISABLE);

  /* Disable 64-bit access */
  FLASH_ReadAccess64Cmd(DISABLE);

  /* Enable the PWR APB1 Clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  
  /* Select the Voltage Range 2 (1.5V) */
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
  
  /* Wait Until the Voltage Regulator is ready */
  while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
  {
  }
        
  /* HCLK = SYSCLK/2 = ~32KHz */
  RCC_HCLKConfig(RCC_SYSCLK_Div2);

  /* PCLK2 = HCLK */
  RCC_PCLK2Config(RCC_HCLK_Div1);

  /* PCLK1 = HCLK */
  RCC_PCLK1Config(RCC_HCLK_Div1);

  /* Set MSI clock range to 65.536KHz */
  RCC_MSIRangeConfig(RCC_MSIRange_0);
  
  /* Select MSI as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);

  /* Wait till PLL is used as system clock source */
  while (RCC_GetSYSCLKSource() != 0x00)
  {} 
  
  /* Configure all GPIO as analog to reduce current consumption on non used IOs */
  /* Enable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_Init(GPIOH, &GPIO_InitStructure);
  GPIO_Init(GPIOF, &GPIO_InitStructure);
  GPIO_Init(GPIOG, &GPIO_InitStructure);  
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
  GPIO_Init(GPIOB, &GPIO_InitStructure);   

  /* Disable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE);

  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO);

  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
  {
  }
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }
  /* Enter RUN LP Mode */
  PWR_EnterLowPowerRunMode(ENABLE);

  /* Wait until the system enters RUN LP and the Regulator is in LP mode */
  while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET)
  {
  }

/* Jump to Internal SRAM and Switch the internal FLASH OFF */
#if defined (LP_RUN_SRAM_MODE)
  LowPowerRunModeSRAM_Measure();
  
#elif defined (LP_RUN_FLASH_MODE)
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
  {
  }
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }
#endif
 

  /* Exit the RUN LP Mode */	
  PWR_EnterLowPowerRunMode(DISABLE);
  
  /* Wait until the system exits RUN LP and the Regulator is in main mode */
  while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET)
  {
  }   

  
  /* Infinite loop */  
  while (1)
  {    
  }
}
Пример #13
0
/**
  * @brief  This function configures the system to enter Low Power Sleep mode for
  *         current consumption measurement purpose.
  *         The maximum clock when the system is in Low Power Run mode is ~128KHz.
  *         This mode can only be entered when Voltage Range 2 is selected. 
  *         Low Power Sleep Mode
  *         ====================   
  *           - 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)      
  * @param  None
  * @retval None
  */
void LowPowerSleepMode_Measure(void)
{
  /* Configure the System Clock to MSI Range 0 (65KHz). ----------------------*/

  /* RCC system reset */
  RCC_DeInit();
  
  /* Flash 0 wait state */
  FLASH_SetLatency(FLASH_Latency_0);
    
  /* Disable Prefetch Buffer */
  FLASH_PrefetchBufferCmd(DISABLE);    

  /* Disable 64-bit access */
  FLASH_ReadAccess64Cmd(DISABLE);

  /* Enable the PWR APB1 Clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  
  /* Select the Voltage Range 2 (1.5V) */
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
  
  /* Wait Until the Voltage Regulator is ready */
  while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
  {
  }
        
  /* HCLK = SYSCLK/2 = ~32KHz */
  RCC_HCLKConfig(RCC_SYSCLK_Div2);

  /* PCLK2 = HCLK */
  RCC_PCLK2Config(RCC_HCLK_Div1);

  /* PCLK1 = HCLK */
  RCC_PCLK1Config(RCC_HCLK_Div1);

  /* Set MSI clock range to 65.536KHz */
  RCC_MSIRangeConfig(RCC_MSIRange_0);
  
  /* Select MSI as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);

  /* Wait till PLL is used as system clock source */
  while (RCC_GetSYSCLKSource() != 0x00)
  {} 
  
  /* Configure all GPIO as analog to reduce current consumption on non used IOs */  
  /* Enable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_Init(GPIOH, &GPIO_InitStructure);
  GPIO_Init(GPIOF, &GPIO_InitStructure);
  GPIO_Init(GPIOG, &GPIO_InitStructure);  
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Disable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE);

  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO);

  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
  {
  }
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }

  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_EXTI);
  
  /* Enable The ultra Low Power Mode */
  PWR_UltraLowPowerCmd(ENABLE);
  
  /* Enable the power down mode during Sleep mode */
  FLASH_SLEEPPowerDownCmd(ENABLE);
  
  /* Request to enter SLEEP mode with regulator in low power mode */
  PWR_EnterSleepMode(PWR_Regulator_LowPower, PWR_SLEEPEntry_WFI);

  /* Initialize LED1 on STM32L152-EVAL board */
  STM_EVAL_LEDInit(LED1);
  

  /* Infinite loop */
  while (1)
  {
    /* Toggle The LED1 */
    STM_EVAL_LEDToggle(LED1);

    /* Inserted Delay */
    for(index = 0; index < 0x5FF; index++);
  }
}
Пример #14
0
/**
  * @brief  This function configures the system to enter Sleep mode for
  *         current consumption measurement purpose.
  *         Sleep Mode
  *         ==========  
  *            - 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)   
  * @param  None
  * @retval None
  */
void SleepMode_Measure(void)
{
  /* Configure System Clock to HSI (16MHz) */
  __IO uint32_t StartUpCounter = 0, HSIStatus = 0;
    
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSI */
  RCC_HSICmd(ENABLE);

  /* Wait till HSI is ready and if Time out is reached exit */
  do
  {
    HSIStatus = RCC_GetFlagStatus(RCC_FLAG_HSIRDY);
    StartUpCounter++;  
  } while((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));


  if (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != RESET)
  {
    HSIStatus = (uint32_t)0x01;
  }
  else
  {
    HSIStatus = (uint32_t)0x00;
  } 

  if (HSIStatus == 0x01)
  {
    /* Enable 64-bit access */
    FLASH_ReadAccess64Cmd(ENABLE);
   
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(ENABLE);
  
    /* Flash 1 wait state */
    FLASH_SetLatency(FLASH_Latency_1);    

    /* Enable the PWR APB1 Clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  
    /* Select the Voltage Range 2 (1.5V) */
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
  
    /* Wait Until the Voltage Regulator is ready */
    while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
    {
    } 

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK */
    RCC_PCLK1Config(RCC_HCLK_Div1);

    /* Select HSI as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

    /* Wait till HSI is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x04)
    {}
  }
  else
  { 
    /* If HSI fails to start-up, the application will have wrong clock configuration.
    User can add here some code to deal with this error */

    /* Go to infinite loop */
    while (1)
    {}
  }

  /* Configure all GPIO as analog to reduce current consumption on non used IOs */
  /* Enable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_Init(GPIOH, &GPIO_InitStructure);
  GPIO_Init(GPIOF, &GPIO_InitStructure);
  GPIO_Init(GPIOG, &GPIO_InitStructure);  
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
  GPIO_Init(GPIOB, &GPIO_InitStructure);   

  /* Disable GPIOs clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
                        RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH |
                        RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE);

  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO);

  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
  {
  }
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }

  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_EXTI);

  /* Request to enter SLEEP mode with regulator ON */
  PWR_EnterSleepMode(PWR_Regulator_ON, PWR_SLEEPEntry_WFI);

  /* Initialize LED1 on STM32L152-EVAL board */
  STM_EVAL_LEDInit(LED1);

  /* Infinite loop */
  while (1)
  {
    /* Toggle The LED1 */
    STM_EVAL_LEDToggle(LED1);

    /* Inserted Delay */
    for(index = 0; index < 0x5FFFF; index++);
  }
}
Пример #15
0
static void prvSetupHardware( void )
{
/* GPIO, EXTI and NVIC Init structure declaration */
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
void SystemCoreClockUpdate( void );

	/* System function that updates the SystemCoreClock variable. */
	SystemCoreClockUpdate();

	/* Essential on STM32 Cortex-M devices. */
	NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

	/* Systick is fed from HCLK/8. */
	SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK_Div8 );

	/* Set MSI clock range to ~4.194MHz. */
	RCC_MSIRangeConfig( RCC_MSIRange_6 );

	/* Enable the GPIOs clocks. */
	RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOD| RCC_AHBPeriph_GPIOE| RCC_AHBPeriph_GPIOH, ENABLE );

	/* Enable comparator clocks. */
	RCC_APB1PeriphClockCmd( RCC_APB1Periph_COMP, ENABLE );

	/* Enable SYSCFG clocks. */
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_SYSCFG , ENABLE );

	/* Set internal voltage regulator to 1.5V. */
	PWR_VoltageScalingConfig( PWR_VoltageScaling_Range2 );

	/* Wait Until the Voltage Regulator is ready. */
	while( PWR_GetFlagStatus( PWR_FLAG_VOS ) != RESET );

	/* Configure User Button pin as input */
	GPIO_InitStructure.GPIO_Pin = USERBUTTON_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
	GPIO_Init( USERBUTTON_GPIO_PORT, &GPIO_InitStructure );

	/* Select User Button pin as input source for EXTI Line */
	SYSCFG_EXTILineConfig( EXTI_PortSourceGPIOA, EXTI_PinSource0 );

	/* Configure EXT1 Line 0 in interrupt mode trigged on Rising edge */
	EXTI_InitStructure.EXTI_Line = EXTI_Line0 ;  /* PA0 for User button AND IDD_WakeUP */
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init( &EXTI_InitStructure );

	/* Enable and set EXTI0 Interrupt to the lowest priority */
	NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init( &NVIC_InitStructure );

	/* Configure the LED_pin as output push-pull for LD3 & LD4 usage */
	GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init( LD_GPIO_PORT, &GPIO_InitStructure );

	/* Force a low level on LEDs */
	GPIO_LOW( LD_GPIO_PORT, LD_GREEN_GPIO_PIN );
	GPIO_LOW( LD_GPIO_PORT, LD_BLUE_GPIO_PIN );
}
Пример #16
0
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
    // EECE 337 Code -- Start
        
    char str[50];                       // Used to display results
    unsigned int delay_time = 5000;      // Will delay for 5 seconds
    const unsigned int numItems = 10;          // # items in array
	int MyArray[10] = { 365, 245, -499, 0, 23, 8, 200, -4, -50, 25 };

	int minimum = 0;                    // Will hold minimum value
	int maximum = 0;                    // Will hold maximum value
    
    // Call Function to obtain Min and Max values from array
	min_max(MyArray, numItems, &minimum, &maximum);	
    
    // Copy min result to str
    sprintf (str, "%d", minimum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // Clear LCD
    LCD_GLASS_Clear();
    
    // Copy max result to str
    sprintf (str, "%d", maximum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // EECE 337 Code -- End
    
    return(0);
}