/**
  @page PWR_CurrentConsumption PWR Current Consumption example
  
  @verbatim
  ******************** (C) COPYRIGHT 2012 STMicroelectronics *******************
  * @file    PWR/CurrentConsumption/readme.txt 
  * @author  MCD Application Team
  * @version V1.1.1
  * @date    13-April-2012
  * @brief   Description of the PWR Current Consumption example.
  ******************************************************************************
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
   @endverbatim

@par Example Description 

This example shows how to configure the STM32L1xx system to measure different
Ultra Low Power modes current consumption. The Ultra Low Power modes are:
  - Low Power Run Mode from Internal SRAM
  - Low Power Run Mode from Internal FLASH
  - Sleep Mode
  - Low Power Sleep Mode
  - STOP mode with or without RTC
  - STANDBY mode with or without RTC

To run this example, user has to follow the following steps:
 1. Select the Ultra Low power modes to be measured by uncommenting the corresponding
    line inside the stm32l1xx_ulp_modes.h file.
       #define LP_RUN_SRAM_MODE
       #define LP_RUN_FLASH_MODE
       #define SLEEP_MODE
       #define LP_SLEEP_MODE
       #define STOP_MODE
       #define STOP_RTC_LSE_MODE
       #define STOP_RTC_LSI_MODE
       #define STANDBY_MODE
       #define STANDBY_RTC_LSE_MODE
       #define STANDBY_RTC_LSI_MODE  
  
 2. Use an external amperemeter to measure the IDD current. 
 
 3. This example can not be used in DEBUG mode as the JTAG IOs are disabled to
    reduce power consumption.
    
Here below a detailed description of the example code:

  @verbatim
 1. First, the  code checks if the BOR is disabled or not. If the BOR is ON, the 
    code writes to Option Bytes and launch and Option byte loading phase generating
    a system reset.

 2. After reset, the program waits for Key button connected to the PA.00 to be 
    pressed to enter the selected ultra low power mode.
     - When the RTC is not used in the ultra low power mode configuration, press
       again the Key button to exit the low power mode.
     - When the RTC is used, the wakeup from low power mode is automatically 
       generated by the RTC (after 4s).

 3. Ultra Low power modes description:

    - Low Power Run mode:
    ===================== 
      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
            - Regulator in LP mode
            - 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
            - Regulator in LP mode
            - Code running from Internal FLASH
            - All peripherals OFF
            - VDD from 1.65V to 3.6V
            - Current Consumption ~25uA  
            - Wakeup using Key Button PA.00
                        
    - 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)
                         
    - Low Power Sleep Mode
    ======================
       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. 
            - System Running at MSI (~32KHz)
            - Flash 0 wait state
            - Voltage Range 2
            - Regulator in LP mode            
            - Code running from Internal FLASH
            - All peripherals OFF
            - FLASH in Power Down mode
            - VREFINT OFF
            - VDD from 1.65V to 3.6V
            - Current Consumption ~4.07uA
            - Wakeup using EXTI Line (Key Button PA.00)
            
    - STOP Mode
    ===========
            - Regulator in LP mode
            - VREFINT OFF            
            - LSI, HSI and HSE OFF
            - No IWDG
            - Current Consumption ~0.5uA
            - Wakeup using EXTI Line (Key Button PA.00)
                        
    - STOP Mode with RTC clocked by LSE
    ===================================   
            - RTC Clocked by LSE external Clock (32.768KHz)
            - Regulator in LP mode
            - VREFINT OFF
            - LSI, HSI and HSE OFF
            - No IWDG
            - Current Consumption ~1.6uA
            - Automatic Wakeup using RTC on LSE (after 4s)
                        
    - STOP Mode with RTC clocked by LSI
    ===================================  
            - RTC Clocked by LSI
            - Regulator in LP mode
            - VREFINT OFF
            - HSI and HSE OFF
            - No IWDG
            - Current Consumption ~1.3uA
            - Automatic Wakeup using RTC on LSI (after ~4s)
                        
    - STANDBY Mode
    ==============
            - IWDG and LSI OFF
            - VREFINT OFF            
            - Current Consumption ~0.3uA
            - Wakeup using WakeUp Pin 1 (PA.00)
                        
    - STANDBY Mode with RTC clocked by LSE 
    ======================================
            - RTC Clocked by LSE external Clock (32.768KHz)
            - IWDG and LSI OFF
            - VREFINT OFF            
            - Current Consumption ~1.3uA
            - Automatic Wakeup using RTC on LSE (after 4s)
            
    - STANDBY Mode with RTC clocked by LSI
    ======================================   
            - RTC Clocked by LSI
            - IWDG OFF
            - VREFINT OFF            
            - Current Consumption ~1.1uA
            - Automatic Wakeup using RTC on LSI (after ~4s)                                   
                         
  4. After reset the system clock frequency is configured to MSI Range 1 (~131KHz)
     and Voltage range 2 and then according to each ultra low power mode the system
     frequency is reconfigured again.

   @endverbatim

@note The STM32L152-EVAL board contains an automatic IDD measurement circuit using
      internal ADC. The associated software allowing the automatic IDD measurement
      is provided with STM32L152-EVAL board demonstration firmware.
      For more details, refer to UM1009 available on <a href="http://www.st.com/internet/mcu/family/141.jsp">  ST Microcontrollers </a>      

@par Directory contents 

  - PWR/CurrentConsumption/stm32l1xx_conf.h              Library Configuration file
  - PWR/CurrentConsumption/stm32l1xx_it.c                Interrupt handlers
  - PWR/CurrentConsumption/stm32l1xx_it.h                Interrupt handlers header file
  - PWR/CurrentConsumption/main.c                        Main program
  - PWR/CurrentConsumption/system_stm32l1xx.c            STM32L1xx system source file
  - PWR/CurrentConsumption/stm32l1xx_ulp_modes.c         STM32L1xx Ultra Low Power Modes source file
  - PWR/CurrentConsumption/stm32l1xx_ulp_modes.h         STM32L1xx Ultra Low Power Modes header file
  - PWR/CurrentConsumption/stm32l1xx_lowpowerrun_sram.c  STM32L1xx Low Power Run Mode from Internal SRAM source file  
  
@note The "system_stm32l1xx.c" is generated by an automatic clock configuration 
      system and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32L1xx_Clock_Configuration_V1.1.0.xls" 
      provided with the AN3309 package available on <a href="http://www.st.com/internet/mcu/family/141.jsp">  ST Microcontrollers </a>
         
@par Hardware and Software environment

  - This example runs on STM32L1xx Ultra Low Power High-, Medium-Density and Medium-Density Plus Devices.
  
  - This example has been tested with STMicroelectronics STM32L152D-EVAL (STM32L1xx 
    Ultra Low Power High-Density) and STM32L152-EVAL (STM32L1xx Ultra Low 
    Power Medium-Density) evaluation board and can be easily tailored to any 
    other supported device and development board.

  - STM32L152-EVAL Set-up
    - Use LED1 connected  to PD.00 pin.
    - Use Key Button connected to PA.00 pin.
    - Connect an amperemeter to JP4 (1<->2 position) to measure the IDD current

  - STM32L152D-EVAL Set-up
    - Use LED1 connected  to PD.03 pin.
    - Use Key Button connected to PA.00 pin.
    - Connect an amperemeter to JP10 (1<->2 position) to measure the IDD current
      
@par How to use it ? 

In order to make the program work, you must do the following :
 - Copy all source files from this example folder to the template folder under
   Project\STM32L1xx_StdPeriph_Templates
 - Open your preferred toolchain 
 - Add the required example files
   - stm32l1xx_ulp_modes.c 
   - stm32l1xx_lowpowerrun_sram.c

@note The stm32l1xx_lowpowerrun_sram.c and stm32l1xx_flash_ramfunc.c files should 
      be placed in Internal SRAM.

  @verbatim
      ARM Compiler
      ------------
      RAM functions are defined using the toolchain options. 
      Functions that are be executed in RAM should reside in a seperate
      source module. Using the 'Options for File' dialog you can simply change
      the 'Code / Const' area of a module to a memory space in physical RAM.
      Available memory areas are declared in the 'Target' tab of the 
      'Options for Target' dialog.

      ICCARM Compiler
      ---------------
      RAM functions are defined using a specific toolchain keyword "__ramfunc".  
        
      GNU Compiler
       ------------
      RAM functions are defined using a specific toolchain attribute
      "__attribute__((section(".data")))".
 
      TASKING Compiler
      ----------------
      RAM functions are defined using a specific toolchain pragma. This 
      pragma is defined inside this file.
        
   @endverbatim
   
 - Rebuild all files and load your image into target memory
 - Run the example

@note
- Ultra Low Power Medium-density devices are STM32L151xx and STM32L152xx 
  microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
- Ultra Low Power Medium-density Plus devices are STM32L151xx, STM32L152xx and 
  STM32L162xx microcontrollers where the Flash memory density is 256 Kbytes.
- Ultra Low Power High-density devices are STM32L151xx, STM32L152xx and STM32L162xx 
  microcontrollers where the Flash memory density is 384 Kbytes.
    
 * <h3><center>&copy; COPYRIGHT STMicroelectronics</center></h3>
 */


