Beispiel #1
0
/**
  * @brief  Bias measurement using IDD stop mode measurement program.
  * @param  None
  * @retval None
  */
void IDD_Measurement_Calibrate(void)
{
  uint16_t pressedkey = 0x00;

  /* Disable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(DISABLE);
  
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_DisplayStringLine(LCD_LINE_0, "Current Bias Value  "); 
  LCD_DisplayStringLine(LCD_LINE_1, "stored in DATAEEPROM");
  IDD_Measurement_ADC_DisplayValue((*(__IO uint16_t *)DATA_EEPROM_BIAS_ADDR), STM32L_MODE_BIAS);
  LCD_DisplayStringLine(LCD_LINE_2, Str);
  LCD_DisplayStringLine(LCD_LINE_5, "  To Start Bias     ");
  LCD_DisplayStringLine(LCD_LINE_6, "measurement press   ");  
  LCD_DisplayStringLine(LCD_LINE_7, "SEL push-button.    ");    
  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "exit.               ");

  pressedkey = Menu_ReadKey();
  while (pressedkey == NOKEY)
  {
    pressedkey = Menu_ReadKey();
  }
   
  if (pressedkey != SEL)
  {
    /* Enable the JoyStick interrupts */
    Demo_IntExtOnOffConfig(ENABLE);
    /* Display the previous menu */
    Menu_DisplayMenu();
    return;
  }
  
  LCD_Clear(LCD_COLOR_WHITE);  
  LCD_DisplayStringLine(LCD_LINE_0, "MCU will be in STOP "); 
  LCD_DisplayStringLine(LCD_LINE_1, "  Bias Measurement  ");
  LCD_DisplayStringLine(LCD_LINE_2, " Make sure that JP4 ");
  LCD_DisplayStringLine(LCD_LINE_3, " in position 1<->2  ");
  
  LCD_DisplayStringLine(LCD_LINE_7, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_8, "continue.           ");
  
  LCD_GLASS_DisplayString("  BIAS  ");
  
  while (Menu_ReadKey() == NOKEY)
  {}
  
  IDD_Measurement(STM32L_STOP, RTC_STATE_OFF, BIAS_CALIB_ON);
}
Beispiel #2
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 IDD_Measurement_Sleep(void)
{
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_GLASS_DisplayString(" SLEEP  ");
  LCD_DisplayStringLine(LCD_LINE_0, "     SLEEP Mode     ");
  LCD_DisplayStringLine(LCD_LINE_2, "Run at System Clock ");
  LCD_DisplayStringLine(LCD_LINE_3, "16MHz, RTC ON, all  ");
  LCD_DisplayStringLine(LCD_LINE_4, "peripherals OFF and ");
  LCD_DisplayStringLine(LCD_LINE_5, "I/Os in Analog input");

  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "continue.           ");
  while (Menu_ReadKey() == NOKEY)
  {}

  LCD_DisplayStringLine(LCD_LINE_0, " MCU in SLEEP Mode  ");
  LCD_DisplayStringLine(LCD_LINE_8, "Press KEY button to ");
  LCD_DisplayStringLine(LCD_LINE_9, "wakeup.             ");

  /* STM32L Low Power Mode Selection */
  IDD_Measurement(STM32L_SLEEP, RTC_STATE_ON, BIAS_CALIB_OFF);
}
Beispiel #3
0
/**
  * @brief  Selects the RTC State during low power modes. RTC could be ON or OFF.
  * @param  None
  * @retval RTC state during low power modes.
  *            - RTC_STATE_ON: RTC ON during low power modes.
  *            - RTC_STATE_OFF: RTC OFF during low power modes.    
  */
uint32_t IDD_Measurement_SelectRTCState(void)
{
  uint8_t pressedkey = NOKEY;
  
  LCD_DisplayStringLine(LCD_LINE_0, "   RTC ON or OFF    ");
  LCD_DisplayStringLine(LCD_LINE_1, "ON: Press SEL       ");
  LCD_DisplayStringLine(LCD_LINE_2, "OFF: Press Any Key  ");

  pressedkey = Menu_ReadKey();
  while (pressedkey == NOKEY)
  {
    pressedkey = Menu_ReadKey();
  }

  if(pressedkey == SEL)
  {
    return RTC_STATE_ON;   
  }
  else
  {
    return RTC_STATE_OFF;    
  }  
}
Beispiel #4
0
/**
  * @brief  Displays the Standby IDD value after woken-up from Standby mode.
  * @param  None
  * @retval None
  */
void IDD_Measurement_DisplayStandby(void)
{   
  while (Menu_ReadKey() != NOKEY)
  {}
 
  IDD_Measurement_ADC_DisplayValue((*(__IO uint16_t *)DATA_EEPROM_STBY_ADDR), STM32L_MODE_LP);
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);
    
  LCD_DisplayStringLine(LCD_LINE_1, "    Standby Mode    ");
  LCD_DisplayStringLine(LCD_LINE_3, Str);
  LCD_DisplayStringLine(LCD_LINE_5, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_6, "continue.           ");
  
  while (Menu_ReadKey() == NOKEY)
  {}

  /* Disable ADC1 */
  ADC_Cmd(ADC1, DISABLE);
}
Beispiel #5
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
  *           - RTC could be ON or 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 IDD_Measurement_SleepLP(void)
{
  uint8_t rtcstate;

  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_GLASS_DisplayString("SLEEP LP");

  rtcstate =  IDD_Measurement_SelectRTCState();

  LCD_DisplayStringLine(LCD_LINE_0, "MCU will be in SLEEP");
  LCD_DisplayStringLine(LCD_LINE_1, "       LP Mode      ");
  LCD_DisplayStringLine(LCD_LINE_2, "Run at MSI 32KHz all");
  LCD_DisplayStringLine(LCD_LINE_3, "peripherals OFF,    ");
  LCD_DisplayStringLine(LCD_LINE_4, "all I/O in Analog   ");
  LCD_DisplayStringLine(LCD_LINE_5, "input and  RTC ON.  ");

  if(rtcstate == RTC_STATE_ON)
  {
    LCD_DisplayStringLine(LCD_LINE_5, "input and  RTC ON.  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_5, "input and  RTC OFF.  ");
  }

  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "continue.           ");
  while (Menu_ReadKey() == NOKEY)
  {}

  /* STM32L Low Power Mode Selection */
  IDD_Measurement(STM32L_SLEEP_LP, rtcstate, BIAS_CALIB_OFF);
}
Beispiel #6
0
/**
  * @brief  RCR receiver demo exec.
  * @param  None
  * @retval None
  */
void Menu_RC5Decode_Func(void)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  
  /* Disable the TIM15, LED Toggling  */
  TIM_Cmd(TIM15, DISABLE);
  
  /* Disable the JoyStick interrupt */
  Demo_IntExtOnOffCmd(DISABLE);
  
  while (Menu_ReadKey() != NOKEY)
  {}
  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_WHITE);   
  
  /* Display Image */
  LCD_SetDisplayWindow(120, 192, 64, 64);
  Storage_OpenReadFile(120, 192, "STFILES/TV.BMP");  
  LCD_WindowModeDisable();
  
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_BLUE);
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_9, "  To exit press UP  ");
  
  /* Initialize the InfraRed application: RC5 */
  RFDemoStatus = RC5DEMO; 
  RC5_Init();
  
  while(Menu_ReadKey() != UP)
  {   
    /* Decode the RC5 frame */
    RC5_Decode(&RC5_FRAME);
  }
  
  LCD_Clear(LCD_COLOR_WHITE);
  
  TIM_DeInit(TIM2);
  /* Time Base configuration 100ms*/
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  TIM_TimeBaseStructure.TIM_Prescaler = 1000;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 0x0C80;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  
  /* Channel 1, 2, 3 and 4 Configuration in Timing mode */
  TIM_OCStructInit(&TIM_OCInitStructure);
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0x0;  
  TIM_OC1Init(TIM2, &TIM_OCInitStructure);
 
  Demo_LedShow(ENABLE);
  
  /* Exit the RF5 demo */
  RFDemoStatus = 0;
  
  /* Enable the JoyStick interrupt */
  Demo_IntExtOnOffCmd(ENABLE);
  
  /* Display menu */
  Menu_DisplayMenu();
}
Beispiel #7
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(); 
}
Beispiel #8
0
/**
  * @brief  Reset the Bias measurement value stored in Data EEPROM.
  * @param  None
  * @retval None
  */
void IDD_Measurement_Bias_Reset(void)
{
  uint8_t pressedkey = 0;
  
  /* Disable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(DISABLE);
  
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_DisplayStringLine(LCD_LINE_0, "Current Bias Value  "); 
  LCD_DisplayStringLine(LCD_LINE_1, "stored in DATAEEPROM");
  IDD_Measurement_ADC_DisplayValue((*(__IO uint16_t *)DATA_EEPROM_BIAS_ADDR), STM32L_MODE_BIAS);
  LCD_DisplayStringLine(LCD_LINE_2, Str);
  LCD_DisplayStringLine(LCD_LINE_5, "  To reset Bias     ");
  LCD_DisplayStringLine(LCD_LINE_6, "measurement press   ");  
  LCD_DisplayStringLine(LCD_LINE_7, "SEL push-button.    ");    
  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "exit.               ");

  pressedkey = Menu_ReadKey();
  while (pressedkey == NOKEY)
  {
    pressedkey = Menu_ReadKey();
  }
   
  if (pressedkey != SEL)
  {
    /* Enable the JoyStick interrupts */
    Demo_IntExtOnOffConfig(ENABLE);
    /* Display the previous menu */
    Menu_DisplayMenu();
    return;
  }
 
  LCD_Clear(LCD_COLOR_WHITE);

  /* Unlock EEPROM write access. */
  DATA_EEPROM_Unlock();
  
  /* Store the value in EEPROM for application needs. */
  DATA_EEPROM_ProgramHalfWord(DATA_EEPROM_BIAS_ADDR, 0x0);
  
  /* Lock back EEPROM write access. */
  DATA_EEPROM_Lock();

  LCD_DisplayStringLine(LCD_LINE_1, "  Bias Measurement  ");
  LCD_DisplayStringLine(LCD_LINE_2, " Bias Value is reset");
  LCD_DisplayStringLine(LCD_LINE_3, " to 0x0.            ");
    
  LCD_DisplayStringLine(LCD_LINE_7, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_8, "continue.           ");

  LCD_GLASS_DisplayString(" STM32L ");
  while (Menu_ReadKey() == NOKEY)
  {}

  /* Enable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(ENABLE);
  
  /* Display the previous menu */
  Menu_DisplayMenu();
}