mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
80:66393a7b209d
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32l1xx_flash.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 80:66393a7b209d 5 * @version V1.3.0
mbed_official 80:66393a7b209d 6 * @date 31-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides all the Flash firmware functions. These functions
mbed_official 76:aeb1df146756 8 * can be executed from Internal FLASH or Internal SRAM memories.
mbed_official 76:aeb1df146756 9 * The functions that should be called from SRAM are defined inside
mbed_official 76:aeb1df146756 10 * the "stm32l1xx_flash_ramfunc.c" file.
mbed_official 76:aeb1df146756 11 * This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 12 * functionalities of the FLASH peripheral:
mbed_official 76:aeb1df146756 13 * + FLASH Interface configuration
mbed_official 76:aeb1df146756 14 * + FLASH Memory Programming
mbed_official 76:aeb1df146756 15 * + DATA EEPROM Programming
mbed_official 76:aeb1df146756 16 * + Option Bytes Programming
mbed_official 76:aeb1df146756 17 * + Interrupts and flags management
mbed_official 76:aeb1df146756 18 *
mbed_official 76:aeb1df146756 19 * @verbatim
mbed_official 76:aeb1df146756 20
mbed_official 76:aeb1df146756 21 ==============================================================================
mbed_official 76:aeb1df146756 22 ##### How to use this driver #####
mbed_official 76:aeb1df146756 23 ==============================================================================
mbed_official 76:aeb1df146756 24 [..] This driver provides functions to configure and program the Flash
mbed_official 76:aeb1df146756 25 memory of all STM32L1xx devices.
mbed_official 76:aeb1df146756 26 [..] These functions are split in 5 groups:
mbed_official 76:aeb1df146756 27 (#) FLASH Interface configuration functions: this group includes
mbed_official 76:aeb1df146756 28 the management of following features:
mbed_official 76:aeb1df146756 29 (++) Set the latency.
mbed_official 76:aeb1df146756 30 (++) Enable/Disable the prefetch buffer.
mbed_official 76:aeb1df146756 31 (++) Enable/Disable the 64 bit Read Access.
mbed_official 76:aeb1df146756 32 (++) Enable/Disable the RUN PowerDown mode.
mbed_official 76:aeb1df146756 33 (++) Enable/Disable the SLEEP PowerDown mode.
mbed_official 76:aeb1df146756 34
mbed_official 76:aeb1df146756 35 (#) FLASH Memory Programming functions: this group includes all
mbed_official 76:aeb1df146756 36 needed functions to erase and program the main memory:
mbed_official 76:aeb1df146756 37 (++) Lock and Unlock the Flash interface.
mbed_official 76:aeb1df146756 38 (++) Erase function: Erase Page.
mbed_official 76:aeb1df146756 39 (++) Program functions: Fast Word and Half Page(should be
mbed_official 76:aeb1df146756 40 executed from internal SRAM).
mbed_official 76:aeb1df146756 41
mbed_official 76:aeb1df146756 42 (#) DATA EEPROM Programming functions: this group includes all
mbed_official 76:aeb1df146756 43 needed functions to erase and program the DATA EEPROM memory:
mbed_official 76:aeb1df146756 44 (++) Lock and Unlock the DATA EEPROM interface.
mbed_official 76:aeb1df146756 45 (++) Erase function: Erase Byte, erase HalfWord, erase Word, erase
mbed_official 76:aeb1df146756 46 (++) Double Word (should be executed from internal SRAM).
mbed_official 76:aeb1df146756 47 (++) Program functions: Fast Program Byte, Fast Program Half-Word,
mbed_official 76:aeb1df146756 48 FastProgramWord, Program Byte, Program Half-Word,
mbed_official 76:aeb1df146756 49 Program Word and Program Double-Word (should be executed
mbed_official 76:aeb1df146756 50 from internal SRAM).
mbed_official 76:aeb1df146756 51
mbed_official 76:aeb1df146756 52 (#) FLASH Option Bytes Programming functions: this group includes
mbed_official 76:aeb1df146756 53 all needed functions to:
mbed_official 76:aeb1df146756 54 (++) Lock and Unlock the Flash Option bytes.
mbed_official 76:aeb1df146756 55 (++) Set/Reset the write protection.
mbed_official 76:aeb1df146756 56 (++) Set the Read protection Level.
mbed_official 76:aeb1df146756 57 (++) Set the BOR level.
mbed_official 76:aeb1df146756 58 (++) rogram the user option Bytes.
mbed_official 76:aeb1df146756 59 (++) Launch the Option Bytes loader.
mbed_official 76:aeb1df146756 60 (++) Get the Write protection.
mbed_official 76:aeb1df146756 61 (++) Get the read protection status.
mbed_official 76:aeb1df146756 62 (++) Get the BOR level.
mbed_official 76:aeb1df146756 63 (++) Get the user option bytes.
mbed_official 76:aeb1df146756 64
mbed_official 76:aeb1df146756 65 (#) FLASH Interrupts and flag management functions: this group
mbed_official 76:aeb1df146756 66 includes all needed functions to:
mbed_official 76:aeb1df146756 67 (++) Enable/Disable the flash interrupt sources.
mbed_official 76:aeb1df146756 68 (++) Get flags status.
mbed_official 76:aeb1df146756 69 (++) Clear flags.
mbed_official 76:aeb1df146756 70 (++) Get Flash operation status.
mbed_official 76:aeb1df146756 71 (++) Wait for last flash operation.
mbed_official 76:aeb1df146756 72
mbed_official 76:aeb1df146756 73 * @endverbatim
mbed_official 76:aeb1df146756 74 *
mbed_official 76:aeb1df146756 75 ******************************************************************************
mbed_official 76:aeb1df146756 76 * @attention
mbed_official 76:aeb1df146756 77 *
mbed_official 106:ced8cbb51063 78 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 79 *
mbed_official 106:ced8cbb51063 80 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 106:ced8cbb51063 81 * are permitted provided that the following conditions are met:
mbed_official 106:ced8cbb51063 82 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 106:ced8cbb51063 83 * this list of conditions and the following disclaimer.
mbed_official 106:ced8cbb51063 84 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 106:ced8cbb51063 85 * this list of conditions and the following disclaimer in the documentation
mbed_official 106:ced8cbb51063 86 * and/or other materials provided with the distribution.
mbed_official 106:ced8cbb51063 87 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 106:ced8cbb51063 88 * may be used to endorse or promote products derived from this software
mbed_official 106:ced8cbb51063 89 * without specific prior written permission.
mbed_official 76:aeb1df146756 90 *
mbed_official 106:ced8cbb51063 91 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 106:ced8cbb51063 92 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 106:ced8cbb51063 93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 106:ced8cbb51063 94 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 106:ced8cbb51063 95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 106:ced8cbb51063 96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 106:ced8cbb51063 97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 106:ced8cbb51063 98 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 106:ced8cbb51063 99 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 106:ced8cbb51063 100 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 101 *
mbed_official 76:aeb1df146756 102 ******************************************************************************
mbed_official 76:aeb1df146756 103 */
mbed_official 76:aeb1df146756 104
mbed_official 76:aeb1df146756 105 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 106 #include "stm32l1xx_flash.h"
mbed_official 76:aeb1df146756 107
mbed_official 76:aeb1df146756 108 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 109 * @{
mbed_official 76:aeb1df146756 110 */
mbed_official 76:aeb1df146756 111
mbed_official 76:aeb1df146756 112 /** @defgroup FLASH
mbed_official 76:aeb1df146756 113 * @brief FLASH driver modules
mbed_official 76:aeb1df146756 114 * @{
mbed_official 76:aeb1df146756 115 */
mbed_official 76:aeb1df146756 116
mbed_official 76:aeb1df146756 117 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 118 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 119
mbed_official 76:aeb1df146756 120 /* FLASH Mask */
mbed_official 76:aeb1df146756 121 #define WRP01_MASK ((uint32_t)0x0000FFFF)
mbed_official 76:aeb1df146756 122 #define WRP23_MASK ((uint32_t)0xFFFF0000)
mbed_official 76:aeb1df146756 123 #define WRP45_MASK ((uint32_t)0x0000FFFF)
mbed_official 76:aeb1df146756 124 #define WRP67_MASK ((uint32_t)0xFFFF0000)
mbed_official 76:aeb1df146756 125 #define WRP89_MASK ((uint32_t)0x0000FFFF)
mbed_official 76:aeb1df146756 126 #define WRP1011_MASK ((uint32_t)0xFFFF0000)
mbed_official 76:aeb1df146756 127
mbed_official 76:aeb1df146756 128 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 129 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 130 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 131 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 132
mbed_official 76:aeb1df146756 133 /** @defgroup FLASH_Private_Functions
mbed_official 76:aeb1df146756 134 * @{
mbed_official 76:aeb1df146756 135 */
mbed_official 76:aeb1df146756 136
mbed_official 76:aeb1df146756 137 /** @defgroup FLASH_Group1 FLASH Interface configuration functions
mbed_official 76:aeb1df146756 138 * @brief FLASH Interface configuration functions
mbed_official 76:aeb1df146756 139 *
mbed_official 76:aeb1df146756 140 @verbatim
mbed_official 76:aeb1df146756 141 ==============================================================================
mbed_official 76:aeb1df146756 142 ##### FLASH Interface configuration functions #####
mbed_official 76:aeb1df146756 143 ==============================================================================
mbed_official 76:aeb1df146756 144
mbed_official 76:aeb1df146756 145 [..] FLASH_Interface configuration_Functions, includes the following functions:
mbed_official 76:aeb1df146756 146 (+) void FLASH_SetLatency(uint32_t FLASH_Latency):
mbed_official 76:aeb1df146756 147 [..] To correctly read data from Flash memory, the number of wait states (LATENCY)
mbed_official 76:aeb1df146756 148 must be correctly programmed according to the frequency of the CPU clock
mbed_official 76:aeb1df146756 149 (HCLK) and the supply voltage of the device.
mbed_official 76:aeb1df146756 150 [..]
mbed_official 76:aeb1df146756 151 ----------------------------------------------------------------
mbed_official 76:aeb1df146756 152 | Wait states | HCLK clock frequency (MHz) |
mbed_official 76:aeb1df146756 153 | |------------------------------------------------|
mbed_official 76:aeb1df146756 154 | (Latency) | voltage range | voltage range |
mbed_official 76:aeb1df146756 155 | | 1.65 V - 3.6 V | 2.0 V - 3.6 V |
mbed_official 76:aeb1df146756 156 | |----------------|---------------|---------------|
mbed_official 76:aeb1df146756 157 | | VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |
mbed_official 76:aeb1df146756 158 |-------------- |----------------|---------------|---------------|
mbed_official 76:aeb1df146756 159 |0WS(1CPU cycle)|0 < HCLK <= 2 |0 < HCLK <= 8 |0 < HCLK <= 16 |
mbed_official 76:aeb1df146756 160 |---------------|----------------|---------------|---------------|
mbed_official 76:aeb1df146756 161 |1WS(2CPU cycle)|2 < HCLK <= 4 |8 < HCLK <= 16 |16 < HCLK <= 32|
mbed_official 76:aeb1df146756 162 ----------------------------------------------------------------
mbed_official 76:aeb1df146756 163 [..]
mbed_official 76:aeb1df146756 164 (+) void FLASH_PrefetchBufferCmd(FunctionalState NewState);
mbed_official 76:aeb1df146756 165 (+) void FLASH_ReadAccess64Cmd(FunctionalState NewState);
mbed_official 76:aeb1df146756 166 (+) void FLASH_RUNPowerDownCmd(FunctionalState NewState);
mbed_official 76:aeb1df146756 167 (+) void FLASH_SLEEPPowerDownCmd(FunctionalState NewState);
mbed_official 76:aeb1df146756 168 (+) void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
mbed_official 76:aeb1df146756 169 [..]
mbed_official 76:aeb1df146756 170 Here below the allowed configuration of Latency, 64Bit access and prefetch buffer
mbed_official 76:aeb1df146756 171 [..]
mbed_official 76:aeb1df146756 172 --------------------------------------------------------------------------------
mbed_official 76:aeb1df146756 173 | | ACC64 = 0 | ACC64 = 1 |
mbed_official 76:aeb1df146756 174 | Latency |----------------|---------------|---------------|---------------|
mbed_official 76:aeb1df146756 175 | | PRFTEN = 0 | PRFTEN = 1 | PRFTEN = 0 | PRFTEN = 1 |
mbed_official 76:aeb1df146756 176 |---------------|----------------|---------------|---------------|---------------|
mbed_official 76:aeb1df146756 177 |0WS(1CPU cycle)| YES | NO | YES | YES |
mbed_official 76:aeb1df146756 178 |---------------|----------------|---------------|---------------|---------------|
mbed_official 76:aeb1df146756 179 |1WS(2CPU cycle)| NO | NO | YES | YES |
mbed_official 76:aeb1df146756 180 --------------------------------------------------------------------------------
mbed_official 76:aeb1df146756 181 [..]
mbed_official 76:aeb1df146756 182 All these functions don't need the unlock sequence.
mbed_official 76:aeb1df146756 183
mbed_official 76:aeb1df146756 184 @endverbatim
mbed_official 76:aeb1df146756 185 * @{
mbed_official 76:aeb1df146756 186 */
mbed_official 76:aeb1df146756 187
mbed_official 76:aeb1df146756 188 /**
mbed_official 76:aeb1df146756 189 * @brief Sets the code latency value.
mbed_official 76:aeb1df146756 190 * @param FLASH_Latency: specifies the FLASH Latency value.
mbed_official 76:aeb1df146756 191 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 192 * @arg FLASH_Latency_0: FLASH Zero Latency cycle.
mbed_official 76:aeb1df146756 193 * @arg FLASH_Latency_1: FLASH One Latency cycle.
mbed_official 76:aeb1df146756 194 * @retval None
mbed_official 76:aeb1df146756 195 */
mbed_official 76:aeb1df146756 196 void FLASH_SetLatency(uint32_t FLASH_Latency)
mbed_official 76:aeb1df146756 197 {
mbed_official 76:aeb1df146756 198 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 199
mbed_official 76:aeb1df146756 200 /* Check the parameters */
mbed_official 76:aeb1df146756 201 assert_param(IS_FLASH_LATENCY(FLASH_Latency));
mbed_official 76:aeb1df146756 202
mbed_official 76:aeb1df146756 203 /* Read the ACR register */
mbed_official 76:aeb1df146756 204 tmpreg = FLASH->ACR;
mbed_official 76:aeb1df146756 205
mbed_official 76:aeb1df146756 206 /* Sets the Latency value */
mbed_official 76:aeb1df146756 207 tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY));
mbed_official 76:aeb1df146756 208 tmpreg |= FLASH_Latency;
mbed_official 76:aeb1df146756 209
mbed_official 76:aeb1df146756 210 /* Write the ACR register */
mbed_official 76:aeb1df146756 211 FLASH->ACR = tmpreg;
mbed_official 76:aeb1df146756 212 }
mbed_official 76:aeb1df146756 213
mbed_official 76:aeb1df146756 214 /**
mbed_official 76:aeb1df146756 215 * @brief Enables or disables the Prefetch Buffer.
mbed_official 76:aeb1df146756 216 * @param NewState: new state of the FLASH prefetch buffer.
mbed_official 76:aeb1df146756 217 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 218 * @retval None
mbed_official 76:aeb1df146756 219 */
mbed_official 76:aeb1df146756 220 void FLASH_PrefetchBufferCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 221 {
mbed_official 76:aeb1df146756 222 /* Check the parameters */
mbed_official 76:aeb1df146756 223 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 224
mbed_official 76:aeb1df146756 225 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 226 {
mbed_official 76:aeb1df146756 227 FLASH->ACR |= FLASH_ACR_PRFTEN;
mbed_official 76:aeb1df146756 228 }
mbed_official 76:aeb1df146756 229 else
mbed_official 76:aeb1df146756 230 {
mbed_official 76:aeb1df146756 231 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTEN));
mbed_official 76:aeb1df146756 232 }
mbed_official 76:aeb1df146756 233 }
mbed_official 76:aeb1df146756 234
mbed_official 76:aeb1df146756 235 /**
mbed_official 76:aeb1df146756 236 * @brief Enables or disables read access to flash by 64 bits.
mbed_official 76:aeb1df146756 237 * @param NewState: new state of the FLASH read access mode.
mbed_official 76:aeb1df146756 238 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 239 * @note If this bit is set, the Read access 64 bit is used.
mbed_official 76:aeb1df146756 240 * If this bit is reset, the Read access 32 bit is used.
mbed_official 76:aeb1df146756 241 * @note This bit cannot be written at the same time as the LATENCY and
mbed_official 76:aeb1df146756 242 * PRFTEN bits.
mbed_official 76:aeb1df146756 243 * To reset this bit, the LATENCY should be zero wait state and the
mbed_official 76:aeb1df146756 244 * prefetch off.
mbed_official 76:aeb1df146756 245 * @retval None
mbed_official 76:aeb1df146756 246 */
mbed_official 76:aeb1df146756 247 void FLASH_ReadAccess64Cmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 248 {
mbed_official 76:aeb1df146756 249 /* Check the parameters */
mbed_official 76:aeb1df146756 250 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 251
mbed_official 76:aeb1df146756 252 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 253 {
mbed_official 76:aeb1df146756 254 FLASH->ACR |= FLASH_ACR_ACC64;
mbed_official 76:aeb1df146756 255 }
mbed_official 76:aeb1df146756 256 else
mbed_official 76:aeb1df146756 257 {
mbed_official 76:aeb1df146756 258 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_ACC64));
mbed_official 76:aeb1df146756 259 }
mbed_official 76:aeb1df146756 260 }
mbed_official 76:aeb1df146756 261
mbed_official 76:aeb1df146756 262 /**
mbed_official 76:aeb1df146756 263 * @brief Enable or disable the power down mode during Sleep mode.
mbed_official 76:aeb1df146756 264 * @note This function is used to power down the FLASH when the system is in SLEEP LP mode.
mbed_official 76:aeb1df146756 265 * @param NewState: new state of the power down mode during sleep mode.
mbed_official 76:aeb1df146756 266 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 267 * @retval None
mbed_official 76:aeb1df146756 268 */
mbed_official 76:aeb1df146756 269 void FLASH_SLEEPPowerDownCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 270 {
mbed_official 76:aeb1df146756 271 /* Check the parameters */
mbed_official 76:aeb1df146756 272 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 275 {
mbed_official 76:aeb1df146756 276 /* Set the SLEEP_PD bit to put Flash in power down mode during sleep mode */
mbed_official 76:aeb1df146756 277 FLASH->ACR |= FLASH_ACR_SLEEP_PD;
mbed_official 76:aeb1df146756 278 }
mbed_official 76:aeb1df146756 279 else
mbed_official 76:aeb1df146756 280 {
mbed_official 76:aeb1df146756 281 /* Clear the SLEEP_PD bit in to put Flash in idle mode during sleep mode */
mbed_official 76:aeb1df146756 282 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_SLEEP_PD));
mbed_official 76:aeb1df146756 283 }
mbed_official 76:aeb1df146756 284 }
mbed_official 76:aeb1df146756 285
mbed_official 76:aeb1df146756 286 /**
mbed_official 76:aeb1df146756 287 * @}
mbed_official 76:aeb1df146756 288 */
mbed_official 76:aeb1df146756 289
mbed_official 76:aeb1df146756 290 /** @defgroup FLASH_Group2 FLASH Memory Programming functions
mbed_official 76:aeb1df146756 291 * @brief FLASH Memory Programming functions
mbed_official 76:aeb1df146756 292 *
mbed_official 76:aeb1df146756 293 @verbatim
mbed_official 76:aeb1df146756 294 ==============================================================================
mbed_official 76:aeb1df146756 295 ##### FLASH Memory Programming functions #####
mbed_official 76:aeb1df146756 296 ==============================================================================
mbed_official 76:aeb1df146756 297
mbed_official 76:aeb1df146756 298 [..] The FLASH Memory Programming functions, includes the following functions:
mbed_official 76:aeb1df146756 299 (+) void FLASH_Unlock(void);
mbed_official 76:aeb1df146756 300 (+) void FLASH_Lock(void);
mbed_official 76:aeb1df146756 301 (+) FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
mbed_official 76:aeb1df146756 302 (+) FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data);
mbed_official 76:aeb1df146756 303
mbed_official 76:aeb1df146756 304 [..] Any operation of erase or program should follow these steps:
mbed_official 76:aeb1df146756 305 (#) Call the FLASH_Unlock() function to enable the flash control register and
mbed_official 76:aeb1df146756 306 program memory access.
mbed_official 76:aeb1df146756 307 (#) Call the desired function to erase page or program data.
mbed_official 76:aeb1df146756 308 (#) Call the FLASH_Lock() to disable the flash program memory access
mbed_official 76:aeb1df146756 309 (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 76:aeb1df146756 310
mbed_official 76:aeb1df146756 311 @endverbatim
mbed_official 76:aeb1df146756 312 * @{
mbed_official 76:aeb1df146756 313 */
mbed_official 76:aeb1df146756 314
mbed_official 76:aeb1df146756 315 /**
mbed_official 76:aeb1df146756 316 * @brief Unlocks the FLASH control register and program memory access.
mbed_official 76:aeb1df146756 317 * @param None
mbed_official 76:aeb1df146756 318 * @retval None
mbed_official 76:aeb1df146756 319 */
mbed_official 76:aeb1df146756 320 void FLASH_Unlock(void)
mbed_official 76:aeb1df146756 321 {
mbed_official 76:aeb1df146756 322 if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET)
mbed_official 76:aeb1df146756 323 {
mbed_official 76:aeb1df146756 324 /* Unlocking the data memory and FLASH_PECR register access */
mbed_official 76:aeb1df146756 325 DATA_EEPROM_Unlock();
mbed_official 76:aeb1df146756 326
mbed_official 76:aeb1df146756 327 /* Unlocking the program memory access */
mbed_official 76:aeb1df146756 328 FLASH->PRGKEYR = FLASH_PRGKEY1;
mbed_official 76:aeb1df146756 329 FLASH->PRGKEYR = FLASH_PRGKEY2;
mbed_official 76:aeb1df146756 330 }
mbed_official 76:aeb1df146756 331 }
mbed_official 76:aeb1df146756 332
mbed_official 76:aeb1df146756 333 /**
mbed_official 76:aeb1df146756 334 * @brief Locks the Program memory access.
mbed_official 76:aeb1df146756 335 * @param None
mbed_official 76:aeb1df146756 336 * @retval None
mbed_official 76:aeb1df146756 337 */
mbed_official 76:aeb1df146756 338 void FLASH_Lock(void)
mbed_official 76:aeb1df146756 339 {
mbed_official 76:aeb1df146756 340 /* Set the PRGLOCK Bit to lock the program memory access */
mbed_official 76:aeb1df146756 341 FLASH->PECR |= FLASH_PECR_PRGLOCK;
mbed_official 76:aeb1df146756 342 }
mbed_official 76:aeb1df146756 343
mbed_official 76:aeb1df146756 344 /**
mbed_official 76:aeb1df146756 345 * @brief Erases a specified page in program memory.
mbed_official 76:aeb1df146756 346 * @note To correctly run this function, the FLASH_Unlock() function
mbed_official 76:aeb1df146756 347 * must be called before.
mbed_official 76:aeb1df146756 348 * Call the FLASH_Lock() to disable the flash memory access
mbed_official 76:aeb1df146756 349 * (recommended to protect the FLASH memory against possible unwanted operation)
mbed_official 76:aeb1df146756 350 * @param Page_Address: The page address in program memory to be erased.
mbed_official 76:aeb1df146756 351 * @note A Page is erased in the Program memory only if the address to load
mbed_official 76:aeb1df146756 352 * is the start address of a page (multiple of 256 bytes).
mbed_official 76:aeb1df146756 353 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 354 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 355 */
mbed_official 76:aeb1df146756 356 FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
mbed_official 76:aeb1df146756 357 {
mbed_official 76:aeb1df146756 358 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 359
mbed_official 76:aeb1df146756 360 /* Check the parameters */
mbed_official 76:aeb1df146756 361 assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address));
mbed_official 76:aeb1df146756 362
mbed_official 76:aeb1df146756 363 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 364 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 365
mbed_official 76:aeb1df146756 366 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 367 {
mbed_official 76:aeb1df146756 368 /* If the previous operation is completed, proceed to erase the page */
mbed_official 76:aeb1df146756 369
mbed_official 76:aeb1df146756 370 /* Set the ERASE bit */
mbed_official 76:aeb1df146756 371 FLASH->PECR |= FLASH_PECR_ERASE;
mbed_official 76:aeb1df146756 372
mbed_official 76:aeb1df146756 373 /* Set PROG bit */
mbed_official 76:aeb1df146756 374 FLASH->PECR |= FLASH_PECR_PROG;
mbed_official 76:aeb1df146756 375
mbed_official 76:aeb1df146756 376 /* Write 00000000h to the first word of the program page to erase */
mbed_official 76:aeb1df146756 377 *(__IO uint32_t *)Page_Address = 0x00000000;
mbed_official 76:aeb1df146756 378
mbed_official 76:aeb1df146756 379 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 380 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 381
mbed_official 76:aeb1df146756 382 /* If the erase operation is completed, disable the ERASE and PROG bits */
mbed_official 76:aeb1df146756 383 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);
mbed_official 76:aeb1df146756 384 FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE);
mbed_official 76:aeb1df146756 385 }
mbed_official 76:aeb1df146756 386 /* Return the Erase Status */
mbed_official 76:aeb1df146756 387 return status;
mbed_official 76:aeb1df146756 388 }
mbed_official 76:aeb1df146756 389
mbed_official 76:aeb1df146756 390 /**
mbed_official 76:aeb1df146756 391 * @brief Programs a word at a specified address in program memory.
mbed_official 76:aeb1df146756 392 * @note To correctly run this function, the FLASH_Unlock() function
mbed_official 76:aeb1df146756 393 * must be called before.
mbed_official 76:aeb1df146756 394 * Call the FLASH_Lock() to disable the flash memory access
mbed_official 76:aeb1df146756 395 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 76:aeb1df146756 396 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 397 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 398 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 399 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 400 */
mbed_official 76:aeb1df146756 401 FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data)
mbed_official 76:aeb1df146756 402 {
mbed_official 76:aeb1df146756 403 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 404
mbed_official 76:aeb1df146756 405 /* Check the parameters */
mbed_official 76:aeb1df146756 406 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 76:aeb1df146756 407
mbed_official 76:aeb1df146756 408 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 409 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 410
mbed_official 76:aeb1df146756 411 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 412 {
mbed_official 76:aeb1df146756 413 /* If the previous operation is completed, proceed to program the new word */
mbed_official 76:aeb1df146756 414 *(__IO uint32_t *)Address = Data;
mbed_official 76:aeb1df146756 415
mbed_official 76:aeb1df146756 416 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 417 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 418 }
mbed_official 76:aeb1df146756 419 /* Return the Write Status */
mbed_official 76:aeb1df146756 420 return status;
mbed_official 76:aeb1df146756 421 }
mbed_official 76:aeb1df146756 422
mbed_official 76:aeb1df146756 423 /**
mbed_official 76:aeb1df146756 424 * @}
mbed_official 76:aeb1df146756 425 */
mbed_official 76:aeb1df146756 426
mbed_official 76:aeb1df146756 427 /** @defgroup FLASH_Group3 DATA EEPROM Programming functions
mbed_official 76:aeb1df146756 428 * @brief DATA EEPROM Programming functions
mbed_official 76:aeb1df146756 429 *
mbed_official 76:aeb1df146756 430 @verbatim
mbed_official 76:aeb1df146756 431 ===============================================================================
mbed_official 76:aeb1df146756 432 ##### DATA EEPROM Programming functions #####
mbed_official 76:aeb1df146756 433 ===============================================================================
mbed_official 76:aeb1df146756 434
mbed_official 76:aeb1df146756 435 [..] The DATA_EEPROM Programming_Functions, includes the following functions:
mbed_official 76:aeb1df146756 436 (+) void DATA_EEPROM_Unlock(void);
mbed_official 76:aeb1df146756 437 (+) void DATA_EEPROM_Lock(void);
mbed_official 76:aeb1df146756 438 (+) FLASH_Status DATA_EEPROM_EraseByte(uint32_t Address);
mbed_official 76:aeb1df146756 439 (+) FLASH_Status DATA_EEPROM_EraseHalfWord(uint32_t Address);
mbed_official 76:aeb1df146756 440 (+) FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address);
mbed_official 76:aeb1df146756 441 (+) FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data);
mbed_official 76:aeb1df146756 442 (+) FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data);
mbed_official 76:aeb1df146756 443 (+) FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data);
mbed_official 76:aeb1df146756 444 (+) FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data);
mbed_official 76:aeb1df146756 445 (+) FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data);
mbed_official 76:aeb1df146756 446 (+) FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data);
mbed_official 76:aeb1df146756 447
mbed_official 76:aeb1df146756 448 [..] Any operation of erase or program should follow these steps:
mbed_official 76:aeb1df146756 449 (#) Call the DATA_EEPROM_Unlock() function to enable the data EEPROM access
mbed_official 76:aeb1df146756 450 and Flash program erase control register access.
mbed_official 76:aeb1df146756 451 (#) Call the desired function to erase or program data.
mbed_official 76:aeb1df146756 452 (#) Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 453 and Flash program erase control register access(recommended
mbed_official 76:aeb1df146756 454 to protect the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 455
mbed_official 76:aeb1df146756 456 @endverbatim
mbed_official 76:aeb1df146756 457 * @{
mbed_official 76:aeb1df146756 458 */
mbed_official 76:aeb1df146756 459
mbed_official 76:aeb1df146756 460 /**
mbed_official 76:aeb1df146756 461 * @brief Unlocks the data memory and FLASH_PECR register access.
mbed_official 76:aeb1df146756 462 * @param None
mbed_official 76:aeb1df146756 463 * @retval None
mbed_official 76:aeb1df146756 464 */
mbed_official 76:aeb1df146756 465 void DATA_EEPROM_Unlock(void)
mbed_official 76:aeb1df146756 466 {
mbed_official 76:aeb1df146756 467 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
mbed_official 76:aeb1df146756 468 {
mbed_official 76:aeb1df146756 469 /* Unlocking the Data memory and FLASH_PECR register access*/
mbed_official 76:aeb1df146756 470 FLASH->PEKEYR = FLASH_PEKEY1;
mbed_official 76:aeb1df146756 471 FLASH->PEKEYR = FLASH_PEKEY2;
mbed_official 76:aeb1df146756 472 }
mbed_official 76:aeb1df146756 473 }
mbed_official 76:aeb1df146756 474
mbed_official 76:aeb1df146756 475 /**
mbed_official 76:aeb1df146756 476 * @brief Locks the Data memory and FLASH_PECR register access.
mbed_official 76:aeb1df146756 477 * @param None
mbed_official 76:aeb1df146756 478 * @retval None
mbed_official 76:aeb1df146756 479 */
mbed_official 76:aeb1df146756 480 void DATA_EEPROM_Lock(void)
mbed_official 76:aeb1df146756 481 {
mbed_official 76:aeb1df146756 482 /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */
mbed_official 76:aeb1df146756 483 FLASH->PECR |= FLASH_PECR_PELOCK;
mbed_official 76:aeb1df146756 484 }
mbed_official 76:aeb1df146756 485
mbed_official 76:aeb1df146756 486 /**
mbed_official 76:aeb1df146756 487 * @brief Enables or disables DATA EEPROM fixed Time programming (2*Tprog).
mbed_official 76:aeb1df146756 488 * @param NewState: new state of the DATA EEPROM fixed Time programming mode.
mbed_official 76:aeb1df146756 489 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 490 * @retval None
mbed_official 76:aeb1df146756 491 */
mbed_official 76:aeb1df146756 492 void DATA_EEPROM_FixedTimeProgramCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 493 {
mbed_official 76:aeb1df146756 494 /* Check the parameters */
mbed_official 76:aeb1df146756 495 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 496
mbed_official 76:aeb1df146756 497 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 498 {
mbed_official 76:aeb1df146756 499 FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW;
mbed_official 76:aeb1df146756 500 }
mbed_official 76:aeb1df146756 501 else
mbed_official 76:aeb1df146756 502 {
mbed_official 76:aeb1df146756 503 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
mbed_official 76:aeb1df146756 504 }
mbed_official 76:aeb1df146756 505 }
mbed_official 76:aeb1df146756 506
mbed_official 76:aeb1df146756 507 /**
mbed_official 76:aeb1df146756 508 * @brief Erase a byte in data memory.
mbed_official 76:aeb1df146756 509 * @param Address: specifies the address to be erased.
mbed_official 80:66393a7b209d 510 * @note This function can be used only for STM32L1XX_HD, STM32L1XX_MDP and
mbed_official 80:66393a7b209d 511 * STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 512 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 513 * must be called before.
mbed_official 80:66393a7b209d 514 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 515 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 516 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 517 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 518 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 519 */
mbed_official 76:aeb1df146756 520 FLASH_Status DATA_EEPROM_EraseByte(uint32_t Address)
mbed_official 76:aeb1df146756 521 {
mbed_official 76:aeb1df146756 522 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 523
mbed_official 76:aeb1df146756 524 /* Check the parameters */
mbed_official 76:aeb1df146756 525 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 526
mbed_official 76:aeb1df146756 527 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 528 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 529
mbed_official 76:aeb1df146756 530 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 531 {
mbed_official 76:aeb1df146756 532 /* Write "00h" to valid address in the data memory" */
mbed_official 76:aeb1df146756 533 *(__IO uint8_t *) Address = (uint8_t)0x00;
mbed_official 76:aeb1df146756 534 }
mbed_official 76:aeb1df146756 535
mbed_official 76:aeb1df146756 536 /* Return the erase status */
mbed_official 76:aeb1df146756 537 return status;
mbed_official 76:aeb1df146756 538 }
mbed_official 76:aeb1df146756 539
mbed_official 76:aeb1df146756 540 /**
mbed_official 76:aeb1df146756 541 * @brief Erase a halfword in data memory.
mbed_official 76:aeb1df146756 542 * @param Address: specifies the address to be erased.
mbed_official 80:66393a7b209d 543 * @note This function can be used only for STM32L1XX_HD, STM32L1XX_MDP and
mbed_official 80:66393a7b209d 544 * STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 545 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 546 * must be called before.
mbed_official 80:66393a7b209d 547 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 548 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 549 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 550 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 551 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 552 */
mbed_official 76:aeb1df146756 553 FLASH_Status DATA_EEPROM_EraseHalfWord(uint32_t Address)
mbed_official 76:aeb1df146756 554 {
mbed_official 76:aeb1df146756 555 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 556
mbed_official 76:aeb1df146756 557 /* Check the parameters */
mbed_official 76:aeb1df146756 558 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 559
mbed_official 76:aeb1df146756 560 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 561 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 562
mbed_official 76:aeb1df146756 563 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 564 {
mbed_official 76:aeb1df146756 565 /* Write "0000h" to valid address in the data memory" */
mbed_official 76:aeb1df146756 566 *(__IO uint16_t *) Address = (uint16_t)0x0000;
mbed_official 76:aeb1df146756 567 }
mbed_official 76:aeb1df146756 568
mbed_official 76:aeb1df146756 569 /* Return the erase status */
mbed_official 76:aeb1df146756 570 return status;
mbed_official 76:aeb1df146756 571 }
mbed_official 76:aeb1df146756 572
mbed_official 76:aeb1df146756 573 /**
mbed_official 76:aeb1df146756 574 * @brief Erase a word in data memory.
mbed_official 76:aeb1df146756 575 * @param Address: specifies the address to be erased.
mbed_official 76:aeb1df146756 576 * @note For STM32L1XX_MD, A data memory word is erased in the data memory only
mbed_official 76:aeb1df146756 577 * if the address to load is the start address of a word (multiple of a word).
mbed_official 76:aeb1df146756 578 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 579 * must be called before.
mbed_official 80:66393a7b209d 580 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 581 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 582 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 583 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 584 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 585 */
mbed_official 76:aeb1df146756 586 FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address)
mbed_official 76:aeb1df146756 587 {
mbed_official 76:aeb1df146756 588 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 589
mbed_official 76:aeb1df146756 590 /* Check the parameters */
mbed_official 76:aeb1df146756 591 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 592
mbed_official 76:aeb1df146756 593 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 594 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 595
mbed_official 76:aeb1df146756 596 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 597 {
mbed_official 76:aeb1df146756 598 /* Write "00000000h" to valid address in the data memory" */
mbed_official 76:aeb1df146756 599 *(__IO uint32_t *) Address = 0x00000000;
mbed_official 76:aeb1df146756 600 }
mbed_official 76:aeb1df146756 601
mbed_official 76:aeb1df146756 602 /* Return the erase status */
mbed_official 76:aeb1df146756 603 return status;
mbed_official 76:aeb1df146756 604 }
mbed_official 76:aeb1df146756 605
mbed_official 76:aeb1df146756 606 /**
mbed_official 76:aeb1df146756 607 * @brief Write a Byte at a specified address in data memory.
mbed_official 76:aeb1df146756 608 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 609 * must be called before.
mbed_official 80:66393a7b209d 610 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 611 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 612 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 613 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 614 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 615 * @note This function assumes that the is data word is already erased.
mbed_official 76:aeb1df146756 616 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 617 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 618 */
mbed_official 76:aeb1df146756 619 FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data)
mbed_official 76:aeb1df146756 620 {
mbed_official 76:aeb1df146756 621 FLASH_Status status = FLASH_COMPLETE;
mbed_official 80:66393a7b209d 622 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 623 uint32_t tmp = 0, tmpaddr = 0;
mbed_official 76:aeb1df146756 624 #endif
mbed_official 76:aeb1df146756 625
mbed_official 76:aeb1df146756 626 /* Check the parameters */
mbed_official 76:aeb1df146756 627 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 628
mbed_official 76:aeb1df146756 629 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 630 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 631
mbed_official 76:aeb1df146756 632 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 633 {
mbed_official 76:aeb1df146756 634 /* Clear the FTDW bit */
mbed_official 76:aeb1df146756 635 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
mbed_official 76:aeb1df146756 636
mbed_official 80:66393a7b209d 637 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 638 if(Data != (uint8_t)0x00)
mbed_official 76:aeb1df146756 639 {
mbed_official 76:aeb1df146756 640 /* If the previous operation is completed, proceed to write the new Data */
mbed_official 76:aeb1df146756 641 *(__IO uint8_t *)Address = Data;
mbed_official 76:aeb1df146756 642
mbed_official 76:aeb1df146756 643 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 644 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 645 }
mbed_official 76:aeb1df146756 646 else
mbed_official 76:aeb1df146756 647 {
mbed_official 76:aeb1df146756 648 tmpaddr = Address & 0xFFFFFFFC;
mbed_official 76:aeb1df146756 649 tmp = * (__IO uint32_t *) tmpaddr;
mbed_official 76:aeb1df146756 650 tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));
mbed_official 76:aeb1df146756 651 tmp &= ~tmpaddr;
mbed_official 76:aeb1df146756 652 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
mbed_official 76:aeb1df146756 653 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
mbed_official 76:aeb1df146756 654 }
mbed_official 80:66393a7b209d 655 #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) || defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 656 /* If the previous operation is completed, proceed to write the new Data */
mbed_official 76:aeb1df146756 657 *(__IO uint8_t *)Address = Data;
mbed_official 76:aeb1df146756 658
mbed_official 76:aeb1df146756 659 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 660 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 661 #endif
mbed_official 76:aeb1df146756 662 }
mbed_official 76:aeb1df146756 663 /* Return the Write Status */
mbed_official 76:aeb1df146756 664 return status;
mbed_official 76:aeb1df146756 665 }
mbed_official 76:aeb1df146756 666
mbed_official 76:aeb1df146756 667 /**
mbed_official 76:aeb1df146756 668 * @brief Writes a half word at a specified address in data memory.
mbed_official 76:aeb1df146756 669 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 670 * must be called before.
mbed_official 80:66393a7b209d 671 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 672 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 673 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 674 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 675 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 676 * @note This function assumes that the is data word is already erased.
mbed_official 76:aeb1df146756 677 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 678 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 679 */
mbed_official 76:aeb1df146756 680 FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data)
mbed_official 76:aeb1df146756 681 {
mbed_official 76:aeb1df146756 682 FLASH_Status status = FLASH_COMPLETE;
mbed_official 80:66393a7b209d 683 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 684 uint32_t tmp = 0, tmpaddr = 0;
mbed_official 76:aeb1df146756 685 #endif
mbed_official 76:aeb1df146756 686
mbed_official 76:aeb1df146756 687 /* Check the parameters */
mbed_official 76:aeb1df146756 688 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 689
mbed_official 76:aeb1df146756 690 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 691 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 692
mbed_official 76:aeb1df146756 693 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 694 {
mbed_official 76:aeb1df146756 695 /* Clear the FTDW bit */
mbed_official 76:aeb1df146756 696 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
mbed_official 76:aeb1df146756 697
mbed_official 80:66393a7b209d 698 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 699 if(Data != (uint16_t)0x0000)
mbed_official 76:aeb1df146756 700 {
mbed_official 76:aeb1df146756 701 /* If the previous operation is completed, proceed to write the new data */
mbed_official 76:aeb1df146756 702 *(__IO uint16_t *)Address = Data;
mbed_official 76:aeb1df146756 703
mbed_official 76:aeb1df146756 704 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 705 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 706 }
mbed_official 76:aeb1df146756 707 else
mbed_official 76:aeb1df146756 708 {
mbed_official 76:aeb1df146756 709 if((Address & 0x3) != 0x3)
mbed_official 76:aeb1df146756 710 {
mbed_official 76:aeb1df146756 711 tmpaddr = Address & 0xFFFFFFFC;
mbed_official 76:aeb1df146756 712 tmp = * (__IO uint32_t *) tmpaddr;
mbed_official 76:aeb1df146756 713 tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));
mbed_official 76:aeb1df146756 714 tmp &= ~tmpaddr;
mbed_official 76:aeb1df146756 715 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
mbed_official 76:aeb1df146756 716 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
mbed_official 76:aeb1df146756 717 }
mbed_official 76:aeb1df146756 718 else
mbed_official 76:aeb1df146756 719 {
mbed_official 76:aeb1df146756 720 DATA_EEPROM_FastProgramByte(Address, 0x00);
mbed_official 76:aeb1df146756 721 DATA_EEPROM_FastProgramByte(Address + 1, 0x00);
mbed_official 76:aeb1df146756 722 }
mbed_official 76:aeb1df146756 723 }
mbed_official 80:66393a7b209d 724 #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) || defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 725 /* If the previous operation is completed, proceed to write the new data */
mbed_official 76:aeb1df146756 726 *(__IO uint16_t *)Address = Data;
mbed_official 76:aeb1df146756 727
mbed_official 76:aeb1df146756 728 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 729 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 730 #endif
mbed_official 76:aeb1df146756 731 }
mbed_official 76:aeb1df146756 732 /* Return the Write Status */
mbed_official 76:aeb1df146756 733 return status;
mbed_official 76:aeb1df146756 734 }
mbed_official 76:aeb1df146756 735
mbed_official 76:aeb1df146756 736 /**
mbed_official 76:aeb1df146756 737 * @brief Programs a word at a specified address in data memory.
mbed_official 76:aeb1df146756 738 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 739 * must be called before.
mbed_official 80:66393a7b209d 740 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 741 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 742 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 743 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 744 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 745 * @note This function assumes that the is data word is already erased.
mbed_official 76:aeb1df146756 746 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 747 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 748 */
mbed_official 76:aeb1df146756 749 FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data)
mbed_official 76:aeb1df146756 750 {
mbed_official 76:aeb1df146756 751 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 752
mbed_official 76:aeb1df146756 753 /* Check the parameters */
mbed_official 76:aeb1df146756 754 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 755
mbed_official 76:aeb1df146756 756 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 757 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 758
mbed_official 76:aeb1df146756 759 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 760 {
mbed_official 76:aeb1df146756 761 /* Clear the FTDW bit */
mbed_official 76:aeb1df146756 762 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
mbed_official 76:aeb1df146756 763
mbed_official 76:aeb1df146756 764 /* If the previous operation is completed, proceed to program the new data */
mbed_official 76:aeb1df146756 765 *(__IO uint32_t *)Address = Data;
mbed_official 76:aeb1df146756 766
mbed_official 76:aeb1df146756 767 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 768 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 769 }
mbed_official 76:aeb1df146756 770 /* Return the Write Status */
mbed_official 76:aeb1df146756 771 return status;
mbed_official 76:aeb1df146756 772 }
mbed_official 76:aeb1df146756 773
mbed_official 76:aeb1df146756 774 /**
mbed_official 76:aeb1df146756 775 * @brief Write a Byte at a specified address in data memory without erase.
mbed_official 76:aeb1df146756 776 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 777 * must be called before.
mbed_official 80:66393a7b209d 778 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 779 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 780 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 781 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
mbed_official 76:aeb1df146756 782 * this function to configure the Fixed Time Programming.
mbed_official 76:aeb1df146756 783 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 784 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 785 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 786 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 787 */
mbed_official 76:aeb1df146756 788 FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data)
mbed_official 76:aeb1df146756 789 {
mbed_official 76:aeb1df146756 790 FLASH_Status status = FLASH_COMPLETE;
mbed_official 80:66393a7b209d 791 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 792 uint32_t tmp = 0, tmpaddr = 0;
mbed_official 76:aeb1df146756 793 #endif
mbed_official 76:aeb1df146756 794
mbed_official 76:aeb1df146756 795 /* Check the parameters */
mbed_official 76:aeb1df146756 796 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 797
mbed_official 76:aeb1df146756 798 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 799 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 800
mbed_official 76:aeb1df146756 801 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 802 {
mbed_official 80:66393a7b209d 803 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 804 if(Data != (uint8_t) 0x00)
mbed_official 76:aeb1df146756 805 {
mbed_official 76:aeb1df146756 806 *(__IO uint8_t *)Address = Data;
mbed_official 76:aeb1df146756 807
mbed_official 76:aeb1df146756 808 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 809 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 810
mbed_official 76:aeb1df146756 811 }
mbed_official 76:aeb1df146756 812 else
mbed_official 76:aeb1df146756 813 {
mbed_official 76:aeb1df146756 814 tmpaddr = Address & 0xFFFFFFFC;
mbed_official 76:aeb1df146756 815 tmp = * (__IO uint32_t *) tmpaddr;
mbed_official 76:aeb1df146756 816 tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));
mbed_official 76:aeb1df146756 817 tmp &= ~tmpaddr;
mbed_official 76:aeb1df146756 818 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
mbed_official 76:aeb1df146756 819 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
mbed_official 76:aeb1df146756 820 }
mbed_official 80:66393a7b209d 821 #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) || defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 822 *(__IO uint8_t *)Address = Data;
mbed_official 76:aeb1df146756 823
mbed_official 76:aeb1df146756 824 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 825 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 826 #endif
mbed_official 76:aeb1df146756 827 }
mbed_official 76:aeb1df146756 828 /* Return the Write Status */
mbed_official 76:aeb1df146756 829 return status;
mbed_official 76:aeb1df146756 830 }
mbed_official 76:aeb1df146756 831
mbed_official 76:aeb1df146756 832 /**
mbed_official 76:aeb1df146756 833 * @brief Writes a half word at a specified address in data memory without erase.
mbed_official 76:aeb1df146756 834 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 835 * must be called before.
mbed_official 80:66393a7b209d 836 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 837 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 838 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 839 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
mbed_official 76:aeb1df146756 840 * this function to configure the Fixed Time Programming
mbed_official 76:aeb1df146756 841 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 842 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 843 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 844 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 845 */
mbed_official 76:aeb1df146756 846 FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data)
mbed_official 76:aeb1df146756 847 {
mbed_official 76:aeb1df146756 848 FLASH_Status status = FLASH_COMPLETE;
mbed_official 80:66393a7b209d 849 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 850 uint32_t tmp = 0, tmpaddr = 0;
mbed_official 76:aeb1df146756 851 #endif
mbed_official 76:aeb1df146756 852
mbed_official 76:aeb1df146756 853 /* Check the parameters */
mbed_official 76:aeb1df146756 854 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 855
mbed_official 76:aeb1df146756 856 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 857 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 858
mbed_official 76:aeb1df146756 859 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 860 {
mbed_official 80:66393a7b209d 861 #if !defined (STM32L1XX_HD) && !defined (STM32L1XX_MDP) && !defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 862 if(Data != (uint16_t)0x0000)
mbed_official 76:aeb1df146756 863 {
mbed_official 76:aeb1df146756 864 *(__IO uint16_t *)Address = Data;
mbed_official 76:aeb1df146756 865
mbed_official 76:aeb1df146756 866 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 867 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 868 }
mbed_official 76:aeb1df146756 869 else
mbed_official 76:aeb1df146756 870 {
mbed_official 76:aeb1df146756 871 if((Address & 0x3) != 0x3)
mbed_official 76:aeb1df146756 872 {
mbed_official 76:aeb1df146756 873 tmpaddr = Address & 0xFFFFFFFC;
mbed_official 76:aeb1df146756 874 tmp = * (__IO uint32_t *) tmpaddr;
mbed_official 76:aeb1df146756 875 tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));
mbed_official 76:aeb1df146756 876 tmp &= ~tmpaddr;
mbed_official 76:aeb1df146756 877 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
mbed_official 76:aeb1df146756 878 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
mbed_official 76:aeb1df146756 879 }
mbed_official 76:aeb1df146756 880 else
mbed_official 76:aeb1df146756 881 {
mbed_official 76:aeb1df146756 882 DATA_EEPROM_FastProgramByte(Address, 0x00);
mbed_official 76:aeb1df146756 883 DATA_EEPROM_FastProgramByte(Address + 1, 0x00);
mbed_official 76:aeb1df146756 884 }
mbed_official 76:aeb1df146756 885 }
mbed_official 80:66393a7b209d 886 #elif defined (STM32L1XX_HD) || defined (STM32L1XX_MDP) || defined (STM32L1XX_XL)
mbed_official 76:aeb1df146756 887 *(__IO uint16_t *)Address = Data;
mbed_official 76:aeb1df146756 888
mbed_official 76:aeb1df146756 889 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 890 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 891 #endif
mbed_official 76:aeb1df146756 892 }
mbed_official 76:aeb1df146756 893 /* Return the Write Status */
mbed_official 76:aeb1df146756 894 return status;
mbed_official 76:aeb1df146756 895 }
mbed_official 76:aeb1df146756 896
mbed_official 76:aeb1df146756 897 /**
mbed_official 76:aeb1df146756 898 * @brief Programs a word at a specified address in data memory without erase.
mbed_official 76:aeb1df146756 899 * @note To correctly run this function, the DATA_EEPROM_Unlock() function
mbed_official 76:aeb1df146756 900 * must be called before.
mbed_official 80:66393a7b209d 901 * Call the DATA_EEPROM_Lock() to disable the data EEPROM access
mbed_official 76:aeb1df146756 902 * and Flash program erase control register access(recommended to protect
mbed_official 76:aeb1df146756 903 * the DATA_EEPROM against possible unwanted operation).
mbed_official 76:aeb1df146756 904 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
mbed_official 76:aeb1df146756 905 * this function to configure the Fixed Time Programming.
mbed_official 76:aeb1df146756 906 * @param Address: specifies the address to be written.
mbed_official 76:aeb1df146756 907 * @param Data: specifies the data to be written.
mbed_official 76:aeb1df146756 908 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 909 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 910 */
mbed_official 76:aeb1df146756 911 FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)
mbed_official 76:aeb1df146756 912 {
mbed_official 76:aeb1df146756 913 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 914
mbed_official 76:aeb1df146756 915 /* Check the parameters */
mbed_official 76:aeb1df146756 916 assert_param(IS_FLASH_DATA_ADDRESS(Address));
mbed_official 76:aeb1df146756 917
mbed_official 76:aeb1df146756 918 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 919 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 920
mbed_official 76:aeb1df146756 921 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 922 {
mbed_official 76:aeb1df146756 923 *(__IO uint32_t *)Address = Data;
mbed_official 76:aeb1df146756 924
mbed_official 76:aeb1df146756 925 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 926 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 927 }
mbed_official 76:aeb1df146756 928 /* Return the Write Status */
mbed_official 76:aeb1df146756 929 return status;
mbed_official 76:aeb1df146756 930 }
mbed_official 76:aeb1df146756 931
mbed_official 76:aeb1df146756 932 /**
mbed_official 76:aeb1df146756 933 * @}
mbed_official 76:aeb1df146756 934 */
mbed_official 76:aeb1df146756 935
mbed_official 76:aeb1df146756 936 /** @defgroup FLASH_Group4 Option Bytes Programming functions
mbed_official 76:aeb1df146756 937 * @brief Option Bytes Programming functions
mbed_official 76:aeb1df146756 938 *
mbed_official 76:aeb1df146756 939 @verbatim
mbed_official 76:aeb1df146756 940 ==============================================================================
mbed_official 76:aeb1df146756 941 ##### Option Bytes Programming functions #####
mbed_official 76:aeb1df146756 942 ==============================================================================
mbed_official 76:aeb1df146756 943
mbed_official 76:aeb1df146756 944 [..] The FLASH_Option Bytes Programming_functions, includes the following functions:
mbed_official 76:aeb1df146756 945 (+) void FLASH_OB_Unlock(void);
mbed_official 76:aeb1df146756 946 (+) void FLASH_OB_Lock(void);
mbed_official 76:aeb1df146756 947 (+) void FLASH_OB_Launch(void);
mbed_official 76:aeb1df146756 948 (+) FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
mbed_official 76:aeb1df146756 949 (+) FLASH_Status FLASH_OB_WRP1Config(uint32_t OB_WRP1, FunctionalState NewState);
mbed_official 76:aeb1df146756 950 (+) FLASH_Status FLASH_OB_WRP2Config(uint32_t OB_WRP2, FunctionalState NewState);
mbed_official 76:aeb1df146756 951 (+) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
mbed_official 76:aeb1df146756 952 (+) FLASH_Status FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState);
mbed_official 76:aeb1df146756 953 (+) FLASH_Status FLASH_OB_PCROP1Config(uint32_t OB_WRP1, FunctionalState NewState);
mbed_official 76:aeb1df146756 954 (+) FLASH_Status FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP);
mbed_official 76:aeb1df146756 955 (+) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
mbed_official 76:aeb1df146756 956 (+) FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR);
mbed_official 76:aeb1df146756 957 (+) uint8_t FLASH_OB_GetUser(void);
mbed_official 76:aeb1df146756 958 (+) uint32_t FLASH_OB_GetWRP(void);
mbed_official 76:aeb1df146756 959 (+) uint32_t FLASH_OB_GetWRP1(void);
mbed_official 76:aeb1df146756 960 (+) uint32_t FLASH_OB_GetWRP2(void);
mbed_official 76:aeb1df146756 961 (+) FlagStatus FLASH_OB_GetRDP(void);
mbed_official 76:aeb1df146756 962 (+) FlagStatus FLASH_OB_GetSPRMOD(void);
mbed_official 76:aeb1df146756 963 (+) uint8_t FLASH_OB_GetBOR(void);
mbed_official 76:aeb1df146756 964 (+) FLASH_Status FLASH_OB_BootConfig(uint16_t OB_BOOT);
mbed_official 76:aeb1df146756 965
mbed_official 76:aeb1df146756 966 [..] Any operation of erase or program should follow these steps:
mbed_official 76:aeb1df146756 967 (#) Call the FLASH_OB_Unlock() function to enable the Flash option control
mbed_official 76:aeb1df146756 968 register access.
mbed_official 76:aeb1df146756 969 (#) Call one or several functions to program the desired option bytes.
mbed_official 76:aeb1df146756 970 (++) void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) => to Enable/Disable
mbed_official 76:aeb1df146756 971 the desired sector write protection.
mbed_official 76:aeb1df146756 972 (++) void FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read Protection Level.
mbed_official 76:aeb1df146756 973 (++) void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) => to configure
mbed_official 76:aeb1df146756 974 the user option Bytes: IWDG, STOP and the Standby.
mbed_official 76:aeb1df146756 975 (++) void FLASH_OB_BORConfig(uint8_t OB_BOR) => to Set the BOR level.
mbed_official 76:aeb1df146756 976 (#) Once all needed option bytes to be programmed are correctly written, call the
mbed_official 76:aeb1df146756 977 FLASH_OB_Launch(void) function to launch the Option Bytes programming process.
mbed_official 76:aeb1df146756 978 (#) Call the FLASH_OB_Lock() to disable the Flash option control register access (recommended
mbed_official 76:aeb1df146756 979 to protect the option Bytes against possible unwanted operations).
mbed_official 76:aeb1df146756 980
mbed_official 76:aeb1df146756 981 [..] Proprietary code Read Out Protection (PcROP):
mbed_official 76:aeb1df146756 982 (#) The PcROP sector is selected by using the same option bytes as the Write
mbed_official 76:aeb1df146756 983 protection (nWRPi bits). As a result, these 2 options are exclusive each other.
mbed_official 76:aeb1df146756 984 (#) In order to activate the PcROP (change the function of the nWRPi option bits),
mbed_official 76:aeb1df146756 985 the SPRMOD option bit must be activated.
mbed_official 76:aeb1df146756 986 (#) The active value of nWRPi bits is inverted when PCROP mode is active, this
mbed_official 76:aeb1df146756 987 means: if SPRMOD = 1 and nWRPi = 1 (default value), then the user sector "i"
mbed_official 76:aeb1df146756 988 is read/write protected.
mbed_official 76:aeb1df146756 989 (#) To activate PCROP mode for Flash sector(s), you need to follow the sequence below:
mbed_official 76:aeb1df146756 990 (++) For sector(s) within the first 128KB of the Flash, use this function
mbed_official 76:aeb1df146756 991 FLASH_OB_PCROPConfig(OB_WRP_Pagesxxx, ENABLE)
mbed_official 76:aeb1df146756 992 (++) For sector(s) within the second 128KB of the Flash, use this function
mbed_official 76:aeb1df146756 993 FLASH_OB_PCROP1Config(OB_WRP_Pagesxxx, ENABLE)
mbed_official 76:aeb1df146756 994 (++) Activate the PCROP mode using FLASH_OB_PCROPSelectionConfig(OB_PcROP_Enable) function
mbed_official 76:aeb1df146756 995 (#) PcROP is available only in STM32L1XX_MDP devices
mbed_official 76:aeb1df146756 996
mbed_official 76:aeb1df146756 997 @endverbatim
mbed_official 76:aeb1df146756 998 * @{
mbed_official 76:aeb1df146756 999 */
mbed_official 76:aeb1df146756 1000
mbed_official 76:aeb1df146756 1001 /**
mbed_official 76:aeb1df146756 1002 * @brief Unlocks the option bytes block access.
mbed_official 76:aeb1df146756 1003 * @param None
mbed_official 76:aeb1df146756 1004 * @retval None
mbed_official 76:aeb1df146756 1005 */
mbed_official 76:aeb1df146756 1006 void FLASH_OB_Unlock(void)
mbed_official 76:aeb1df146756 1007 {
mbed_official 76:aeb1df146756 1008 if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET)
mbed_official 76:aeb1df146756 1009 {
mbed_official 76:aeb1df146756 1010 /* Unlocking the data memory and FLASH_PECR register access */
mbed_official 76:aeb1df146756 1011 DATA_EEPROM_Unlock();
mbed_official 76:aeb1df146756 1012
mbed_official 76:aeb1df146756 1013 /* Unlocking the option bytes block access */
mbed_official 76:aeb1df146756 1014 FLASH->OPTKEYR = FLASH_OPTKEY1;
mbed_official 76:aeb1df146756 1015 FLASH->OPTKEYR = FLASH_OPTKEY2;
mbed_official 76:aeb1df146756 1016 }
mbed_official 76:aeb1df146756 1017 }
mbed_official 76:aeb1df146756 1018
mbed_official 76:aeb1df146756 1019 /**
mbed_official 76:aeb1df146756 1020 * @brief Locks the option bytes block access.
mbed_official 76:aeb1df146756 1021 * @param None
mbed_official 76:aeb1df146756 1022 * @retval None
mbed_official 76:aeb1df146756 1023 */
mbed_official 76:aeb1df146756 1024 void FLASH_OB_Lock(void)
mbed_official 76:aeb1df146756 1025 {
mbed_official 76:aeb1df146756 1026 /* Set the OPTLOCK Bit to lock the option bytes block access */
mbed_official 76:aeb1df146756 1027 FLASH->PECR |= FLASH_PECR_OPTLOCK;
mbed_official 76:aeb1df146756 1028 }
mbed_official 76:aeb1df146756 1029
mbed_official 76:aeb1df146756 1030 /**
mbed_official 76:aeb1df146756 1031 * @brief Launch the option byte loading.
mbed_official 76:aeb1df146756 1032 * @param None
mbed_official 76:aeb1df146756 1033 * @retval None
mbed_official 76:aeb1df146756 1034 */
mbed_official 76:aeb1df146756 1035 void FLASH_OB_Launch(void)
mbed_official 76:aeb1df146756 1036 {
mbed_official 76:aeb1df146756 1037 /* Set the OBL_Launch bit to lauch the option byte loading */
mbed_official 76:aeb1df146756 1038 FLASH->PECR |= FLASH_PECR_OBL_LAUNCH;
mbed_official 76:aeb1df146756 1039 }
mbed_official 76:aeb1df146756 1040
mbed_official 76:aeb1df146756 1041 /**
mbed_official 76:aeb1df146756 1042 * @brief Write protects the desired pages of the first 128KB of the Flash.
mbed_official 76:aeb1df146756 1043 * @param OB_WRP: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 1044 * This parameter can be:
mbed_official 76:aeb1df146756 1045 * @arg value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511
mbed_official 76:aeb1df146756 1046 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 1047 * @param NewState: new state of the specified FLASH Pages Wtite protection.
mbed_official 76:aeb1df146756 1048 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1049 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1050 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1051 */
mbed_official 76:aeb1df146756 1052 FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
mbed_official 76:aeb1df146756 1053 {
mbed_official 76:aeb1df146756 1054 uint32_t WRP01_Data = 0, WRP23_Data = 0;
mbed_official 76:aeb1df146756 1055
mbed_official 76:aeb1df146756 1056 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1057 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 76:aeb1df146756 1058
mbed_official 76:aeb1df146756 1059 /* Check the parameters */
mbed_official 76:aeb1df146756 1060 assert_param(IS_OB_WRP(OB_WRP));
mbed_official 76:aeb1df146756 1061 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1062
mbed_official 76:aeb1df146756 1063 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1064 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1065
mbed_official 76:aeb1df146756 1066 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1067 {
mbed_official 76:aeb1df146756 1068 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1069 {
mbed_official 76:aeb1df146756 1070 WRP01_Data = (uint16_t)(((OB_WRP & WRP01_MASK) | OB->WRP01));
mbed_official 76:aeb1df146756 1071 WRP23_Data = (uint16_t)((((OB_WRP & WRP23_MASK)>>16 | OB->WRP23)));
mbed_official 76:aeb1df146756 1072 tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data);
mbed_official 76:aeb1df146756 1073 OB->WRP01 = tmp1;
mbed_official 76:aeb1df146756 1074
mbed_official 76:aeb1df146756 1075 tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data);
mbed_official 76:aeb1df146756 1076 OB->WRP23 = tmp2;
mbed_official 76:aeb1df146756 1077 }
mbed_official 76:aeb1df146756 1078
mbed_official 76:aeb1df146756 1079 else
mbed_official 76:aeb1df146756 1080 {
mbed_official 76:aeb1df146756 1081 WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01));
mbed_official 76:aeb1df146756 1082 WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23)));
mbed_official 76:aeb1df146756 1083
mbed_official 76:aeb1df146756 1084 tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data);
mbed_official 76:aeb1df146756 1085 OB->WRP01 = tmp1;
mbed_official 76:aeb1df146756 1086
mbed_official 76:aeb1df146756 1087 tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data);
mbed_official 76:aeb1df146756 1088 OB->WRP23 = tmp2;
mbed_official 76:aeb1df146756 1089 }
mbed_official 76:aeb1df146756 1090 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1091 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1092 }
mbed_official 76:aeb1df146756 1093
mbed_official 76:aeb1df146756 1094 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 1095 return status;
mbed_official 76:aeb1df146756 1096 }
mbed_official 76:aeb1df146756 1097
mbed_official 76:aeb1df146756 1098 /**
mbed_official 76:aeb1df146756 1099 * @brief Write protects the desired pages of the second 128KB of the Flash.
mbed_official 80:66393a7b209d 1100 * @note This function can be used only for STM32L1XX_HD, STM32L1XX_MDP and
mbed_official 80:66393a7b209d 1101 * STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 1102 * @param OB_WRP1: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 1103 * This parameter can be:
mbed_official 76:aeb1df146756 1104 * @arg value between OB_WRP_Pages512to527 and OB_WRP_Pages1008to1023
mbed_official 76:aeb1df146756 1105 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 1106 * @param NewState: new state of the specified FLASH Pages Wtite protection.
mbed_official 76:aeb1df146756 1107 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1108 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1109 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1110 */
mbed_official 76:aeb1df146756 1111 FLASH_Status FLASH_OB_WRP1Config(uint32_t OB_WRP1, FunctionalState NewState)
mbed_official 76:aeb1df146756 1112 {
mbed_official 76:aeb1df146756 1113 uint32_t WRP45_Data = 0, WRP67_Data = 0;
mbed_official 76:aeb1df146756 1114
mbed_official 76:aeb1df146756 1115 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1116 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 76:aeb1df146756 1117
mbed_official 76:aeb1df146756 1118 /* Check the parameters */
mbed_official 76:aeb1df146756 1119 assert_param(IS_OB_WRP(OB_WRP1));
mbed_official 76:aeb1df146756 1120 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1121
mbed_official 76:aeb1df146756 1122 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1123 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1124
mbed_official 76:aeb1df146756 1125 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1126 {
mbed_official 76:aeb1df146756 1127 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1128 {
mbed_official 76:aeb1df146756 1129 WRP45_Data = (uint16_t)(((OB_WRP1 & WRP45_MASK) | OB->WRP45));
mbed_official 76:aeb1df146756 1130 WRP67_Data = (uint16_t)((((OB_WRP1 & WRP67_MASK)>>16 | OB->WRP67)));
mbed_official 76:aeb1df146756 1131 tmp1 = (uint32_t)(~(WRP45_Data) << 16)|(WRP45_Data);
mbed_official 76:aeb1df146756 1132 OB->WRP45 = tmp1;
mbed_official 76:aeb1df146756 1133
mbed_official 76:aeb1df146756 1134 tmp2 = (uint32_t)(~(WRP67_Data) << 16)|(WRP67_Data);
mbed_official 76:aeb1df146756 1135 OB->WRP67 = tmp2;
mbed_official 76:aeb1df146756 1136 }
mbed_official 76:aeb1df146756 1137
mbed_official 76:aeb1df146756 1138 else
mbed_official 76:aeb1df146756 1139 {
mbed_official 76:aeb1df146756 1140 WRP45_Data = (uint16_t)(~OB_WRP1 & (WRP45_MASK & OB->WRP45));
mbed_official 76:aeb1df146756 1141 WRP67_Data = (uint16_t)((((~OB_WRP1 & WRP67_MASK)>>16 & OB->WRP67)));
mbed_official 76:aeb1df146756 1142
mbed_official 76:aeb1df146756 1143 tmp1 = (uint32_t)((~WRP45_Data) << 16)|(WRP45_Data);
mbed_official 76:aeb1df146756 1144 OB->WRP45 = tmp1;
mbed_official 76:aeb1df146756 1145
mbed_official 76:aeb1df146756 1146 tmp2 = (uint32_t)((~WRP67_Data) << 16)|(WRP67_Data);
mbed_official 76:aeb1df146756 1147 OB->WRP67 = tmp2;
mbed_official 76:aeb1df146756 1148 }
mbed_official 76:aeb1df146756 1149 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1150 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1151 }
mbed_official 76:aeb1df146756 1152
mbed_official 76:aeb1df146756 1153 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 1154 return status;
mbed_official 76:aeb1df146756 1155 }
mbed_official 76:aeb1df146756 1156
mbed_official 76:aeb1df146756 1157 /**
mbed_official 76:aeb1df146756 1158 * @brief Write protects the desired pages of the third 128KB of the Flash.
mbed_official 80:66393a7b209d 1159 * @note This function can be used only for STM32L1XX_HD and STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 1160 * @param OB_WRP2: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 1161 * This parameter can be:
mbed_official 76:aeb1df146756 1162 * @arg value between OB_WRP_Pages1024to1039 and OB_WRP_Pages1520to1535
mbed_official 76:aeb1df146756 1163 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 1164 * @param NewState: new state of the specified FLASH Pages Wtite protection.
mbed_official 76:aeb1df146756 1165 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1166 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1167 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1168 */
mbed_official 76:aeb1df146756 1169 FLASH_Status FLASH_OB_WRP2Config(uint32_t OB_WRP2, FunctionalState NewState)
mbed_official 76:aeb1df146756 1170 {
mbed_official 76:aeb1df146756 1171 uint32_t WRP89_Data = 0, WRP1011_Data = 0;
mbed_official 76:aeb1df146756 1172
mbed_official 76:aeb1df146756 1173 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1174 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 76:aeb1df146756 1175
mbed_official 76:aeb1df146756 1176 /* Check the parameters */
mbed_official 76:aeb1df146756 1177 assert_param(IS_OB_WRP(OB_WRP2));
mbed_official 76:aeb1df146756 1178 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1179
mbed_official 76:aeb1df146756 1180 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1181 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1182
mbed_official 76:aeb1df146756 1183 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1184 {
mbed_official 76:aeb1df146756 1185 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1186 {
mbed_official 76:aeb1df146756 1187 WRP89_Data = (uint16_t)(((OB_WRP2 & WRP89_MASK) | OB->WRP89));
mbed_official 76:aeb1df146756 1188 WRP1011_Data = (uint16_t)((((OB_WRP2 & WRP1011_MASK)>>16 | OB->WRP1011)));
mbed_official 76:aeb1df146756 1189 tmp1 = (uint32_t)(~(WRP89_Data) << 16)|(WRP89_Data);
mbed_official 76:aeb1df146756 1190 OB->WRP89 = tmp1;
mbed_official 76:aeb1df146756 1191
mbed_official 76:aeb1df146756 1192 tmp2 = (uint32_t)(~(WRP1011_Data) << 16)|(WRP1011_Data);
mbed_official 76:aeb1df146756 1193 OB->WRP1011 = tmp2;
mbed_official 76:aeb1df146756 1194 }
mbed_official 76:aeb1df146756 1195
mbed_official 76:aeb1df146756 1196 else
mbed_official 76:aeb1df146756 1197 {
mbed_official 76:aeb1df146756 1198 WRP89_Data = (uint16_t)(~OB_WRP2 & (WRP89_MASK & OB->WRP89));
mbed_official 76:aeb1df146756 1199 WRP1011_Data = (uint16_t)((((~OB_WRP2 & WRP1011_MASK)>>16 & OB->WRP1011)));
mbed_official 76:aeb1df146756 1200
mbed_official 76:aeb1df146756 1201 tmp1 = (uint32_t)((~WRP89_Data) << 16)|(WRP89_Data);
mbed_official 76:aeb1df146756 1202 OB->WRP89 = tmp1;
mbed_official 76:aeb1df146756 1203
mbed_official 76:aeb1df146756 1204 tmp2 = (uint32_t)((~WRP1011_Data) << 16)|(WRP1011_Data);
mbed_official 76:aeb1df146756 1205 OB->WRP1011 = tmp2;
mbed_official 76:aeb1df146756 1206 }
mbed_official 76:aeb1df146756 1207 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1208 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1209 }
mbed_official 76:aeb1df146756 1210
mbed_official 76:aeb1df146756 1211 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 1212 return status;
mbed_official 76:aeb1df146756 1213 }
mbed_official 76:aeb1df146756 1214
mbed_official 76:aeb1df146756 1215 /**
mbed_official 76:aeb1df146756 1216 * @brief Enables or disables the read out protection.
mbed_official 76:aeb1df146756 1217 * @note To correctly run this function, the FLASH_OB_Unlock() function
mbed_official 76:aeb1df146756 1218 * must be called before.
mbed_official 76:aeb1df146756 1219 * @param FLASH_ReadProtection_Level: specifies the read protection level.
mbed_official 76:aeb1df146756 1220 * This parameter can be:
mbed_official 76:aeb1df146756 1221 * @arg OB_RDP_Level_0: No protection
mbed_official 76:aeb1df146756 1222 * @arg OB_RDP_Level_1: Read protection of the memory
mbed_official 76:aeb1df146756 1223 * @arg OB_RDP_Level_2: Chip protection
mbed_official 76:aeb1df146756 1224 *
mbed_official 76:aeb1df146756 1225 * !!!Warning!!! When enabling OB_RDP_Level_2 it's no more possible to go back to level 1 or 0
mbed_official 76:aeb1df146756 1226 *
mbed_official 76:aeb1df146756 1227 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1228 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1229 */
mbed_official 76:aeb1df146756 1230 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP)
mbed_official 76:aeb1df146756 1231 {
mbed_official 76:aeb1df146756 1232 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1233 uint8_t tmp1 = 0;
mbed_official 76:aeb1df146756 1234 uint32_t tmp2 = 0;
mbed_official 76:aeb1df146756 1235
mbed_official 76:aeb1df146756 1236 /* Check the parameters */
mbed_official 76:aeb1df146756 1237 assert_param(IS_OB_RDP(OB_RDP));
mbed_official 76:aeb1df146756 1238 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1239
mbed_official 76:aeb1df146756 1240 /* calculate the option byte to write */
mbed_official 76:aeb1df146756 1241 tmp1 = (uint8_t)(~(OB_RDP ));
mbed_official 76:aeb1df146756 1242 tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)OB_RDP));
mbed_official 76:aeb1df146756 1243
mbed_official 76:aeb1df146756 1244 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1245 {
mbed_official 76:aeb1df146756 1246 /* program read protection level */
mbed_official 76:aeb1df146756 1247 OB->RDP = tmp2;
mbed_official 76:aeb1df146756 1248 }
mbed_official 76:aeb1df146756 1249
mbed_official 76:aeb1df146756 1250 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1251 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1252
mbed_official 76:aeb1df146756 1253 /* Return the Read protection operation Status */
mbed_official 76:aeb1df146756 1254 return status;
mbed_official 76:aeb1df146756 1255 }
mbed_official 76:aeb1df146756 1256
mbed_official 76:aeb1df146756 1257 /**
mbed_official 76:aeb1df146756 1258 * @brief Enables or disables the read/write protection (PCROP) of the desired
mbed_official 76:aeb1df146756 1259 * sectors, for the first 128KB of the Flash.
mbed_official 76:aeb1df146756 1260 * @note This function can be used only for STM32L1XX_MDP devices
mbed_official 76:aeb1df146756 1261 * @param OB_WRP: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 1262 * This parameter can be:
mbed_official 76:aeb1df146756 1263 * @arg value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511
mbed_official 76:aeb1df146756 1264 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 1265 * @param NewState: new state of the specified FLASH Pages Write protection.
mbed_official 76:aeb1df146756 1266 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1267 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1268 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1269 */
mbed_official 76:aeb1df146756 1270 FLASH_Status FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState)
mbed_official 76:aeb1df146756 1271 {
mbed_official 76:aeb1df146756 1272 uint32_t WRP01_Data = 0, WRP23_Data = 0;
mbed_official 76:aeb1df146756 1273
mbed_official 76:aeb1df146756 1274 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1275 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 76:aeb1df146756 1276
mbed_official 76:aeb1df146756 1277 /* Check the parameters */
mbed_official 76:aeb1df146756 1278 assert_param(IS_OB_WRP(OB_WRP));
mbed_official 76:aeb1df146756 1279 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1280
mbed_official 76:aeb1df146756 1281 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1282 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1283
mbed_official 76:aeb1df146756 1284 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1285 {
mbed_official 76:aeb1df146756 1286 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1287 {
mbed_official 76:aeb1df146756 1288 WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01));
mbed_official 76:aeb1df146756 1289 WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23)));
mbed_official 76:aeb1df146756 1290
mbed_official 76:aeb1df146756 1291 tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data);
mbed_official 76:aeb1df146756 1292 OB->WRP01 = tmp1;
mbed_official 76:aeb1df146756 1293
mbed_official 76:aeb1df146756 1294 tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data);
mbed_official 76:aeb1df146756 1295 OB->WRP23 = tmp2;
mbed_official 76:aeb1df146756 1296
mbed_official 76:aeb1df146756 1297 }
mbed_official 76:aeb1df146756 1298
mbed_official 76:aeb1df146756 1299 else
mbed_official 76:aeb1df146756 1300 {
mbed_official 76:aeb1df146756 1301 WRP01_Data = (uint16_t)((OB_WRP & WRP01_MASK) | OB->WRP01);
mbed_official 76:aeb1df146756 1302 WRP23_Data = (uint16_t)(((OB_WRP & WRP23_MASK) >> 16) | OB->WRP23);
mbed_official 76:aeb1df146756 1303
mbed_official 76:aeb1df146756 1304 tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data);
mbed_official 76:aeb1df146756 1305 OB->WRP01 = tmp1;
mbed_official 76:aeb1df146756 1306
mbed_official 76:aeb1df146756 1307 tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data);
mbed_official 76:aeb1df146756 1308 OB->WRP23 = tmp2;
mbed_official 76:aeb1df146756 1309
mbed_official 76:aeb1df146756 1310 }
mbed_official 76:aeb1df146756 1311 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1312 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1313 }
mbed_official 76:aeb1df146756 1314
mbed_official 76:aeb1df146756 1315 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 1316 return status;
mbed_official 76:aeb1df146756 1317 }
mbed_official 76:aeb1df146756 1318
mbed_official 76:aeb1df146756 1319 /**
mbed_official 76:aeb1df146756 1320 * @brief Enables or disables the read/write protection (PCROP) of the desired
mbed_official 76:aeb1df146756 1321 * sectors, for the second 128KB of the Flash.
mbed_official 76:aeb1df146756 1322 * @note This function can be used only for STM32L1XX_MDP devices
mbed_official 76:aeb1df146756 1323 * @param OB_WRP1: specifies the address of the pages to be write protected.
mbed_official 76:aeb1df146756 1324 * This parameter can be:
mbed_official 76:aeb1df146756 1325 * @arg value between OB_WRP_Pages512to527 and OB_WRP_Pages1008to1023
mbed_official 76:aeb1df146756 1326 * @arg OB_WRP_AllPages
mbed_official 76:aeb1df146756 1327 * @param NewState: new state of the specified FLASH Pages Write protection.
mbed_official 76:aeb1df146756 1328 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1329 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1330 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1331 */
mbed_official 76:aeb1df146756 1332 FLASH_Status FLASH_OB_PCROP1Config(uint32_t OB_WRP1, FunctionalState NewState)
mbed_official 76:aeb1df146756 1333 {
mbed_official 76:aeb1df146756 1334 uint32_t WRP45_Data = 0, WRP67_Data = 0;
mbed_official 76:aeb1df146756 1335
mbed_official 76:aeb1df146756 1336 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1337 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 76:aeb1df146756 1338
mbed_official 76:aeb1df146756 1339 /* Check the parameters */
mbed_official 76:aeb1df146756 1340 assert_param(IS_OB_WRP(OB_WRP1));
mbed_official 76:aeb1df146756 1341 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1342
mbed_official 76:aeb1df146756 1343 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1344 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1345
mbed_official 76:aeb1df146756 1346 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1347 {
mbed_official 76:aeb1df146756 1348 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1349 {
mbed_official 76:aeb1df146756 1350 WRP45_Data = (uint16_t)(~OB_WRP1 & (WRP45_MASK & OB->WRP45));
mbed_official 76:aeb1df146756 1351 WRP67_Data = (uint16_t)((((~OB_WRP1 & WRP67_MASK)>>16 & OB->WRP67)));
mbed_official 76:aeb1df146756 1352
mbed_official 76:aeb1df146756 1353 tmp1 = (uint32_t)((~WRP45_Data) << 16)|(WRP45_Data);
mbed_official 76:aeb1df146756 1354 OB->WRP45 = tmp1;
mbed_official 76:aeb1df146756 1355
mbed_official 76:aeb1df146756 1356 tmp2 = (uint32_t)((~WRP67_Data) << 16)|(WRP67_Data);
mbed_official 76:aeb1df146756 1357 OB->WRP67 = tmp2;
mbed_official 76:aeb1df146756 1358 }
mbed_official 76:aeb1df146756 1359 else
mbed_official 76:aeb1df146756 1360 {
mbed_official 76:aeb1df146756 1361 WRP45_Data = (uint16_t)((OB_WRP1 & WRP45_MASK) | OB->WRP45);
mbed_official 76:aeb1df146756 1362 WRP67_Data = (uint16_t)(((OB_WRP1 & WRP67_MASK)>>16) | OB->WRP67);
mbed_official 76:aeb1df146756 1363 tmp1 = (uint32_t)(~(WRP45_Data) << 16)|(WRP45_Data);
mbed_official 76:aeb1df146756 1364 OB->WRP45 = tmp1;
mbed_official 76:aeb1df146756 1365
mbed_official 76:aeb1df146756 1366 tmp2 = (uint32_t)(~(WRP67_Data) << 16)|(WRP67_Data);
mbed_official 76:aeb1df146756 1367 OB->WRP67 = tmp2;
mbed_official 76:aeb1df146756 1368 }
mbed_official 76:aeb1df146756 1369 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1370 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1371 }
mbed_official 76:aeb1df146756 1372
mbed_official 76:aeb1df146756 1373 /* Return the write protection operation Status */
mbed_official 76:aeb1df146756 1374 return status;
mbed_official 76:aeb1df146756 1375 }
mbed_official 76:aeb1df146756 1376
mbed_official 76:aeb1df146756 1377 /**
mbed_official 76:aeb1df146756 1378 * @brief Select the Protection Mode (SPRMOD).
mbed_official 76:aeb1df146756 1379 * @note This function can be used only for STM32L1XX_MDP devices
mbed_official 76:aeb1df146756 1380 * @note Once SPRMOD bit is active, unprotection of a protected sector is not possible
mbed_official 76:aeb1df146756 1381 * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
mbed_official 76:aeb1df146756 1382 * @param OB_PcROP: Select the Protection Mode of nWPRi bits.
mbed_official 76:aeb1df146756 1383 * This parameter can be:
mbed_official 76:aeb1df146756 1384 * @arg OB_PcROP_Enable: nWRPi control the read&write protection (PcROP) of respective user sectors.
mbed_official 76:aeb1df146756 1385 * @arg OB_PcROP_Disable: nWRPi control the write protection of respective user sectors.
mbed_official 76:aeb1df146756 1386 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1387 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1388 */
mbed_official 76:aeb1df146756 1389 FLASH_Status FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP)
mbed_official 76:aeb1df146756 1390 {
mbed_official 76:aeb1df146756 1391 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1392 uint16_t tmp1 = 0;
mbed_official 76:aeb1df146756 1393 uint32_t tmp2 = 0;
mbed_official 76:aeb1df146756 1394 uint8_t optiontmp = 0;
mbed_official 76:aeb1df146756 1395 uint16_t optiontmp2 = 0;
mbed_official 76:aeb1df146756 1396
mbed_official 76:aeb1df146756 1397 /* Check the parameters */
mbed_official 76:aeb1df146756 1398 assert_param(IS_OB_PCROP_SELECT(OB_PcROP));
mbed_official 76:aeb1df146756 1399 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1400
mbed_official 76:aeb1df146756 1401 /* Mask RDP Byte */
mbed_official 76:aeb1df146756 1402 optiontmp = (uint8_t)(*(__IO uint8_t *)(OB_BASE));
mbed_official 76:aeb1df146756 1403
mbed_official 76:aeb1df146756 1404 /* Update Option Byte */
mbed_official 76:aeb1df146756 1405 optiontmp2 = (uint16_t)(OB_PcROP | optiontmp);
mbed_official 76:aeb1df146756 1406
mbed_official 76:aeb1df146756 1407
mbed_official 76:aeb1df146756 1408 /* calculate the option byte to write */
mbed_official 76:aeb1df146756 1409 tmp1 = (uint16_t)(~(optiontmp2 ));
mbed_official 76:aeb1df146756 1410 tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)optiontmp2));
mbed_official 76:aeb1df146756 1411
mbed_official 76:aeb1df146756 1412 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1413 {
mbed_official 76:aeb1df146756 1414 /* program PCRop */
mbed_official 76:aeb1df146756 1415 OB->RDP = tmp2;
mbed_official 76:aeb1df146756 1416 }
mbed_official 76:aeb1df146756 1417
mbed_official 76:aeb1df146756 1418 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1419 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1420
mbed_official 76:aeb1df146756 1421 /* Return the Read protection operation Status */
mbed_official 76:aeb1df146756 1422 return status;
mbed_official 76:aeb1df146756 1423 }
mbed_official 76:aeb1df146756 1424
mbed_official 76:aeb1df146756 1425 /**
mbed_official 76:aeb1df146756 1426 * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
mbed_official 76:aeb1df146756 1427 * @param OB_IWDG: Selects the WDG mode.
mbed_official 76:aeb1df146756 1428 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1429 * @arg OB_IWDG_SW: Software WDG selected
mbed_official 76:aeb1df146756 1430 * @arg OB_IWDG_HW: Hardware WDG selected
mbed_official 76:aeb1df146756 1431 * @param OB_STOP: Reset event when entering STOP mode.
mbed_official 76:aeb1df146756 1432 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1433 * @arg OB_STOP_NoRST: No reset generated when entering in STOP
mbed_official 76:aeb1df146756 1434 * @arg OB_STOP_RST: Reset generated when entering in STOP
mbed_official 76:aeb1df146756 1435 * @param OB_STDBY: Reset event when entering Standby mode.
mbed_official 76:aeb1df146756 1436 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1437 * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
mbed_official 76:aeb1df146756 1438 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
mbed_official 76:aeb1df146756 1439 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1440 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1441 */
mbed_official 76:aeb1df146756 1442 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
mbed_official 76:aeb1df146756 1443 {
mbed_official 76:aeb1df146756 1444 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1445 uint32_t tmp = 0, tmp1 = 0;
mbed_official 76:aeb1df146756 1446
mbed_official 76:aeb1df146756 1447 /* Check the parameters */
mbed_official 76:aeb1df146756 1448 assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
mbed_official 76:aeb1df146756 1449 assert_param(IS_OB_STOP_SOURCE(OB_STOP));
mbed_official 76:aeb1df146756 1450 assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
mbed_official 76:aeb1df146756 1451
mbed_official 76:aeb1df146756 1452 /* Get the User Option byte register */
mbed_official 76:aeb1df146756 1453 tmp1 = (FLASH->OBR & 0x000F0000) >> 16;
mbed_official 76:aeb1df146756 1454
mbed_official 76:aeb1df146756 1455 /* Calculate the user option byte to write */
mbed_official 76:aeb1df146756 1456 tmp = (uint32_t)(((uint32_t)~((uint32_t)((uint32_t)(OB_IWDG) | (uint32_t)(OB_STOP) | (uint32_t)(OB_STDBY) | tmp1))) << ((uint32_t)0x10));
mbed_official 76:aeb1df146756 1457 tmp |= ((uint32_t)(OB_IWDG) | ((uint32_t)OB_STOP) | (uint32_t)(OB_STDBY) | tmp1);
mbed_official 76:aeb1df146756 1458
mbed_official 76:aeb1df146756 1459 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1460 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1461
mbed_official 76:aeb1df146756 1462 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1463 {
mbed_official 76:aeb1df146756 1464 /* Write the User Option Byte */
mbed_official 76:aeb1df146756 1465 OB->USER = tmp;
mbed_official 76:aeb1df146756 1466 }
mbed_official 76:aeb1df146756 1467
mbed_official 76:aeb1df146756 1468 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1469 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1470
mbed_official 76:aeb1df146756 1471 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 1472 return status;
mbed_official 76:aeb1df146756 1473 }
mbed_official 76:aeb1df146756 1474
mbed_official 76:aeb1df146756 1475 /**
mbed_official 76:aeb1df146756 1476 * @brief Programs the FLASH brownout reset threshold level Option Byte.
mbed_official 76:aeb1df146756 1477 * @param OB_BOR: Selects the brownout reset threshold level.
mbed_official 76:aeb1df146756 1478 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1479 * @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD
mbed_official 76:aeb1df146756 1480 * power supply reaches the PDR(Power Down Reset) threshold (1.5V)
mbed_official 76:aeb1df146756 1481 * @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply
mbed_official 76:aeb1df146756 1482 * @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply
mbed_official 76:aeb1df146756 1483 * @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply
mbed_official 76:aeb1df146756 1484 * @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply
mbed_official 76:aeb1df146756 1485 * @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply
mbed_official 76:aeb1df146756 1486 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1487 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1488 */
mbed_official 76:aeb1df146756 1489 FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR)
mbed_official 76:aeb1df146756 1490 {
mbed_official 76:aeb1df146756 1491 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1492 uint32_t tmp = 0, tmp1 = 0;
mbed_official 76:aeb1df146756 1493
mbed_official 76:aeb1df146756 1494 /* Check the parameters */
mbed_official 76:aeb1df146756 1495 assert_param(IS_OB_BOR_LEVEL(OB_BOR));
mbed_official 76:aeb1df146756 1496
mbed_official 76:aeb1df146756 1497 /* Get the User Option byte register */
mbed_official 76:aeb1df146756 1498 tmp1 = (FLASH->OBR & 0x00F00000) >> 16;
mbed_official 76:aeb1df146756 1499
mbed_official 76:aeb1df146756 1500 /* Calculate the option byte to write */
mbed_official 76:aeb1df146756 1501 tmp = (uint32_t)~(OB_BOR | tmp1)<<16;
mbed_official 76:aeb1df146756 1502 tmp |= (OB_BOR | tmp1);
mbed_official 76:aeb1df146756 1503
mbed_official 76:aeb1df146756 1504 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1505 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1506
mbed_official 76:aeb1df146756 1507 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1508 {
mbed_official 76:aeb1df146756 1509 /* Write the BOR Option Byte */
mbed_official 76:aeb1df146756 1510 OB->USER = tmp;
mbed_official 76:aeb1df146756 1511 }
mbed_official 76:aeb1df146756 1512
mbed_official 76:aeb1df146756 1513 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1514 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1515
mbed_official 76:aeb1df146756 1516 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 1517 return status;
mbed_official 76:aeb1df146756 1518 }
mbed_official 76:aeb1df146756 1519
mbed_official 76:aeb1df146756 1520 /**
mbed_official 76:aeb1df146756 1521 * @brief Configures to boot from Bank1 or Bank2.
mbed_official 80:66393a7b209d 1522 * @note This function can be used only for STM32L1XX_HD and STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 1523 * @param OB_BOOT: select the FLASH Bank to boot from.
mbed_official 76:aeb1df146756 1524 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1525 * @arg OB_BOOT_BANK2: At startup, if boot pins are set in boot from user Flash
mbed_official 76:aeb1df146756 1526 * position and this parameter is selected the device will boot from Bank2 or Bank1,
mbed_official 76:aeb1df146756 1527 * depending on the activation of the bank. The active banks are checked in
mbed_official 76:aeb1df146756 1528 * the following order: Bank2, followed by Bank1.
mbed_official 76:aeb1df146756 1529 * The active bank is recognized by the value programmed at the base address
mbed_official 76:aeb1df146756 1530 * of the respective bank (corresponding to the initial stack pointer value
mbed_official 76:aeb1df146756 1531 * in the interrupt vector table).
mbed_official 76:aeb1df146756 1532 * @arg OB_BOOT_BANK1: At startup, if boot pins are set in boot from user Flash
mbed_official 76:aeb1df146756 1533 * position and this parameter is selected the device will boot from Bank1(Default).
mbed_official 76:aeb1df146756 1534 * For more information, please refer to AN2606 from www.st.com.
mbed_official 76:aeb1df146756 1535 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1536 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1537 */
mbed_official 76:aeb1df146756 1538 FLASH_Status FLASH_OB_BootConfig(uint8_t OB_BOOT)
mbed_official 76:aeb1df146756 1539 {
mbed_official 76:aeb1df146756 1540 FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1541 uint32_t tmp = 0, tmp1 = 0;
mbed_official 76:aeb1df146756 1542
mbed_official 76:aeb1df146756 1543 /* Check the parameters */
mbed_official 76:aeb1df146756 1544 assert_param(IS_OB_BOOT_BANK(OB_BOOT));
mbed_official 76:aeb1df146756 1545
mbed_official 76:aeb1df146756 1546 /* Get the User Option byte register */
mbed_official 76:aeb1df146756 1547 tmp1 = (FLASH->OBR & 0x007F0000) >> 16;
mbed_official 76:aeb1df146756 1548
mbed_official 76:aeb1df146756 1549 /* Calculate the option byte to write */
mbed_official 76:aeb1df146756 1550 tmp = (uint32_t)~(OB_BOOT | tmp1)<<16;
mbed_official 76:aeb1df146756 1551 tmp |= (OB_BOOT | tmp1);
mbed_official 76:aeb1df146756 1552
mbed_official 76:aeb1df146756 1553 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1554 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1555
mbed_official 76:aeb1df146756 1556 if(status == FLASH_COMPLETE)
mbed_official 76:aeb1df146756 1557 {
mbed_official 76:aeb1df146756 1558 /* Write the BOOT Option Byte */
mbed_official 76:aeb1df146756 1559 OB->USER = tmp;
mbed_official 76:aeb1df146756 1560 }
mbed_official 76:aeb1df146756 1561
mbed_official 76:aeb1df146756 1562 /* Wait for last operation to be completed */
mbed_official 76:aeb1df146756 1563 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
mbed_official 76:aeb1df146756 1564
mbed_official 76:aeb1df146756 1565 /* Return the Option Byte program Status */
mbed_official 76:aeb1df146756 1566 return status;
mbed_official 76:aeb1df146756 1567 }
mbed_official 76:aeb1df146756 1568
mbed_official 76:aeb1df146756 1569 /**
mbed_official 76:aeb1df146756 1570 * @brief Returns the FLASH User Option Bytes values.
mbed_official 76:aeb1df146756 1571 * @param None
mbed_official 76:aeb1df146756 1572 * @retval The FLASH User Option Bytes.
mbed_official 76:aeb1df146756 1573 */
mbed_official 76:aeb1df146756 1574 uint8_t FLASH_OB_GetUser(void)
mbed_official 76:aeb1df146756 1575 {
mbed_official 76:aeb1df146756 1576 /* Return the User Option Byte */
mbed_official 76:aeb1df146756 1577 return (uint8_t)(FLASH->OBR >> 20);
mbed_official 76:aeb1df146756 1578 }
mbed_official 76:aeb1df146756 1579
mbed_official 76:aeb1df146756 1580 /**
mbed_official 76:aeb1df146756 1581 * @brief Returns the FLASH Write Protection Option Bytes value.
mbed_official 76:aeb1df146756 1582 * @param None
mbed_official 76:aeb1df146756 1583 * @retval The FLASH Write Protection Option Bytes value.
mbed_official 76:aeb1df146756 1584 */
mbed_official 76:aeb1df146756 1585 uint32_t FLASH_OB_GetWRP(void)
mbed_official 76:aeb1df146756 1586 {
mbed_official 76:aeb1df146756 1587 /* Return the FLASH write protection Register value */
mbed_official 76:aeb1df146756 1588 return (uint32_t)(FLASH->WRPR);
mbed_official 76:aeb1df146756 1589 }
mbed_official 76:aeb1df146756 1590
mbed_official 76:aeb1df146756 1591 /**
mbed_official 76:aeb1df146756 1592 * @brief Returns the FLASH Write Protection Option Bytes value.
mbed_official 80:66393a7b209d 1593 * @note This function can be used only for STM32L1XX_HD, STM32L1XX_MDP and
mbed_official 80:66393a7b209d 1594 * STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 1595 * @param None
mbed_official 76:aeb1df146756 1596 * @retval The FLASH Write Protection Option Bytes value.
mbed_official 76:aeb1df146756 1597 */
mbed_official 76:aeb1df146756 1598 uint32_t FLASH_OB_GetWRP1(void)
mbed_official 76:aeb1df146756 1599 {
mbed_official 76:aeb1df146756 1600 /* Return the FLASH write protection Register value */
mbed_official 76:aeb1df146756 1601 return (uint32_t)(FLASH->WRPR1);
mbed_official 76:aeb1df146756 1602 }
mbed_official 76:aeb1df146756 1603
mbed_official 76:aeb1df146756 1604 /**
mbed_official 76:aeb1df146756 1605 * @brief Returns the FLASH Write Protection Option Bytes value.
mbed_official 80:66393a7b209d 1606 * @note This function can be used only for STM32L1XX_HD and STM32L1XX_XL devices.
mbed_official 76:aeb1df146756 1607 * @param None
mbed_official 76:aeb1df146756 1608 * @retval The FLASH Write Protection Option Bytes value.
mbed_official 76:aeb1df146756 1609 */
mbed_official 76:aeb1df146756 1610 uint32_t FLASH_OB_GetWRP2(void)
mbed_official 76:aeb1df146756 1611 {
mbed_official 76:aeb1df146756 1612 /* Return the FLASH write protection Register value */
mbed_official 76:aeb1df146756 1613 return (uint32_t)(FLASH->WRPR2);
mbed_official 76:aeb1df146756 1614 }
mbed_official 76:aeb1df146756 1615
mbed_official 76:aeb1df146756 1616 /**
mbed_official 76:aeb1df146756 1617 * @brief Checks whether the FLASH Read out Protection Status is set or not.
mbed_official 76:aeb1df146756 1618 * @param None
mbed_official 76:aeb1df146756 1619 * @retval FLASH ReadOut Protection Status(SET or RESET).
mbed_official 76:aeb1df146756 1620 */
mbed_official 76:aeb1df146756 1621 FlagStatus FLASH_OB_GetRDP(void)
mbed_official 76:aeb1df146756 1622 {
mbed_official 76:aeb1df146756 1623 FlagStatus readstatus = RESET;
mbed_official 76:aeb1df146756 1624
mbed_official 76:aeb1df146756 1625 if ((uint8_t)(FLASH->OBR) != (uint8_t)OB_RDP_Level_0)
mbed_official 76:aeb1df146756 1626 {
mbed_official 76:aeb1df146756 1627 readstatus = SET;
mbed_official 76:aeb1df146756 1628 }
mbed_official 76:aeb1df146756 1629 else
mbed_official 76:aeb1df146756 1630 {
mbed_official 76:aeb1df146756 1631 readstatus = RESET;
mbed_official 76:aeb1df146756 1632 }
mbed_official 76:aeb1df146756 1633 return readstatus;
mbed_official 76:aeb1df146756 1634 }
mbed_official 76:aeb1df146756 1635
mbed_official 76:aeb1df146756 1636 /**
mbed_official 76:aeb1df146756 1637 * @brief Returns the SPRMOD Status.
mbed_official 76:aeb1df146756 1638 * @note This function can be used only for STM32L1XX_MDP devices
mbed_official 76:aeb1df146756 1639 * @param None
mbed_official 76:aeb1df146756 1640 * @retval The SPRMOD Status.
mbed_official 76:aeb1df146756 1641 */
mbed_official 76:aeb1df146756 1642 FlagStatus FLASH_OB_GetSPRMOD(void)
mbed_official 76:aeb1df146756 1643 {
mbed_official 76:aeb1df146756 1644 FlagStatus readstatus = RESET;
mbed_official 76:aeb1df146756 1645 uint16_t tmp = 0;
mbed_official 76:aeb1df146756 1646
mbed_official 76:aeb1df146756 1647 /* Return the SPRMOD value */
mbed_official 76:aeb1df146756 1648 tmp = (uint16_t)(FLASH->OBR & (uint16_t)(0x0100));
mbed_official 76:aeb1df146756 1649
mbed_official 76:aeb1df146756 1650 if (tmp != (uint16_t)0x0000)
mbed_official 76:aeb1df146756 1651 {
mbed_official 76:aeb1df146756 1652 readstatus = SET;
mbed_official 76:aeb1df146756 1653 }
mbed_official 76:aeb1df146756 1654 else
mbed_official 76:aeb1df146756 1655 {
mbed_official 76:aeb1df146756 1656 readstatus = RESET;
mbed_official 76:aeb1df146756 1657 }
mbed_official 76:aeb1df146756 1658 return readstatus;
mbed_official 76:aeb1df146756 1659 }
mbed_official 76:aeb1df146756 1660
mbed_official 76:aeb1df146756 1661 /**
mbed_official 76:aeb1df146756 1662 * @brief Returns the FLASH BOR level.
mbed_official 76:aeb1df146756 1663 * @param None
mbed_official 76:aeb1df146756 1664 * @retval The FLASH User Option Bytes.
mbed_official 76:aeb1df146756 1665 */
mbed_official 76:aeb1df146756 1666 uint8_t FLASH_OB_GetBOR(void)
mbed_official 76:aeb1df146756 1667 {
mbed_official 76:aeb1df146756 1668 /* Return the BOR level */
mbed_official 76:aeb1df146756 1669 return (uint8_t)((FLASH->OBR & (uint32_t)0x000F0000) >> 16);
mbed_official 76:aeb1df146756 1670 }
mbed_official 76:aeb1df146756 1671
mbed_official 76:aeb1df146756 1672 /**
mbed_official 76:aeb1df146756 1673 * @}
mbed_official 76:aeb1df146756 1674 */
mbed_official 76:aeb1df146756 1675
mbed_official 76:aeb1df146756 1676 /** @defgroup FLASH_Group5 Interrupts and flags management functions
mbed_official 76:aeb1df146756 1677 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 1678 *
mbed_official 76:aeb1df146756 1679 @verbatim
mbed_official 76:aeb1df146756 1680 ==============================================================================
mbed_official 76:aeb1df146756 1681 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 1682 ==============================================================================
mbed_official 76:aeb1df146756 1683
mbed_official 76:aeb1df146756 1684 @endverbatim
mbed_official 76:aeb1df146756 1685 * @{
mbed_official 76:aeb1df146756 1686 */
mbed_official 76:aeb1df146756 1687
mbed_official 76:aeb1df146756 1688 /**
mbed_official 76:aeb1df146756 1689 * @brief Enables or disables the specified FLASH interrupts.
mbed_official 76:aeb1df146756 1690 * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or
mbed_official 76:aeb1df146756 1691 * disabled.
mbed_official 76:aeb1df146756 1692 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1693 * @arg FLASH_IT_EOP: FLASH end of programming Interrupt
mbed_official 76:aeb1df146756 1694 * @arg FLASH_IT_ERR: FLASH Error Interrupt
mbed_official 76:aeb1df146756 1695 * @retval None
mbed_official 76:aeb1df146756 1696 */
mbed_official 76:aeb1df146756 1697 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
mbed_official 76:aeb1df146756 1698 {
mbed_official 76:aeb1df146756 1699 /* Check the parameters */
mbed_official 76:aeb1df146756 1700 assert_param(IS_FLASH_IT(FLASH_IT));
mbed_official 76:aeb1df146756 1701 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1702
mbed_official 76:aeb1df146756 1703 if(NewState != DISABLE)
mbed_official 76:aeb1df146756 1704 {
mbed_official 76:aeb1df146756 1705 /* Enable the interrupt sources */
mbed_official 76:aeb1df146756 1706 FLASH->PECR |= FLASH_IT;
mbed_official 76:aeb1df146756 1707 }
mbed_official 76:aeb1df146756 1708 else
mbed_official 76:aeb1df146756 1709 {
mbed_official 76:aeb1df146756 1710 /* Disable the interrupt sources */
mbed_official 76:aeb1df146756 1711 FLASH->PECR &= ~(uint32_t)FLASH_IT;
mbed_official 76:aeb1df146756 1712 }
mbed_official 76:aeb1df146756 1713 }
mbed_official 76:aeb1df146756 1714
mbed_official 76:aeb1df146756 1715 /**
mbed_official 76:aeb1df146756 1716 * @brief Checks whether the specified FLASH flag is set or not.
mbed_official 76:aeb1df146756 1717 * @param FLASH_FLAG: specifies the FLASH flag to check.
mbed_official 76:aeb1df146756 1718 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1719 * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag
mbed_official 76:aeb1df146756 1720 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
mbed_official 76:aeb1df146756 1721 * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode
mbed_official 76:aeb1df146756 1722 * @arg FLASH_FLAG_ENDHV: FLASH End of high voltage flag
mbed_official 76:aeb1df146756 1723 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
mbed_official 76:aeb1df146756 1724 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
mbed_official 76:aeb1df146756 1725 * @arg FLASH_FLAG_SIZERR: FLASH size error flag
mbed_official 76:aeb1df146756 1726 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
mbed_official 76:aeb1df146756 1727 * @arg FLASH_FLAG_OPTVERRUSR: FLASH Option User validity error flag
mbed_official 76:aeb1df146756 1728 * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag (available only in STM32L1XX_MDP devices)
mbed_official 76:aeb1df146756 1729 * @retval The new state of FLASH_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 1730 */
mbed_official 76:aeb1df146756 1731 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
mbed_official 76:aeb1df146756 1732 {
mbed_official 76:aeb1df146756 1733 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1734
mbed_official 76:aeb1df146756 1735 /* Check the parameters */
mbed_official 76:aeb1df146756 1736 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));
mbed_official 76:aeb1df146756 1737
mbed_official 76:aeb1df146756 1738 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 1739 {
mbed_official 76:aeb1df146756 1740 bitstatus = SET;
mbed_official 76:aeb1df146756 1741 }
mbed_official 76:aeb1df146756 1742 else
mbed_official 76:aeb1df146756 1743 {
mbed_official 76:aeb1df146756 1744 bitstatus = RESET;
mbed_official 76:aeb1df146756 1745 }
mbed_official 76:aeb1df146756 1746 /* Return the new state of FLASH_FLAG (SET or RESET) */
mbed_official 76:aeb1df146756 1747 return bitstatus;
mbed_official 76:aeb1df146756 1748 }
mbed_official 76:aeb1df146756 1749
mbed_official 76:aeb1df146756 1750 /**
mbed_official 76:aeb1df146756 1751 * @brief Clears the FLASH's pending flags.
mbed_official 76:aeb1df146756 1752 * @param FLASH_FLAG: specifies the FLASH flags to clear.
mbed_official 76:aeb1df146756 1753 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1754 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
mbed_official 76:aeb1df146756 1755 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
mbed_official 76:aeb1df146756 1756 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
mbed_official 76:aeb1df146756 1757 * @arg FLASH_FLAG_SIZERR: FLASH size error flag
mbed_official 76:aeb1df146756 1758 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
mbed_official 76:aeb1df146756 1759 * @arg FLASH_FLAG_OPTVERRUSR: FLASH Option User validity error flag
mbed_official 76:aeb1df146756 1760 * @arg FLASH_FLAG_RDERR: FLASH Read protected error flag (available only in STM32L1XX_MDP devices)
mbed_official 76:aeb1df146756 1761 * @retval None
mbed_official 76:aeb1df146756 1762 */
mbed_official 76:aeb1df146756 1763 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
mbed_official 76:aeb1df146756 1764 {
mbed_official 76:aeb1df146756 1765 /* Check the parameters */
mbed_official 76:aeb1df146756 1766 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));
mbed_official 76:aeb1df146756 1767
mbed_official 76:aeb1df146756 1768 /* Clear the flags */
mbed_official 76:aeb1df146756 1769 FLASH->SR = FLASH_FLAG;
mbed_official 76:aeb1df146756 1770 }
mbed_official 76:aeb1df146756 1771
mbed_official 76:aeb1df146756 1772 /**
mbed_official 76:aeb1df146756 1773 * @brief Returns the FLASH Status.
mbed_official 76:aeb1df146756 1774 * @param None
mbed_official 76:aeb1df146756 1775 * @retval FLASH Status: The returned value can be:
mbed_official 76:aeb1df146756 1776 * FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE.
mbed_official 76:aeb1df146756 1777 */
mbed_official 76:aeb1df146756 1778 FLASH_Status FLASH_GetStatus(void)
mbed_official 76:aeb1df146756 1779 {
mbed_official 76:aeb1df146756 1780 FLASH_Status FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1781
mbed_official 76:aeb1df146756 1782 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
mbed_official 76:aeb1df146756 1783 {
mbed_official 76:aeb1df146756 1784 FLASHstatus = FLASH_BUSY;
mbed_official 76:aeb1df146756 1785 }
mbed_official 76:aeb1df146756 1786 else
mbed_official 76:aeb1df146756 1787 {
mbed_official 76:aeb1df146756 1788 if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)
mbed_official 76:aeb1df146756 1789 {
mbed_official 76:aeb1df146756 1790 FLASHstatus = FLASH_ERROR_WRP;
mbed_official 76:aeb1df146756 1791 }
mbed_official 76:aeb1df146756 1792 else
mbed_official 76:aeb1df146756 1793 {
mbed_official 76:aeb1df146756 1794 if((FLASH->SR & (uint32_t)0x1E00) != (uint32_t)0x00)
mbed_official 76:aeb1df146756 1795 {
mbed_official 76:aeb1df146756 1796 FLASHstatus = FLASH_ERROR_PROGRAM;
mbed_official 76:aeb1df146756 1797 }
mbed_official 76:aeb1df146756 1798 else
mbed_official 76:aeb1df146756 1799 {
mbed_official 76:aeb1df146756 1800 FLASHstatus = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1801 }
mbed_official 76:aeb1df146756 1802 }
mbed_official 76:aeb1df146756 1803 }
mbed_official 76:aeb1df146756 1804 /* Return the FLASH Status */
mbed_official 76:aeb1df146756 1805 return FLASHstatus;
mbed_official 76:aeb1df146756 1806 }
mbed_official 76:aeb1df146756 1807
mbed_official 76:aeb1df146756 1808
mbed_official 76:aeb1df146756 1809 /**
mbed_official 76:aeb1df146756 1810 * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur.
mbed_official 76:aeb1df146756 1811 * @param Timeout: FLASH programming Timeout.
mbed_official 76:aeb1df146756 1812 * @retval FLASH Status: The returned value can be: FLASH_BUSY,
mbed_official 76:aeb1df146756 1813 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 76:aeb1df146756 1814 */
mbed_official 76:aeb1df146756 1815 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
mbed_official 76:aeb1df146756 1816 {
mbed_official 76:aeb1df146756 1817 __IO FLASH_Status status = FLASH_COMPLETE;
mbed_official 76:aeb1df146756 1818
mbed_official 76:aeb1df146756 1819 /* Check for the FLASH Status */
mbed_official 76:aeb1df146756 1820 status = FLASH_GetStatus();
mbed_official 76:aeb1df146756 1821
mbed_official 76:aeb1df146756 1822 /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
mbed_official 76:aeb1df146756 1823 while((status == FLASH_BUSY) && (Timeout != 0x00))
mbed_official 76:aeb1df146756 1824 {
mbed_official 76:aeb1df146756 1825 status = FLASH_GetStatus();
mbed_official 76:aeb1df146756 1826 Timeout--;
mbed_official 76:aeb1df146756 1827 }
mbed_official 76:aeb1df146756 1828
mbed_official 76:aeb1df146756 1829 if(Timeout == 0x00 )
mbed_official 76:aeb1df146756 1830 {
mbed_official 76:aeb1df146756 1831 status = FLASH_TIMEOUT;
mbed_official 76:aeb1df146756 1832 }
mbed_official 76:aeb1df146756 1833 /* Return the operation status */
mbed_official 76:aeb1df146756 1834 return status;
mbed_official 76:aeb1df146756 1835 }
mbed_official 76:aeb1df146756 1836
mbed_official 76:aeb1df146756 1837 /**
mbed_official 76:aeb1df146756 1838 * @}
mbed_official 76:aeb1df146756 1839 */
mbed_official 76:aeb1df146756 1840
mbed_official 76:aeb1df146756 1841 /**
mbed_official 76:aeb1df146756 1842 * @}
mbed_official 76:aeb1df146756 1843 */
mbed_official 76:aeb1df146756 1844
mbed_official 76:aeb1df146756 1845 /**
mbed_official 76:aeb1df146756 1846 * @}
mbed_official 76:aeb1df146756 1847 */
mbed_official 76:aeb1df146756 1848
mbed_official 76:aeb1df146756 1849 /**
mbed_official 76:aeb1df146756 1850 * @}
mbed_official 76:aeb1df146756 1851 */
mbed_official 76:aeb1df146756 1852
mbed_official 76:aeb1df146756 1853 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/