Restructure libs source to support multi platform
[fw/stlink] / example / libstm32l_discovery / src / stm32l1xx_flash.c
diff --git a/example/libstm32l_discovery/src/stm32l1xx_flash.c b/example/libstm32l_discovery/src/stm32l1xx_flash.c
deleted file mode 100644 (file)
index 2fa60a7..0000000
+++ /dev/null
@@ -1,1335 +0,0 @@
-/**\r
-  ******************************************************************************\r
-  * @file    stm32l1xx_flash.c\r
-  * @author  MCD Application Team\r
-  * @version V1.0.0\r
-  * @date    31-December-2010\r
-  * @brief   This file provides all the Flash firmware functions. These functions \r
-  *          can be executed from Internal FLASH or Internal SRAM memories. \r
-  *          The functions that should be called from SRAM are defined inside \r
-  *          the "stm32l1xx_flash_ramfunc.c" file.\r
-  *          This file provides firmware functions to manage the following \r
-  *          functionalities of the FLASH peripheral:\r
-  *            - FLASH Interface configuration\r
-  *            - FLASH Memory Programming\r
-  *            - DATA EEPROM Programming\r
-  *            - Option Bytes Programming\r
-  *            - Interrupts and flags management\r
-  *               \r
-  *  @verbatim\r
-  *  \r
-  *          ===================================================================\r
-  *                                 How to use this driver\r
-  *          ===================================================================\r
-  *                           \r
-  *          This driver provides functions to configure and program the Flash \r
-  *          memory of all STM32L1xx devices\r
-  *          These functions are split in 5 groups\r
-  * \r
-  *           1. FLASH Interface configuration functions: this group includes \r
-  *              the management of following features:\r
-  *                    - Set the latency\r
-  *                    - Enable/Disable the prefetch buffer\r
-  *                    - Enable/Disable the 64 bit Read Access \r
-  *                    - Enable/Disable the RUN PowerDown mode\r
-  *                    - Enable/Disable the SLEEP PowerDown mode  \r
-  *  \r
-  *           2. FLASH Memory Programming functions: this group includes all \r
-  *              needed functions to erase and program the main memory:\r
-  *                    - Lock and Unlock the Flash interface.\r
-  *                    - Erase function: Erase Page.\r
-  *                    - Program functions: Fast Word and Half Page(should be \r
-  *                      executed from internal SRAM).\r
-  *   \r
-  *           3. DATA EEPROM Programming functions: this group includes all \r
-  *              needed functions to erase and program the DATA EEPROM memory:\r
-  *                    - Lock and Unlock the DATA EEPROM interface.\r
-  *                    - Erase function: Erase Word, erase Double Word (should be \r
-  *                      executed from internal SRAM).\r
-  *                    - Program functions: Fast Program Byte, Fast Program Half-Word, \r
-  *                      FastProgramWord, Program Byte, Program Half-Word, \r
-  *                      Program Word and Program Double-Word (should be executed \r
-  *                      from internal SRAM).\r
-  *    \r
-  *           4. FLASH Option Bytes Programming functions: this group includes \r
-  *              all needed functions to:\r
-  *                    - Lock and Unlock the Flash Option bytes.  \r
-  *                    - Set/Reset the write protection\r
-  *                    - Set the Read protection Level\r
-  *                    - Set the BOR level\r
-  *                    - Program the user option Bytes \r
-  *                    - Launch the Option Bytes loader\r
-  *                    - Get the Write protection\r
-  *                    - Get the read protection status\r
-  *                    - Get the BOR level\r
-  *                    - Get the user option bytes        \r
-  *  \r
-  *           5. FLASH Interrupts and flag management functions: this group \r
-  *              includes all needed functions to:\r
-  *                    - Enable/Disable the flash interrupt sources\r
-  *                    - Get flags status\r
-  *                    - Clear flags\r
-  *                    - Get Flash operation status\r
-  *                    - Wait for last flash operation   \r
-  * \r
-  *  @endverbatim\r
-  *                      \r
-  ******************************************************************************\r
-  * @attention\r
-  *\r
-  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
-  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
-  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
-  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
-  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
-  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
-  *\r
-  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
-  ******************************************************************************  \r
-  */ \r
-\r
-/* Includes ------------------------------------------------------------------*/\r
-#include "stm32l1xx_flash.h"\r
-\r
-/** @addtogroup STM32L1xx_StdPeriph_Driver\r
-  * @{\r
-  */\r
-\r
-/** @defgroup FLASH \r
-  * @brief FLASH driver modules\r
-  * @{\r
-  */ \r
-\r
-/* Private typedef -----------------------------------------------------------*/\r
-/* Private define ------------------------------------------------------------*/\r
-  \r
-/* FLASH Mask */\r
-#define RDPRT_MASK                 ((uint32_t)0x00000002)\r
-#define WRP01_MASK                 ((uint32_t)0x0000FFFF)\r
-#define WRP23_MASK                 ((uint32_t)0xFFFF0000)\r
-\r
-/* Private macro -------------------------------------------------------------*/\r
-/* Private variables ---------------------------------------------------------*/\r
-/* Private function prototypes -----------------------------------------------*/\r
-/* Private functions ---------------------------------------------------------*/\r
\r
-/** @defgroup FLASH_Private_Functions\r
-  * @{\r
-  */ \r
-\r
-/** @defgroup FLASH_Group1 FLASH Interface configuration functions\r
-  *  @brief   FLASH Interface configuration functions \r
- *\r
-@verbatim   \r
- ===============================================================================\r
-                       FLASH Interface configuration functions\r
- ===============================================================================  \r
-\r
-   FLASH_Interface configuration_Functions, includes the following functions:\r
-   - void FLASH_SetLatency(uint32_t FLASH_Latency):\r
-     To correctly read data from Flash memory, the number of wait states (LATENCY) \r
-     must be correctly programmed according to the frequency of the CPU clock \r
-     (HCLK) and the supply voltage of the device.\r
-  ----------------------------------------------------------------     \r
- |  Wait states  |                HCLK clock frequency (MHz)      |\r
- |               |------------------------------------------------|     \r
- |   (Latency)   |            voltage range       | voltage range | \r
- |               |            1.65 V - 3.6 V      | 2.0 V - 3.6 V |\r
- |               |----------------|---------------|---------------| \r
- |               |  VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |\r
- |-------------- |----------------|---------------|---------------|             \r
- |0WS(1CPU cycle)|0 < HCLK <= 2   |0 < HCLK <= 8  |0 < HCLK <= 16 |\r
- |---------------|----------------|---------------|---------------|  \r
- |1WS(2CPU cycle)|2 < HCLK <= 4   |8 < HCLK <= 16 |16 < HCLK <= 32| \r
-  ----------------------------------------------------------------   \r
-   \r
-   - void FLASH_PrefetchBufferCmd(FunctionalState NewState);\r
-   - void FLASH_ReadAccess64Cmd(FunctionalState NewState);\r
-   - void FLASH_RUNPowerDownCmd(FunctionalState NewState);\r
-   - void FLASH_SLEEPPowerDownCmd(FunctionalState NewState);\r
-   - void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);\r
-   \r
-  Here below the allowed configuration of Latency, 64Bit access and prefetch buffer\r
-  --------------------------------------------------------------------------------              \r
- |               |              ACC64 = 0         |              ACC64 = 1        |\r
- |   Latency     |----------------|---------------|---------------|---------------|   \r
- |               |   PRFTEN = 0   |   PRFTEN = 1  |   PRFTEN = 0  |   PRFTEN = 1  | \r
- |---------------|----------------|---------------|---------------|---------------|   \r
- |0WS(1CPU cycle)|     YES        |     NO        |     YES       |     YES       |\r
- |---------------|----------------|---------------|---------------|---------------| \r
- |1WS(2CPU cycle)|     NO         |     NO        |     YES       |     YES       | \r
-  --------------------------------------------------------------------------------   \r
-   All these functions don't need the unlock sequence.\r
-\r
-@endverbatim\r
-  * @{\r
-  */\r
-\r
-/**\r
-  * @brief  Sets the code latency value.\r
-  * @param  FLASH_Latency: specifies the FLASH Latency value.\r
-  *   This parameter can be one of the following values:\r
-  *     @arg FLASH_Latency_0: FLASH Zero Latency cycle\r
-  *     @arg FLASH_Latency_1: FLASH One Latency cycle\r
-  * @retval None\r
-  */\r
-void FLASH_SetLatency(uint32_t FLASH_Latency)\r
-{\r
-   uint32_t tmpreg = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_LATENCY(FLASH_Latency));\r
-  \r
-  /* Read the ACR register */\r
-  tmpreg = FLASH->ACR;  \r
-  \r
-  /* Sets the Latency value */\r
-  tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY));\r
-  tmpreg |= FLASH_Latency;\r
-  \r
-  /* Write the ACR register */\r
-  FLASH->ACR = tmpreg;\r
-}\r
-\r
-/**\r
-  * @brief  Enables or disables the Prefetch Buffer.\r
-  * @param  NewState: new state of the FLASH prefetch buffer.\r
-  *              This parameter can be: ENABLE or DISABLE. \r
-  * @retval None\r
-  */\r
-void FLASH_PrefetchBufferCmd(FunctionalState NewState)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-   \r
-  if(NewState != DISABLE)\r
-  {\r
-    FLASH->ACR |= FLASH_ACR_PRFTEN;\r
-  }\r
-  else\r
-  {\r
-    FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTEN));\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Enables or disables read access to flash by 64 bits.\r
-  * @param  NewState: new state of the FLASH read access mode.\r
-  *              This parameter can be: ENABLE or DISABLE.  \r
-  * @note   - If this bit is set, the Read access 64 bit is used.\r
-  *         - If this bit is reset, the Read access 32 bit is used.\r
-  * @note   - This bit cannot be written at the same time as the LATENCY and \r
-  *           PRFTEN bits. \r
-  *         - To reset this bit, the LATENCY should be zero wait state and the \r
-  *           prefetch off.\r
-  * @retval None\r
-  */\r
-void FLASH_ReadAccess64Cmd(FunctionalState NewState)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-  \r
-  if(NewState != DISABLE)\r
-  {\r
-    FLASH->ACR |= FLASH_ACR_ACC64;\r
-  }\r
-  else\r
-  {\r
-    FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_ACC64));\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Enable or disable the power down mode during Sleep mode.\r
-  * @note   This function is used to power down the FLASH when the system is in SLEEP LP mode.  \r
-  * @param  NewState: new state of the power down mode during sleep mode.\r
-  *   This parameter can be: ENABLE or DISABLE.\r
-  * @retval None\r
-  */\r
-void FLASH_SLEEPPowerDownCmd(FunctionalState NewState)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-  \r
-  if (NewState != DISABLE)\r
-  {\r
-    /* Set the SLEEP_PD bit to put Flash in power down mode during sleep mode */\r
-    FLASH->ACR |= FLASH_ACR_SLEEP_PD;\r
-  }\r
-  else\r
-  {\r
-    /* Clear the SLEEP_PD bit in to put Flash in idle mode during sleep mode */\r
-    FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_SLEEP_PD));\r
-  }\r
-}\r
-\r
-/**\r
-  * @}\r
-  */\r
-\r
-/** @defgroup FLASH_Group2 FLASH Memory Programming functions\r
- *  @brief   FLASH Memory Programming functions\r
- *\r
-@verbatim   \r
- ===============================================================================\r
-                      FLASH Memory Programming functions\r
- ===============================================================================  \r
-\r
-   The FLASH Memory Programming functions, includes the following functions:\r
-    - void FLASH_Unlock(void);\r
-    - void FLASH_Lock(void);\r
-    - FLASH_Status FLASH_ErasePage(uint32_t Page_Address);\r
-    - FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data);\r
-   \r
-   Any operation of erase or program should follow these steps:\r
-\r
-   1. Call the FLASH_Unlock() function to enable the flash control register and \r
-     program memory access\r
-\r
-   2. Call the desired function to erase page or program data\r
-\r
-   3. Call the FLASH_Lock() to disable the flash program memory access \r
-     (recommended to protect the FLASH memory against possible unwanted operation)\r
-\r
-@endverbatim\r
-  * @{\r
-  */\r
-\r
-/**\r
-  * @brief  Unlocks the FLASH control register and program memory access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void FLASH_Unlock(void)\r
-{\r
-  if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET)\r
-  {\r
-    /* Unlocking the data memory and FLASH_PECR register access */\r
-    DATA_EEPROM_Unlock();\r
-  \r
-    /* Unlocking the program memory access */\r
-    FLASH->PRGKEYR = FLASH_PRGKEY1;\r
-    FLASH->PRGKEYR = FLASH_PRGKEY2;  \r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Locks the Program memory access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void FLASH_Lock(void)\r
-{\r
-  /* Set the PRGLOCK Bit to lock the program memory access */\r
-  FLASH->PECR |= FLASH_PECR_PRGLOCK;\r
-}\r
-\r
-/**\r
-  * @brief  Erases a specified page in program memory.\r
-  * @note   - To correctly run this function, the FLASH_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_Lock() to disable the flash memory access \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)  \r
-  * @param  Page_Address: The page address in program memory to be erased.\r
-  * @note   A Page is erased in the Program memory only if the address to load \r
-  *         is the start address of a page (multiple of 256 bytes).  \r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_ErasePage(uint32_t Page_Address)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address));\r
\r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* If the previous operation is completed, proceed to erase the page */\r
-\r
-    /* Set the ERASE bit */\r
-    FLASH->PECR |= FLASH_PECR_ERASE;\r
-\r
-    /* Set PROG bit */\r
-    FLASH->PECR |= FLASH_PECR_PROG;\r
-  \r
-    /* Write 00000000h to the first word of the program page to erase */\r
-    *(__IO uint32_t *)Page_Address = 0x00000000;\r
\r
-    /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-\r
-    /* If the erase operation is completed, disable the ERASE and PROG bits */\r
-    FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);\r
-    FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE);   \r
-  }     \r
-  /* Return the Erase Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Programs a word at a specified address in program memory.\r
-  * @note   - To correctly run this function, the FLASH_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_Lock() to disable the flash memory access  \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)  \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @retval FLASH Status: The returned value can be:  \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));\r
-  \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* If the previous operation is completed, proceed to program the new  word */  \r
-    *(__IO uint32_t *)Address = Data;\r
-    \r
-    /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);       \r
-  }\r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @}\r
-  */\r
-  \r
-/** @defgroup FLASH_Group3 DATA EEPROM Programming functions\r
- *  @brief   DATA EEPROM Programming functions\r
- *\r
-@verbatim   \r
- ===============================================================================\r
-                       DATA EEPROM Programming functions\r
- ===============================================================================  \r
-\r
-   The DATA_EEPROM Programming_Functions, includes the following functions:\r
-   - void DATA_EEPROM_Unlock(void);\r
-   - void DATA_EEPROM_Lock(void);\r
-   - FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address);\r
-   - FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data);\r
-   - FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data);\r
-   - FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data);\r
-   - FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data);\r
-   - FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data);\r
-   - FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data);\r
-   \r
-   Any operation of erase or program should follow these steps:\r
-\r
-   1. Call the DATA_EEPROM_Unlock() function to enable the data EEPROM access\r
-     and Flash program erase control register access.\r
-\r
-   2. Call the desired function to erase or program data\r
-\r
-   3. Call the DATA_EEPROM_Lock() to disable the data EEPROM access\r
-     and Flash program erase control register access(recommended\r
-     to protect the DATA_EEPROM against possible unwanted operation)\r
-\r
-@endverbatim\r
-  * @{\r
-  */\r
-\r
-/**\r
-  * @brief  Unlocks the data memory and FLASH_PECR register access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void DATA_EEPROM_Unlock(void)\r
-{\r
-  if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)\r
-  {  \r
-    /* Unlocking the Data memory and FLASH_PECR register access*/\r
-    FLASH->PEKEYR = FLASH_PEKEY1;\r
-    FLASH->PEKEYR = FLASH_PEKEY2;\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Locks the Data memory and FLASH_PECR register access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void DATA_EEPROM_Lock(void)\r
-{\r
-  /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */\r
-  FLASH->PECR |= FLASH_PECR_PELOCK;\r
-}\r
-\r
-/**\r
-  * @brief  Enables or disables DATA EEPROM fixed Time programming (2*Tprog).\r
-  * @param  NewState: new state of the DATA EEPROM fixed Time programming mode.\r
-  *              This parameter can be: ENABLE or DISABLE.  \r
-  * @retval None\r
-  */\r
-void DATA_EEPROM_FixedTimeProgramCmd(FunctionalState NewState)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-  \r
-  if(NewState != DISABLE)\r
-  {\r
-    FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW;\r
-  }\r
-  else\r
-  {\r
-    FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Erase a word in data memory.\r
-  * @param  Address: specifies the address to be erased\r
-  * @note1  - A data memory word is erased in the data memory only if the address \r
-  *         to load is the start address of a word (multiple of a word).\r
-  * @note2   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *          - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)    \r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address));\r
-  \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* Write "00000000h" to valid address in the data memory" */\r
-    *(__IO uint32_t *) Address = 0x00000000;\r
-  }\r
-   \r
-  /* Return the erase status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Write a Byte at a specified address in data memory.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)  \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @note This function assumes that the is data word is already erased.  \r
-  * @retval FLASH Status: The returned value can be:  \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp = 0, tmpaddr = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address)); \r
-\r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-    \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* Clear the FTDW bit */\r
-    FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));\r
-    \r
-    if(Data != (uint8_t)0x00) \r
-    {\r
-      /* If the previous operation is completed, proceed to write the new Data */        \r
-      *(__IO uint8_t *)Address = Data;\r
-            \r
-      /* Wait for last operation to be completed */\r
-      status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);           \r
-    }\r
-    else\r
-    {\r
-      tmpaddr = Address & 0xFFFFFFFC;\r
-      tmp = * (__IO uint32_t *) tmpaddr;\r
-      tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));\r
-      tmp &= ~tmpaddr;\r
-      status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);\r
-      status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);         \r
-    }       \r
-  }\r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Writes a half word at a specified address in data memory.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)    \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @note This function assumes that the is data word is already erased.  \r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or  FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp = 0, tmpaddr = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address));\r
-\r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-    \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* Clear the FTDW bit */\r
-    FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));\r
-  \r
-    if(Data != (uint16_t)0x0000) \r
-    {\r
-      /* If the previous operation is completed, proceed to write the new data */   \r
-      *(__IO uint16_t *)Address = Data;\r
-  \r
-      /* Wait for last operation to be completed */\r
-      status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-    }\r
-    else\r
-    {\r
-      if((Address & 0x3) != 0x3)\r
-      {        \r
-        tmpaddr = Address & 0xFFFFFFFC;\r
-        tmp = * (__IO uint32_t *) tmpaddr;\r
-        tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));\r
-        tmp &= ~tmpaddr;        \r
-        status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);\r
-        status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);      \r
-      }\r
-      else\r
-      {\r
-        DATA_EEPROM_FastProgramByte(Address, 0x00);\r
-        DATA_EEPROM_FastProgramByte(Address + 1, 0x00);          \r
-      }      \r
-    }      \r
-  } \r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Programs a word at a specified address in data memory.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to the data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)    \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @note This function assumes that the is data word is already erased.    \r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address));\r
-  \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    /* Clear the FTDW bit */\r
-    FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));\r
-  \r
-    /* If the previous operation is completed, proceed to program the new data */    \r
-    *(__IO uint32_t *)Address = Data;\r
-    \r
-    /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);       \r
-  }\r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Write a Byte at a specified address in data memory without erase.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation) \r
-  * @note   The function  DATA_EEPROM_FixedTimeProgramCmd() can be called before \r
-  *         this function to configure the Fixed Time Programming.      \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp = 0, tmpaddr = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address)); \r
-\r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    if(Data != (uint8_t) 0x00)\r
-    {  \r
-      *(__IO uint8_t *)Address = Data;\r
-    \r
-      /* Wait for last operation to be completed */\r
-      status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-\r
-    }\r
-    else\r
-    {\r
-      tmpaddr = Address & 0xFFFFFFFC;\r
-      tmp = * (__IO uint32_t *) tmpaddr;\r
-      tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));\r
-      tmp &= ~tmpaddr;        \r
-      status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);\r
-      status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);        \r
-    }   \r
-  }\r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Writes a half word at a specified address in data memory without erase.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)\r
-  * @note   The function  DATA_EEPROM_FixedTimeProgramCmd() can be called before \r
-  *         this function to configure the Fixed Time Programming                 \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @retval FLASH Status: The returned value can be:  \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp = 0, tmpaddr = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address));\r
-\r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    if(Data != (uint16_t)0x0000)\r
-    {\r
-      *(__IO uint16_t *)Address = Data;\r
-   \r
-      /* Wait for last operation to be completed */\r
-      status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);     \r
-    }\r
-    else\r
-    {\r
-      if((Address & 0x3) != 0x3)\r
-      {\r
-        tmpaddr = Address & 0xFFFFFFFC;\r
-        tmp = * (__IO uint32_t *) tmpaddr;\r
-        tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));\r
-        tmp &= ~tmpaddr;          \r
-        status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);\r
-        status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);  \r
-      }\r
-      else\r
-      {\r
-        DATA_EEPROM_FastProgramByte(Address, 0x00);\r
-        DATA_EEPROM_FastProgramByte(Address + 1, 0x00);          \r
-      }              \r
-    }    \r
-  } \r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Programs a word at a specified address in data memory without erase.\r
-  * @note   - To correctly run this function, the DATA_EEPROM_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the DATA_EEPROM_Lock() to he data EEPROM access\r
-  *            and Flash program erase control register access(recommended to protect \r
-  *            the DATA_EEPROM against possible unwanted operation)  \r
-  * @note   The function  DATA_EEPROM_FixedTimeProgramCmd() can be called before \r
-  *         this function to configure the Fixed Time Programming.               \r
-  * @param  Address: specifies the address to be written.\r
-  * @param  Data: specifies the data to be written.\r
-  * @retval FLASH Status: The returned value can be:  \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or  FLASH_TIMEOUT. \r
-  */\r
-FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_DATA_ADDRESS(Address));\r
-  \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    *(__IO uint32_t *)Address = Data;\r
-\r
-    /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);        \r
-  }\r
-  /* Return the Write Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @}\r
-  */\r
-\r
-/** @defgroup FLASH_Group4 Option Bytes Programming functions\r
- *  @brief   Option Bytes Programming functions \r
- *\r
-@verbatim   \r
- ===============================================================================\r
-                        Option Bytes Programming functions\r
- ===============================================================================  \r
-\r
-   The FLASH_Option Bytes Programming_functions, includes the following functions:\r
-   - void FLASH_OB_Unlock(void);\r
-   - void FLASH_OB_Lock(void);\r
-   - void FLASH_OB_Launch(void);\r
-   - FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);\r
-   - FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);\r
-   - FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);\r
-   - FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR);\r
-   - uint8_t FLASH_OB_GetUser(void);\r
-   - uint32_t FLASH_OB_GetWRP(void);\r
-   - FlagStatus FLASH_OB_GetRDP(void);\r
-   - uint8_t FLASH_OB_GetBOR(void);\r
-   \r
-   Any operation of erase or program should follow these steps:\r
-   \r
-   1. Call the FLASH_OB_Unlock() function to enable the Flash option control register access\r
-   \r
-   2. Call one or several functions to program the desired option bytes \r
-      - void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) => to Enable/Disable \r
-        the desired sector write protection\r
-      - void FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read Protection Level\r
-      - void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) => to configure \r
-        the user option Bytes: IWDG, STOP and the Standby.\r
-      - void FLASH_OB_BORConfig(uint8_t OB_BOR) => to Set the BOR level \r
-      - FLASH_Status FLASH_ProgramOTP(uint32_t Address, uint32_t Data) => to program the OTP bytes                      \r
-   \r
-   3. Once all needed option bytes to be programmed are correctly written, call the\r
-     FLASH_OB_Launch(void) function to launch the Option Bytes programming process.  \r
-   \r
-   4. Call the FLASH_OB_Lock() to disable the Flash option control register access (recommended\r
-      to protect the option Bytes against possible unwanted operations)\r
-\r
-@endverbatim\r
-  * @{\r
-  */\r
-\r
-/**\r
-  * @brief  Unlocks the option bytes block access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void FLASH_OB_Unlock(void)\r
-{\r
-  if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET)\r
-  {\r
-    /* Unlocking the data memory and FLASH_PECR register access */\r
-    DATA_EEPROM_Unlock();\r
-  \r
-    /* Unlocking the option bytes block access */\r
-    FLASH->OPTKEYR = FLASH_OPTKEY1;\r
-    FLASH->OPTKEYR = FLASH_OPTKEY2;\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Locks the option bytes block access.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void FLASH_OB_Lock(void)\r
-{\r
-  /* Set the OPTLOCK Bit to lock the option bytes block access */\r
-  FLASH->PECR |= FLASH_PECR_OPTLOCK;\r
-}\r
-\r
-/**\r
-  * @brief  Launch the option byte loading.\r
-  * @param  None\r
-  * @retval None\r
-  */\r
-void FLASH_OB_Launch(void)\r
-{\r
-  /* Set the OBL_Launch bit to lauch the option byte loading */\r
-  FLASH->PECR |= FLASH_PECR_OBL_LAUNCH;\r
-}\r
-\r
-/**\r
-  * @brief  Write protects the desired pages\r
-  * @note   - To correctly run this function, the FLASH_OB_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)    \r
-  * @param  OB_WRP: specifies the address of the pages to be write protected.\r
-  *   This parameter can be:\r
-  *     @arg  value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511\r
-  *     @arg OB_WRP_AllPages\r
-  * @param  NewState: new state of the specified FLASH Pages Wtite protection.\r
-  *   This parameter can be: ENABLE or DISABLE.\r
-  * @retval FLASH Status: The returned value can be: \r
-  * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)\r
-{\r
-  uint32_t WRP01_Data = 0, WRP23_Data = 0;\r
-  \r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp1 = 0, tmp2 = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_OB_WRP(OB_WRP));\r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-     \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
\r
-  if(status == FLASH_COMPLETE)\r
-  {\r
-    if (NewState != DISABLE)\r
-    {\r
-      WRP01_Data = (uint16_t)(((OB_WRP & WRP01_MASK) | OB->WRP01));\r
-      WRP23_Data = (uint16_t)((((OB_WRP & WRP23_MASK)>>16 | OB->WRP23))); \r
-      tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data);\r
-      OB->WRP01 = tmp1;\r
-      \r
-      tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data);\r
-      OB->WRP23 = tmp2;      \r
-    }             \r
-    \r
-    else\r
-    {\r
-      WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01));\r
-      WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23))); \r
-\r
-      tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data);\r
-      OB->WRP01 = tmp1;\r
-      \r
-      tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data);\r
-      OB->WRP23 = tmp2;\r
-    }\r
-    /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  }\r
-\r
-  /* Return the write protection operation Status */\r
-  return status;      \r
-}\r
-\r
-/**\r
-  * @brief  Enables or disables the read out protection.\r
-  * @note   - To correctly run this function, the FLASH_OB_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)   \r
-  * @param  FLASH_ReadProtection_Level: specifies the read protection level. \r
-  *   This parameter can be:\r
-  *     @arg OB_RDP_Level_0: No protection\r
-  *     @arg OB_RDP_Level_1: Read protection of the memory                     \r
-  *     @arg OB_RDP_Level_2: Chip protection\r
-  *     @retval FLASH Status: The returned value can be: \r
-  * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint8_t tmp1 = 0;\r
-  uint32_t tmp2 = 0;\r
-  \r
-  /* Check the parameters */\r
-  assert_param(IS_OB_RDP(OB_RDP));\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  /* calculate the option byte to write */\r
-  tmp1 = (uint8_t)(~(OB_RDP ));\r
-  tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)OB_RDP));\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {         \r
-   /* program read protection level */\r
-    OB->RDP = tmp2;\r
-  }\r
-  \r
-  /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-     \r
-  /* Return the Read protection operation Status */\r
-  return status;            \r
-}\r
-\r
-/**\r
-  * @brief  Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.\r
-  * @note   - To correctly run this function, the FLASH_OB_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)   \r
-  * @param  OB_IWDG: Selects the WDG mode\r
-  *   This parameter can be one of the following values:\r
-  *     @arg OB_IWDG_SW: Software WDG selected\r
-  *     @arg OB_IWDG_HW: Hardware WDG selected\r
-  * @param  OB_STOP: Reset event when entering STOP mode.\r
-  *   This parameter can be one of the following values:\r
-  *     @arg OB_STOP_NoRST: No reset generated when entering in STOP\r
-  *     @arg OB_STOP_RST: Reset generated when entering in STOP\r
-  * @param  OB_STDBY: Reset event when entering Standby mode.\r
-  *   This parameter can be one of the following values:\r
-  *     @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY\r
-  *     @arg OB_STDBY_RST: Reset generated when entering in STANDBY\r
-  * @retval FLASH Status: The returned value can be: \r
-  * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE; \r
-  uint32_t tmp = 0, tmp1 = 0;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));\r
-  assert_param(IS_OB_STOP_SOURCE(OB_STOP));\r
-  assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));\r
-\r
-  /* Get the User Option byte register */\r
-  tmp1 = (FLASH->OBR & 0x000F0000) >> 16;\r
-    \r
-  /* Calculate the user option byte to write */ \r
-  tmp = (uint32_t)(((uint32_t)~((uint32_t)((uint32_t)(OB_IWDG) | (uint32_t)(OB_STOP) | (uint32_t)(OB_STDBY) | tmp1))) << ((uint32_t)0x10));\r
-  tmp |= ((uint32_t)(OB_IWDG) | ((uint32_t)OB_STOP) | (uint32_t)(OB_STDBY) | tmp1);\r
-  \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {  \r
-    /* Write the User Option Byte */              \r
-    OB->USER = tmp; \r
-  }\r
-  \r
-  /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-       \r
-  /* Return the Option Byte program Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Programs the FLASH brownout reset threshold level Option Byte.\r
-  * @note   - To correctly run this function, the FLASH_OB_Unlock() function\r
-  *           must be called before.\r
-  *         - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes \r
-  *          (recommended to protect the FLASH memory against possible unwanted operation)   \r
-  * @param  OB_BOR: Selects the brownout reset threshold level\r
-  *   This parameter can be one of the following values:\r
-  *     @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD \r
-  *                      power supply reaches the PDR(Power Down Reset) threshold (1.5V)\r
-  *     @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply\r
-  *     @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply\r
-  *     @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply\r
-  *     @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply\r
-  *     @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply\r
-  * @retval FLASH Status: The returned value can be: \r
-  * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR)\r
-{\r
-  FLASH_Status status = FLASH_COMPLETE;\r
-  uint32_t tmp = 0, tmp1 = 0;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_OB_BOR_LEVEL(OB_BOR));\r
-\r
-  /* Get the User Option byte register */\r
-  tmp1 = (FLASH->OBR & 0x00700000) >> 16;\r
-     \r
-  /* Calculate the option byte to write */\r
-  tmp = (uint32_t)~(OB_BOR | tmp1)<<16;\r
-  tmp |= (OB_BOR | tmp1);\r
-    \r
-  /* Wait for last operation to be completed */\r
-  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-  \r
-  if(status == FLASH_COMPLETE)\r
-  {  \r
-    /* Write the BOR Option Byte */            \r
-    OB->USER = tmp; \r
-  }\r
-  \r
-  /* Wait for last operation to be completed */\r
-    status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);\r
-        \r
-  /* Return the Option Byte program Status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @brief  Returns the FLASH User Option Bytes values.\r
-  * @param  None\r
-  * @retval The FLASH User Option Bytes .\r
-  */\r
-uint8_t FLASH_OB_GetUser(void)\r
-{\r
-  /* Return the User Option Byte */\r
-  return (uint8_t)(FLASH->OBR >> 20);\r
-}\r
-\r
-/**\r
-  * @brief  Returns the FLASH Write Protection Option Bytes value.\r
-  * @param  None\r
-  * @retval The FLASH Write Protection Option Bytes value\r
-  */\r
-uint32_t FLASH_OB_GetWRP(void)\r
-{\r
-  /* Return the FLASH write protection Register value */\r
-  return (uint32_t)(FLASH->WRPR);\r
-}\r
-\r
-/**\r
-  * @brief  Checks whether the FLASH Read out Protection Status is set or not.\r
-  * @param  None\r
-  * @retval FLASH ReadOut Protection Status(SET or RESET)\r
-  */\r
-FlagStatus FLASH_OB_GetRDP(void)\r
-{\r
-  FlagStatus readstatus = RESET;\r
-  \r
-  if ((uint8_t)(FLASH->OBR) != (uint8_t)OB_RDP_Level_0)\r
-  {\r
-    readstatus = SET;\r
-  }\r
-  else\r
-  {\r
-    readstatus = RESET;\r
-  }\r
-  return readstatus;\r
-}\r
-\r
-/**\r
-  * @brief  Returns the FLASH BOR level.\r
-  * @param  None\r
-  * @retval The FLASH User Option Bytes .\r
-  */\r
-uint8_t FLASH_OB_GetBOR(void)\r
-{\r
-  /* Return the BOR level */\r
-  return (uint8_t)((FLASH->OBR & (uint32_t)0x000F0000) >> 16);\r
-}\r
-\r
-/**\r
-  * @}\r
-  */\r
-\r
-/** @defgroup FLASH_Group5 Interrupts and flags management functions\r
- *  @brief   Interrupts and flags management functions\r
- *\r
-@verbatim   \r
- ===============================================================================\r
-                  Interrupts and flags management functions\r
- ===============================================================================  \r
-\r
-@endverbatim\r
-  * @{\r
-  */\r
-\r
-/**\r
-  * @brief  Enables or disables the specified FLASH interrupts.\r
-  * @param  FLASH_IT: specifies the FLASH interrupt sources to be enabled or \r
-  *         disabled.\r
-  *   This parameter can be any combination of the following values:     \r
-  *     @arg FLASH_IT_EOP: FLASH end of programming Interrupt\r
-  *     @arg FLASH_IT_ERR: FLASH Error Interrupt  \r
-  * @retval None \r
-  */\r
-void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_IT(FLASH_IT)); \r
-  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
-  \r
-  if(NewState != DISABLE)\r
-  {\r
-    /* Enable the interrupt sources */\r
-    FLASH->PECR |= FLASH_IT;\r
-  }\r
-  else\r
-  {\r
-    /* Disable the interrupt sources */\r
-    FLASH->PECR &= ~(uint32_t)FLASH_IT;\r
-  }\r
-}\r
-\r
-/**\r
-  * @brief  Checks whether the specified FLASH flag is set or not.\r
-  * @param  FLASH_FLAG: specifies the FLASH flag to check.\r
-  *   This parameter can be one of the following values:\r
-  *     @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag \r
-  *     @arg FLASH_FLAG_EOP: FLASH End of Operation flag\r
-  *     @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode\r
-  *     @arg FLASH_FLAG_ENDHV: FLASH End of high voltage flag\r
-  *     @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag \r
-  *     @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag\r
-  *     @arg FLASH_FLAG_SIZERR: FLASH size error flag    \r
-  *     @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag         \r
-  * @retval The new state of FLASH_FLAG (SET or RESET).\r
-  */\r
-FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)\r
-{\r
-  FlagStatus bitstatus = RESET;\r
-\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));\r
-\r
-  if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)\r
-  {\r
-    bitstatus = SET;\r
-  }\r
-  else\r
-  {\r
-    bitstatus = RESET;\r
-  }\r
-  /* Return the new state of FLASH_FLAG (SET or RESET) */\r
-  return bitstatus; \r
-}\r
-\r
-/**\r
-  * @brief  Clears the FLASH\92s pending flags.\r
-  * @param  FLASH_FLAG: specifies the FLASH flags to clear.\r
-  *   This parameter can be any combination of the following values:\r
-  *     @arg FLASH_FLAG_EOP: FLASH End of Operation flag\r
-  *     @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag \r
-  *     @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag \r
-  *     @arg FLASH_FLAG_SIZERR: FLASH size error flag    \r
-  *     @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag              \r
-  * @retval None\r
-  */\r
-void FLASH_ClearFlag(uint32_t FLASH_FLAG)\r
-{\r
-  /* Check the parameters */\r
-  assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));\r
-  \r
-  /* Clear the flags */\r
-  FLASH->SR = FLASH_FLAG;\r
-}\r
-\r
-/**\r
-  * @brief  Returns the FLASH Status.\r
-  * @param  None\r
-  * @retval FLASH Status: The returned value can be: \r
-  *   FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE.\r
-  */\r
-FLASH_Status FLASH_GetStatus(void)\r
-{\r
-  FLASH_Status FLASHstatus = FLASH_COMPLETE;\r
-  \r
-  if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY) \r
-  {\r
-    FLASHstatus = FLASH_BUSY;\r
-  }\r
-  else \r
-  {  \r
-    if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)\r
-    { \r
-      FLASHstatus = FLASH_ERROR_WRP;\r
-    }\r
-    else \r
-    {\r
-      if((FLASH->SR & (uint32_t)0xFEF0) != (uint32_t)0x00)\r
-      {\r
-        FLASHstatus = FLASH_ERROR_PROGRAM; \r
-      }\r
-      else\r
-      {\r
-        FLASHstatus = FLASH_COMPLETE;\r
-      }\r
-    }\r
-  }\r
-  /* Return the FLASH Status */\r
-  return FLASHstatus;\r
-}\r
-\r
-\r
-/**\r
-  * @brief  Waits for a FLASH operation to complete or a TIMEOUT to occur.\r
-  * @param  Timeout: FLASH programming Timeout\r
-  * @retval FLASH Status: The returned value can be: FLASH_BUSY, \r
-  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.\r
-  */\r
-FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)\r
-{ \r
-  FLASH_Status status = FLASH_COMPLETE;\r
-   \r
-  /* Check for the FLASH Status */\r
-  status = FLASH_GetStatus();\r
-  \r
-  /* Wait for a FLASH operation to complete or a TIMEOUT to occur */\r
-  while((status == FLASH_BUSY) && (Timeout != 0x00))\r
-  {\r
-    status = FLASH_GetStatus();\r
-    Timeout--;\r
-  }\r
-  \r
-  if(Timeout == 0x00 )\r
-  {\r
-    status = FLASH_TIMEOUT;\r
-  }\r
-  /* Return the operation status */\r
-  return status;\r
-}\r
-\r
-/**\r
-  * @}\r
-  */\r
-\r
-/**\r
-  * @}\r
-  */\r
-   \r
-  /**\r
-  * @}\r
-  */ \r
-\r
-/**\r
-  * @}\r
-  */ \r
-\r
-/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r