mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Tue Jan 07 11:00:05 2014 +0000
Revision:
70:c1fbde68b492
Parent:
52:a51c77007319
Child:
84:f54042cbc282
Synchronized with git revision 3f438a307904431f2782db3c8fa49946b9fc1d85

Full URL: https://github.com/mbedmicro/mbed/commit/3f438a307904431f2782db3c8fa49946b9fc1d85/

[NUCLEO_F103RB] license text changed + sleep hal updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /**
mbed_official 52:a51c77007319 2 ******************************************************************************
mbed_official 52:a51c77007319 3 * @file stm32f10x_flash.c
mbed_official 52:a51c77007319 4 * @author MCD Application Team
mbed_official 52:a51c77007319 5 * @version V3.5.0
mbed_official 52:a51c77007319 6 * @date 11-March-2011
mbed_official 52:a51c77007319 7 * @brief This file provides all the FLASH firmware functions.
mbed_official 70:c1fbde68b492 8 *******************************************************************************
mbed_official 70:c1fbde68b492 9 * Copyright (c) 2014, STMicroelectronics
mbed_official 70:c1fbde68b492 10 * All rights reserved.
mbed_official 70:c1fbde68b492 11 *
mbed_official 70:c1fbde68b492 12 * Redistribution and use in source and binary forms, with or without
mbed_official 70:c1fbde68b492 13 * modification, are permitted provided that the following conditions are met:
mbed_official 70:c1fbde68b492 14 *
mbed_official 70:c1fbde68b492 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 70:c1fbde68b492 16 * this list of conditions and the following disclaimer.
mbed_official 70:c1fbde68b492 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 70:c1fbde68b492 18 * this list of conditions and the following disclaimer in the documentation
mbed_official 70:c1fbde68b492 19 * and/or other materials provided with the distribution.
mbed_official 70:c1fbde68b492 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 70:c1fbde68b492 21 * may be used to endorse or promote products derived from this software
mbed_official 70:c1fbde68b492 22 * without specific prior written permission.
mbed_official 70:c1fbde68b492 23 *
mbed_official 70:c1fbde68b492 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 70:c1fbde68b492 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 70:c1fbde68b492 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 70:c1fbde68b492 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 70:c1fbde68b492 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 70:c1fbde68b492 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 70:c1fbde68b492 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 70:c1fbde68b492 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 70:c1fbde68b492 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 70:c1fbde68b492 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 70:c1fbde68b492 34 *******************************************************************************
mbed_official 70:c1fbde68b492 35 */
mbed_official 52:a51c77007319 36
mbed_official 52:a51c77007319 37 /* Includes ------------------------------------------------------------------*/
mbed_official 52:a51c77007319 38 #include "stm32f10x_flash.h"
mbed_official 52:a51c77007319 39
mbed_official 52:a51c77007319 40 /** @addtogroup STM32F10x_StdPeriph_Driver
mbed_official 52:a51c77007319 41 * @{
mbed_official 52:a51c77007319 42 */
mbed_official 52:a51c77007319 43
mbed_official 52:a51c77007319 44 /** @defgroup FLASH
mbed_official 52:a51c77007319 45 * @brief FLASH driver modules
mbed_official 52:a51c77007319 46 * @{
mbed_official 52:a51c77007319 47 */
mbed_official 52:a51c77007319 48
mbed_official 52:a51c77007319 49 /** @defgroup FLASH_Private_TypesDefinitions
mbed_official 52:a51c77007319 50 * @{
mbed_official 52:a51c77007319 51 */
mbed_official 52:a51c77007319 52
mbed_official 52:a51c77007319 53 /**
mbed_official 52:a51c77007319 54 * @}
mbed_official 52:a51c77007319 55 */
mbed_official 52:a51c77007319 56
mbed_official 52:a51c77007319 57 /** @defgroup FLASH_Private_Defines
mbed_official 52:a51c77007319 58 * @{
mbed_official 52:a51c77007319 59 */
mbed_official 52:a51c77007319 60
mbed_official 52:a51c77007319 61 /* Flash Access Control Register bits */
mbed_official 52:a51c77007319 62 #define ACR_LATENCY_Mask ((uint32_t)0x00000038)
mbed_official 52:a51c77007319 63 #define ACR_HLFCYA_Mask ((uint32_t)0xFFFFFFF7)
mbed_official 52:a51c77007319 64 #define ACR_PRFTBE_Mask ((uint32_t)0xFFFFFFEF)
mbed_official 52:a51c77007319 65
mbed_official 52:a51c77007319 66 /* Flash Access Control Register bits */
mbed_official 52:a51c77007319 67 #define ACR_PRFTBS_Mask ((uint32_t)0x00000020)
mbed_official 52:a51c77007319 68
mbed_official 52:a51c77007319 69 /* Flash Control Register bits */
mbed_official 52:a51c77007319 70 #define CR_PG_Set ((uint32_t)0x00000001)
mbed_official 52:a51c77007319 71 #define CR_PG_Reset ((uint32_t)0x00001FFE)
mbed_official 52:a51c77007319 72 #define CR_PER_Set ((uint32_t)0x00000002)
mbed_official 52:a51c77007319 73 #define CR_PER_Reset ((uint32_t)0x00001FFD)
mbed_official 52:a51c77007319 74 #define CR_MER_Set ((uint32_t)0x00000004)
mbed_official 52:a51c77007319 75 #define CR_MER_Reset ((uint32_t)0x00001FFB)
mbed_official 52:a51c77007319 76 #define CR_OPTPG_Set ((uint32_t)0x00000010)
mbed_official 52:a51c77007319 77 #define CR_OPTPG_Reset ((uint32_t)0x00001FEF)
mbed_official 52:a51c77007319 78 #define CR_OPTER_Set ((uint32_t)0x00000020)
mbed_official 52:a51c77007319 79 #define CR_OPTER_Reset ((uint32_t)0x00001FDF)
mbed_official 52:a51c77007319 80 #define CR_STRT_Set ((uint32_t)0x00000040)
mbed_official 52:a51c77007319 81 #define CR_LOCK_Set ((uint32_t)0x00000080)
mbed_official 52:a51c77007319 82
mbed_official 52:a51c77007319 83 /* FLASH Mask */
mbed_official 52:a51c77007319 84 #define RDPRT_Mask ((uint32_t)0x00000002)
mbed_official 52:a51c77007319 85 #define WRP0_Mask ((uint32_t)0x000000FF)
mbed_official 52:a51c77007319 86 #define WRP1_Mask ((uint32_t)0x0000FF00)
mbed_official 52:a51c77007319 87 #define WRP2_Mask ((uint32_t)0x00FF0000)
mbed_official 52:a51c77007319 88 #define WRP3_Mask ((uint32_t)0xFF000000)
mbed_official 52:a51c77007319 89 #define OB_USER_BFB2 ((uint16_t)0x0008)
mbed_official 52:a51c77007319 90
mbed_official 52:a51c77007319 91 /* FLASH Keys */
mbed_official 52:a51c77007319 92 #define RDP_Key ((uint16_t)0x00A5)
mbed_official 52:a51c77007319 93 #define FLASH_KEY1 ((uint32_t)0x45670123)
mbed_official 52:a51c77007319 94 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
mbed_official 52:a51c77007319 95
mbed_official 52:a51c77007319 96 /* FLASH BANK address */
mbed_official 52:a51c77007319 97 #define FLASH_BANK1_END_ADDRESS ((uint32_t)0x807FFFF)
mbed_official 52:a51c77007319 98
mbed_official 52:a51c77007319 99 /* Delay definition */
mbed_official 52:a51c77007319 100 #define EraseTimeout ((uint32_t)0x000B0000)
mbed_official 52:a51c77007319 101 #define ProgramTimeout ((uint32_t)0x00002000)
mbed_official 52:a51c77007319 102 /**
mbed_official 52:a51c77007319 103 * @}
mbed_official 52:a51c77007319 104 */
mbed_official 52:a51c77007319 105
mbed_official 52:a51c77007319 106 /** @defgroup FLASH_Private_Macros
mbed_official 52:a51c77007319 107 * @{
mbed_official 52:a51c77007319 108 */
mbed_official 52:a51c77007319 109
mbed_official 52:a51c77007319 110 /**
mbed_official 52:a51c77007319 111 * @}
mbed_official 52:a51c77007319 112 */
mbed_official 52:a51c77007319 113
mbed_official 52:a51c77007319 114 /** @defgroup FLASH_Private_Variables
mbed_official 52:a51c77007319 115 * @{
mbed_official 52:a51c77007319 116 */
mbed_official 52:a51c77007319 117
mbed_official 52:a51c77007319 118 /**
mbed_official 52:a51c77007319 119 * @}
mbed_official 52:a51c77007319 120 */
mbed_official 52:a51c77007319 121
mbed_official 52:a51c77007319 122 /** @defgroup FLASH_Private_FunctionPrototypes
mbed_official 52:a51c77007319 123 * @{
mbed_official 52:a51c77007319 124 */
mbed_official 52:a51c77007319 125
mbed_official 52:a51c77007319 126 /**
mbed_official 52:a51c77007319 127 * @}
mbed_official 52:a51c77007319 128 */
mbed_official 52:a51c77007319 129
mbed_official 52:a51c77007319 130 /** @defgroup FLASH_Private_Functions
mbed_official 52:a51c77007319 131 * @{
mbed_official 52:a51c77007319 132 */
mbed_official 52:a51c77007319 133
mbed_official 52:a51c77007319 134 /**
mbed_official 52:a51c77007319 135 @code
mbed_official 52:a51c77007319 136
mbed_official 52:a51c77007319 137 This driver provides functions to configure and program the Flash memory of all STM32F10x devices,
mbed_official 52:a51c77007319 138 including the latest STM32F10x_XL density devices.
mbed_official 52:a51c77007319 139
mbed_official 52:a51c77007319 140 STM32F10x_XL devices feature up to 1 Mbyte with dual bank architecture for read-while-write (RWW) capability:
mbed_official 52:a51c77007319 141 - bank1: fixed size of 512 Kbytes (256 pages of 2Kbytes each)
mbed_official 52:a51c77007319 142 - bank2: up to 512 Kbytes (up to 256 pages of 2Kbytes each)
mbed_official 52:a51c77007319 143 While other STM32F10x devices features only one bank with memory up to 512 Kbytes.
mbed_official 52:a51c77007319 144
mbed_official 52:a51c77007319 145 In version V3.3.0, some functions were updated and new ones were added to support
mbed_official 52:a51c77007319 146 STM32F10x_XL devices. Thus some functions manages all devices, while other are
mbed_official 52:a51c77007319 147 dedicated for XL devices only.
mbed_official 52:a51c77007319 148
mbed_official 52:a51c77007319 149 The table below presents the list of available functions depending on the used STM32F10x devices.
mbed_official 52:a51c77007319 150
mbed_official 52:a51c77007319 151 ***************************************************
mbed_official 52:a51c77007319 152 * Legacy functions used for all STM32F10x devices *
mbed_official 52:a51c77007319 153 ***************************************************
mbed_official 52:a51c77007319 154 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 155 | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
mbed_official 52:a51c77007319 156 | | devices | devices | |
mbed_official 52:a51c77007319 157 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 158 |FLASH_SetLatency | Yes | Yes | No change |
mbed_official 52:a51c77007319 159 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 160 |FLASH_HalfCycleAccessCmd | Yes | Yes | No change |
mbed_official 52:a51c77007319 161 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 162 |FLASH_PrefetchBufferCmd | Yes | Yes | No change |
mbed_official 52:a51c77007319 163 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 164 |FLASH_Unlock | Yes | Yes | - For STM32F10X_XL devices: unlock Bank1 and Bank2. |
mbed_official 52:a51c77007319 165 | | | | - For other devices: unlock Bank1 and it is equivalent |
mbed_official 52:a51c77007319 166 | | | | to FLASH_UnlockBank1 function. |
mbed_official 52:a51c77007319 167 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 168 |FLASH_Lock | Yes | Yes | - For STM32F10X_XL devices: lock Bank1 and Bank2. |
mbed_official 52:a51c77007319 169 | | | | - For other devices: lock Bank1 and it is equivalent |
mbed_official 52:a51c77007319 170 | | | | to FLASH_LockBank1 function. |
mbed_official 52:a51c77007319 171 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 172 |FLASH_ErasePage | Yes | Yes | - For STM32F10x_XL devices: erase a page in Bank1 and Bank2 |
mbed_official 52:a51c77007319 173 | | | | - For other devices: erase a page in Bank1 |
mbed_official 52:a51c77007319 174 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 175 |FLASH_EraseAllPages | Yes | Yes | - For STM32F10x_XL devices: erase all pages in Bank1 and Bank2 |
mbed_official 52:a51c77007319 176 | | | | - For other devices: erase all pages in Bank1 |
mbed_official 52:a51c77007319 177 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 178 |FLASH_EraseOptionBytes | Yes | Yes | No change |
mbed_official 52:a51c77007319 179 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 180 |FLASH_ProgramWord | Yes | Yes | Updated to program up to 1MByte (depending on the used device) |
mbed_official 52:a51c77007319 181 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 182 |FLASH_ProgramHalfWord | Yes | Yes | Updated to program up to 1MByte (depending on the used device) |
mbed_official 52:a51c77007319 183 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 184 |FLASH_ProgramOptionByteData | Yes | Yes | No change |
mbed_official 52:a51c77007319 185 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 186 |FLASH_EnableWriteProtection | Yes | Yes | No change |
mbed_official 52:a51c77007319 187 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 188 |FLASH_ReadOutProtection | Yes | Yes | No change |
mbed_official 52:a51c77007319 189 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 190 |FLASH_UserOptionByteConfig | Yes | Yes | No change |
mbed_official 52:a51c77007319 191 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 192 |FLASH_GetUserOptionByte | Yes | Yes | No change |
mbed_official 52:a51c77007319 193 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 194 |FLASH_GetWriteProtectionOptionByte | Yes | Yes | No change |
mbed_official 52:a51c77007319 195 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 196 |FLASH_GetReadOutProtectionStatus | Yes | Yes | No change |
mbed_official 52:a51c77007319 197 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 198 |FLASH_GetPrefetchBufferStatus | Yes | Yes | No change |
mbed_official 52:a51c77007319 199 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 200 |FLASH_ITConfig | Yes | Yes | - For STM32F10x_XL devices: enable Bank1 and Bank2's interrupts|
mbed_official 52:a51c77007319 201 | | | | - For other devices: enable Bank1's interrupts |
mbed_official 52:a51c77007319 202 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 203 |FLASH_GetFlagStatus | Yes | Yes | - For STM32F10x_XL devices: return Bank1 and Bank2's flag status|
mbed_official 52:a51c77007319 204 | | | | - For other devices: return Bank1's flag status |
mbed_official 52:a51c77007319 205 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 206 |FLASH_ClearFlag | Yes | Yes | - For STM32F10x_XL devices: clear Bank1 and Bank2's flag |
mbed_official 52:a51c77007319 207 | | | | - For other devices: clear Bank1's flag |
mbed_official 52:a51c77007319 208 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 209 |FLASH_GetStatus | Yes | Yes | - Return the status of Bank1 (for all devices) |
mbed_official 52:a51c77007319 210 | | | | equivalent to FLASH_GetBank1Status function |
mbed_official 52:a51c77007319 211 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 212 |FLASH_WaitForLastOperation | Yes | Yes | - Wait for Bank1 last operation (for all devices) |
mbed_official 52:a51c77007319 213 | | | | equivalent to: FLASH_WaitForLastBank1Operation function |
mbed_official 52:a51c77007319 214 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 215
mbed_official 52:a51c77007319 216 ************************************************************************************************************************
mbed_official 52:a51c77007319 217 * New functions used for all STM32F10x devices to manage Bank1: *
mbed_official 52:a51c77007319 218 * - These functions are mainly useful for STM32F10x_XL density devices, to have separate control for Bank1 and bank2 *
mbed_official 52:a51c77007319 219 * - For other devices, these functions are optional (covered by functions listed above) *
mbed_official 52:a51c77007319 220 ************************************************************************************************************************
mbed_official 52:a51c77007319 221 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 222 | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
mbed_official 52:a51c77007319 223 | | devices | devices | |
mbed_official 52:a51c77007319 224 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 225 | FLASH_UnlockBank1 | Yes | Yes | - Unlock Bank1 |
mbed_official 52:a51c77007319 226 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 227 |FLASH_LockBank1 | Yes | Yes | - Lock Bank1 |
mbed_official 52:a51c77007319 228 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 229 | FLASH_EraseAllBank1Pages | Yes | Yes | - Erase all pages in Bank1 |
mbed_official 52:a51c77007319 230 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 231 | FLASH_GetBank1Status | Yes | Yes | - Return the status of Bank1 |
mbed_official 52:a51c77007319 232 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 233 | FLASH_WaitForLastBank1Operation | Yes | Yes | - Wait for Bank1 last operation |
mbed_official 52:a51c77007319 234 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 235
mbed_official 52:a51c77007319 236 *****************************************************************************
mbed_official 52:a51c77007319 237 * New Functions used only with STM32F10x_XL density devices to manage Bank2 *
mbed_official 52:a51c77007319 238 *****************************************************************************
mbed_official 52:a51c77007319 239 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 240 | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
mbed_official 52:a51c77007319 241 | | devices | devices | |
mbed_official 52:a51c77007319 242 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 243 | FLASH_UnlockBank2 | Yes | No | - Unlock Bank2 |
mbed_official 52:a51c77007319 244 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 245 |FLASH_LockBank2 | Yes | No | - Lock Bank2 |
mbed_official 52:a51c77007319 246 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 247 | FLASH_EraseAllBank2Pages | Yes | No | - Erase all pages in Bank2 |
mbed_official 52:a51c77007319 248 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 249 | FLASH_GetBank2Status | Yes | No | - Return the status of Bank2 |
mbed_official 52:a51c77007319 250 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 251 | FLASH_WaitForLastBank2Operation | Yes | No | - Wait for Bank2 last operation |
mbed_official 52:a51c77007319 252 |----------------------------------------------------------------------------------------------------------------------------------|
mbed_official 52:a51c77007319 253 | FLASH_BootConfig | Yes | No | - Configure to boot from Bank1 or Bank2 |
mbed_official 52:a51c77007319 254 +----------------------------------------------------------------------------------------------------------------------------------+
mbed_official 52:a51c77007319 255 @endcode
mbed_official 52:a51c77007319 256 */
mbed_official 52:a51c77007319 257
mbed_official 52:a51c77007319 258
mbed_official 52:a51c77007319 259 /**
mbed_official 52:a51c77007319 260 * @brief Sets the code latency value.
mbed_official 52:a51c77007319 261 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 262 * @param FLASH_Latency: specifies the FLASH Latency value.
mbed_official 52:a51c77007319 263 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 264 * @arg FLASH_Latency_0: FLASH Zero Latency cycle
mbed_official 52:a51c77007319 265 * @arg FLASH_Latency_1: FLASH One Latency cycle
mbed_official 52:a51c77007319 266 * @arg FLASH_Latency_2: FLASH Two Latency cycles
mbed_official 52:a51c77007319 267 * @retval None
mbed_official 52:a51c77007319 268 */
mbed_official 52:a51c77007319 269 void FLASH_SetLatency(uint32_t FLASH_Latency)
mbed_official 52:a51c77007319 270 {
mbed_official 52:a51c77007319 271 uint32_t tmpreg = 0;
mbed_official 52:a51c77007319 272
mbed_official 52:a51c77007319 273 /* Check the parameters */
mbed_official 52:a51c77007319 274 assert_param(IS_FLASH_LATENCY(FLASH_Latency));
mbed_official 52:a51c77007319 275
mbed_official 52:a51c77007319 276 /* Read the ACR register */
mbed_official 52:a51c77007319 277 tmpreg = FLASH->ACR;
mbed_official 52:a51c77007319 278
mbed_official 52:a51c77007319 279 /* Sets the Latency value */
mbed_official 52:a51c77007319 280 tmpreg &= ACR_LATENCY_Mask;
mbed_official 52:a51c77007319 281 tmpreg |= FLASH_Latency;
mbed_official 52:a51c77007319 282
mbed_official 52:a51c77007319 283 /* Write the ACR register */
mbed_official 52:a51c77007319 284 FLASH->ACR = tmpreg;
mbed_official 52:a51c77007319 285 }
mbed_official 52:a51c77007319 286
mbed_official 52:a51c77007319 287 /**
mbed_official 52:a51c77007319 288 * @brief Enables or disables the Half cycle flash access.
mbed_official 52:a51c77007319 289 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 290 * @param FLASH_HalfCycleAccess: specifies the FLASH Half cycle Access mode.
mbed_official 52:a51c77007319 291 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 292 * @arg FLASH_HalfCycleAccess_Enable: FLASH Half Cycle Enable
mbed_official 52:a51c77007319 293 * @arg FLASH_HalfCycleAccess_Disable: FLASH Half Cycle Disable
mbed_official 52:a51c77007319 294 * @retval None
mbed_official 52:a51c77007319 295 */
mbed_official 52:a51c77007319 296 void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess)
mbed_official 52:a51c77007319 297 {
mbed_official 52:a51c77007319 298 /* Check the parameters */
mbed_official 52:a51c77007319 299 assert_param(IS_FLASH_HALFCYCLEACCESS_STATE(FLASH_HalfCycleAccess));
mbed_official 52:a51c77007319 300
mbed_official 52:a51c77007319 301 /* Enable or disable the Half cycle access */
mbed_official 52:a51c77007319 302 FLASH->ACR &= ACR_HLFCYA_Mask;
mbed_official 52:a51c77007319 303 FLASH->ACR |= FLASH_HalfCycleAccess;
mbed_official 52:a51c77007319 304 }
mbed_official 52:a51c77007319 305
mbed_official 52:a51c77007319 306 /**
mbed_official 52:a51c77007319 307 * @brief Enables or disables the Prefetch Buffer.
mbed_official 52:a51c77007319 308 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 309 * @param FLASH_PrefetchBuffer: specifies the Prefetch buffer status.
mbed_official 52:a51c77007319 310 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 311 * @arg FLASH_PrefetchBuffer_Enable: FLASH Prefetch Buffer Enable
mbed_official 52:a51c77007319 312 * @arg FLASH_PrefetchBuffer_Disable: FLASH Prefetch Buffer Disable
mbed_official 52:a51c77007319 313 * @retval None
mbed_official 52:a51c77007319 314 */
mbed_official 52:a51c77007319 315 void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer)
mbed_official 52:a51c77007319 316 {
mbed_official 52:a51c77007319 317 /* Check the parameters */
mbed_official 52:a51c77007319 318 assert_param(IS_FLASH_PREFETCHBUFFER_STATE(FLASH_PrefetchBuffer));
mbed_official 52:a51c77007319 319
mbed_official 52:a51c77007319 320 /* Enable or disable the Prefetch Buffer */
mbed_official 52:a51c77007319 321 FLASH->ACR &= ACR_PRFTBE_Mask;
mbed_official 52:a51c77007319 322 FLASH->ACR |= FLASH_PrefetchBuffer;
mbed_official 52:a51c77007319 323 }
mbed_official 52:a51c77007319 324
mbed_official 52:a51c77007319 325 /**
mbed_official 52:a51c77007319 326 * @brief Unlocks the FLASH Program Erase Controller.
mbed_official 52:a51c77007319 327 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 328 * - For STM32F10X_XL devices this function unlocks Bank1 and Bank2.
mbed_official 52:a51c77007319 329 * - For all other devices it unlocks Bank1 and it is equivalent
mbed_official 52:a51c77007319 330 * to FLASH_UnlockBank1 function..
mbed_official 52:a51c77007319 331 * @param None
mbed_official 52:a51c77007319 332 * @retval None
mbed_official 52:a51c77007319 333 */
mbed_official 52:a51c77007319 334 void FLASH_Unlock(void)
mbed_official 52:a51c77007319 335 {
mbed_official 52:a51c77007319 336 /* Authorize the FPEC of Bank1 Access */
mbed_official 52:a51c77007319 337 FLASH->KEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 338 FLASH->KEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 339
mbed_official 52:a51c77007319 340 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 341 /* Authorize the FPEC of Bank2 Access */
mbed_official 52:a51c77007319 342 FLASH->KEYR2 = FLASH_KEY1;
mbed_official 52:a51c77007319 343 FLASH->KEYR2 = FLASH_KEY2;
mbed_official 52:a51c77007319 344 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 345 }
mbed_official 52:a51c77007319 346 /**
mbed_official 52:a51c77007319 347 * @brief Unlocks the FLASH Bank1 Program Erase Controller.
mbed_official 52:a51c77007319 348 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 349 * - For STM32F10X_XL devices this function unlocks Bank1.
mbed_official 52:a51c77007319 350 * - For all other devices it unlocks Bank1 and it is
mbed_official 52:a51c77007319 351 * equivalent to FLASH_Unlock function.
mbed_official 52:a51c77007319 352 * @param None
mbed_official 52:a51c77007319 353 * @retval None
mbed_official 52:a51c77007319 354 */
mbed_official 52:a51c77007319 355 void FLASH_UnlockBank1(void)
mbed_official 52:a51c77007319 356 {
mbed_official 52:a51c77007319 357 /* Authorize the FPEC of Bank1 Access */
mbed_official 52:a51c77007319 358 FLASH->KEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 359 FLASH->KEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 360 }
mbed_official 52:a51c77007319 361
mbed_official 52:a51c77007319 362 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 363 /**
mbed_official 52:a51c77007319 364 * @brief Unlocks the FLASH Bank2 Program Erase Controller.
mbed_official 52:a51c77007319 365 * @note This function can be used only for STM32F10X_XL density devices.
mbed_official 52:a51c77007319 366 * @param None
mbed_official 52:a51c77007319 367 * @retval None
mbed_official 52:a51c77007319 368 */
mbed_official 52:a51c77007319 369 void FLASH_UnlockBank2(void)
mbed_official 52:a51c77007319 370 {
mbed_official 52:a51c77007319 371 /* Authorize the FPEC of Bank2 Access */
mbed_official 52:a51c77007319 372 FLASH->KEYR2 = FLASH_KEY1;
mbed_official 52:a51c77007319 373 FLASH->KEYR2 = FLASH_KEY2;
mbed_official 52:a51c77007319 374
mbed_official 52:a51c77007319 375 }
mbed_official 52:a51c77007319 376 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 377
mbed_official 52:a51c77007319 378 /**
mbed_official 52:a51c77007319 379 * @brief Locks the FLASH Program Erase Controller.
mbed_official 52:a51c77007319 380 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 381 * - For STM32F10X_XL devices this function Locks Bank1 and Bank2.
mbed_official 52:a51c77007319 382 * - For all other devices it Locks Bank1 and it is equivalent
mbed_official 52:a51c77007319 383 * to FLASH_LockBank1 function.
mbed_official 52:a51c77007319 384 * @param None
mbed_official 52:a51c77007319 385 * @retval None
mbed_official 52:a51c77007319 386 */
mbed_official 52:a51c77007319 387 void FLASH_Lock(void)
mbed_official 52:a51c77007319 388 {
mbed_official 52:a51c77007319 389 /* Set the Lock Bit to lock the FPEC and the CR of Bank1 */
mbed_official 52:a51c77007319 390 FLASH->CR |= CR_LOCK_Set;
mbed_official 52:a51c77007319 391
mbed_official 52:a51c77007319 392 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 393 /* Set the Lock Bit to lock the FPEC and the CR of Bank2 */
mbed_official 52:a51c77007319 394 FLASH->CR2 |= CR_LOCK_Set;
mbed_official 52:a51c77007319 395 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 396 }
mbed_official 52:a51c77007319 397
mbed_official 52:a51c77007319 398 /**
mbed_official 52:a51c77007319 399 * @brief Locks the FLASH Bank1 Program Erase Controller.
mbed_official 52:a51c77007319 400 * @note this function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 401 * - For STM32F10X_XL devices this function Locks Bank1.
mbed_official 52:a51c77007319 402 * - For all other devices it Locks Bank1 and it is equivalent
mbed_official 52:a51c77007319 403 * to FLASH_Lock function.
mbed_official 52:a51c77007319 404 * @param None
mbed_official 52:a51c77007319 405 * @retval None
mbed_official 52:a51c77007319 406 */
mbed_official 52:a51c77007319 407 void FLASH_LockBank1(void)
mbed_official 52:a51c77007319 408 {
mbed_official 52:a51c77007319 409 /* Set the Lock Bit to lock the FPEC and the CR of Bank1 */
mbed_official 52:a51c77007319 410 FLASH->CR |= CR_LOCK_Set;
mbed_official 52:a51c77007319 411 }
mbed_official 52:a51c77007319 412
mbed_official 52:a51c77007319 413 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 414 /**
mbed_official 52:a51c77007319 415 * @brief Locks the FLASH Bank2 Program Erase Controller.
mbed_official 52:a51c77007319 416 * @note This function can be used only for STM32F10X_XL density devices.
mbed_official 52:a51c77007319 417 * @param None
mbed_official 52:a51c77007319 418 * @retval None
mbed_official 52:a51c77007319 419 */
mbed_official 52:a51c77007319 420 void FLASH_LockBank2(void)
mbed_official 52:a51c77007319 421 {
mbed_official 52:a51c77007319 422 /* Set the Lock Bit to lock the FPEC and the CR of Bank2 */
mbed_official 52:a51c77007319 423 FLASH->CR2 |= CR_LOCK_Set;
mbed_official 52:a51c77007319 424 }
mbed_official 52:a51c77007319 425 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 426
mbed_official 52:a51c77007319 427 /**
mbed_official 52:a51c77007319 428 * @brief Erases a specified FLASH page.
mbed_official 52:a51c77007319 429 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 430 * @param Page_Address: The page address to be erased.
mbed_official 52:a51c77007319 431 * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
mbed_official 52:a51c77007319 432 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 433 */
mbed_official 52:a51c77007319 434 FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
mbed_official 52:a51c77007319 435 {
mbed_official 52:a51c77007319 436 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 437 /* Check the parameters */
mbed_official 52:a51c77007319 438 assert_param(IS_FLASH_ADDRESS(Page_Address));
mbed_official 52:a51c77007319 439
mbed_official 52:a51c77007319 440 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 441 if(Page_Address < FLASH_BANK1_END_ADDRESS)
mbed_official 52:a51c77007319 442 {
mbed_official 52:a51c77007319 443 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 444 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 445 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 446 {
mbed_official 52:a51c77007319 447 /* if the previous operation is completed, proceed to erase the page */
mbed_official 52:a51c77007319 448 FLASH->CR|= CR_PER_Set;
mbed_official 52:a51c77007319 449 FLASH->AR = Page_Address;
mbed_official 52:a51c77007319 450 FLASH->CR|= CR_STRT_Set;
mbed_official 52:a51c77007319 451
mbed_official 52:a51c77007319 452 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 453 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 454
mbed_official 52:a51c77007319 455 /* Disable the PER Bit */
mbed_official 52:a51c77007319 456 FLASH->CR &= CR_PER_Reset;
mbed_official 52:a51c77007319 457 }
mbed_official 52:a51c77007319 458 }
mbed_official 52:a51c77007319 459 else
mbed_official 52:a51c77007319 460 {
mbed_official 52:a51c77007319 461 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 462 status = FLASH_WaitForLastBank2Operation(EraseTimeout);
mbed_official 52:a51c77007319 463 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 464 {
mbed_official 52:a51c77007319 465 /* if the previous operation is completed, proceed to erase the page */
mbed_official 52:a51c77007319 466 FLASH->CR2|= CR_PER_Set;
mbed_official 52:a51c77007319 467 FLASH->AR2 = Page_Address;
mbed_official 52:a51c77007319 468 FLASH->CR2|= CR_STRT_Set;
mbed_official 52:a51c77007319 469
mbed_official 52:a51c77007319 470 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 471 status = FLASH_WaitForLastBank2Operation(EraseTimeout);
mbed_official 52:a51c77007319 472
mbed_official 52:a51c77007319 473 /* Disable the PER Bit */
mbed_official 52:a51c77007319 474 FLASH->CR2 &= CR_PER_Reset;
mbed_official 52:a51c77007319 475 }
mbed_official 52:a51c77007319 476 }
mbed_official 52:a51c77007319 477 #else
mbed_official 52:a51c77007319 478 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 479 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 480
mbed_official 52:a51c77007319 481 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 482 {
mbed_official 52:a51c77007319 483 /* if the previous operation is completed, proceed to erase the page */
mbed_official 52:a51c77007319 484 FLASH->CR|= CR_PER_Set;
mbed_official 52:a51c77007319 485 FLASH->AR = Page_Address;
mbed_official 52:a51c77007319 486 FLASH->CR|= CR_STRT_Set;
mbed_official 52:a51c77007319 487
mbed_official 52:a51c77007319 488 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 489 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 490
mbed_official 52:a51c77007319 491 /* Disable the PER Bit */
mbed_official 52:a51c77007319 492 FLASH->CR &= CR_PER_Reset;
mbed_official 52:a51c77007319 493 }
mbed_official 52:a51c77007319 494 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 495
mbed_official 52:a51c77007319 496 /* Return the Erase Status */
mbed_official 52:a51c77007319 497 return status;
mbed_official 52:a51c77007319 498 }
mbed_official 52:a51c77007319 499
mbed_official 52:a51c77007319 500 /**
mbed_official 52:a51c77007319 501 * @brief Erases all FLASH pages.
mbed_official 52:a51c77007319 502 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 503 * @param None
mbed_official 52:a51c77007319 504 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 505 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 506 */
mbed_official 52:a51c77007319 507 FLASH_Status FLASH_EraseAllPages(void)
mbed_official 52:a51c77007319 508 {
mbed_official 52:a51c77007319 509 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 510
mbed_official 52:a51c77007319 511 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 512 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 513 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 514
mbed_official 52:a51c77007319 515 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 516 {
mbed_official 52:a51c77007319 517 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 52:a51c77007319 518 FLASH->CR |= CR_MER_Set;
mbed_official 52:a51c77007319 519 FLASH->CR |= CR_STRT_Set;
mbed_official 52:a51c77007319 520
mbed_official 52:a51c77007319 521 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 522 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 523
mbed_official 52:a51c77007319 524 /* Disable the MER Bit */
mbed_official 52:a51c77007319 525 FLASH->CR &= CR_MER_Reset;
mbed_official 52:a51c77007319 526 }
mbed_official 52:a51c77007319 527 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 528 {
mbed_official 52:a51c77007319 529 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 52:a51c77007319 530 FLASH->CR2 |= CR_MER_Set;
mbed_official 52:a51c77007319 531 FLASH->CR2 |= CR_STRT_Set;
mbed_official 52:a51c77007319 532
mbed_official 52:a51c77007319 533 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 534 status = FLASH_WaitForLastBank2Operation(EraseTimeout);
mbed_official 52:a51c77007319 535
mbed_official 52:a51c77007319 536 /* Disable the MER Bit */
mbed_official 52:a51c77007319 537 FLASH->CR2 &= CR_MER_Reset;
mbed_official 52:a51c77007319 538 }
mbed_official 52:a51c77007319 539 #else
mbed_official 52:a51c77007319 540 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 541 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 542 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 543 {
mbed_official 52:a51c77007319 544 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 52:a51c77007319 545 FLASH->CR |= CR_MER_Set;
mbed_official 52:a51c77007319 546 FLASH->CR |= CR_STRT_Set;
mbed_official 52:a51c77007319 547
mbed_official 52:a51c77007319 548 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 549 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 550
mbed_official 52:a51c77007319 551 /* Disable the MER Bit */
mbed_official 52:a51c77007319 552 FLASH->CR &= CR_MER_Reset;
mbed_official 52:a51c77007319 553 }
mbed_official 52:a51c77007319 554 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 555
mbed_official 52:a51c77007319 556 /* Return the Erase Status */
mbed_official 52:a51c77007319 557 return status;
mbed_official 52:a51c77007319 558 }
mbed_official 52:a51c77007319 559
mbed_official 52:a51c77007319 560 /**
mbed_official 52:a51c77007319 561 * @brief Erases all Bank1 FLASH pages.
mbed_official 52:a51c77007319 562 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 563 * - For STM32F10X_XL devices this function erases all Bank1 pages.
mbed_official 52:a51c77007319 564 * - For all other devices it erases all Bank1 pages and it is equivalent
mbed_official 52:a51c77007319 565 * to FLASH_EraseAllPages function.
mbed_official 52:a51c77007319 566 * @param None
mbed_official 52:a51c77007319 567 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 568 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 569 */
mbed_official 52:a51c77007319 570 FLASH_Status FLASH_EraseAllBank1Pages(void)
mbed_official 52:a51c77007319 571 {
mbed_official 52:a51c77007319 572 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 573 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 574 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 575
mbed_official 52:a51c77007319 576 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 577 {
mbed_official 52:a51c77007319 578 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 52:a51c77007319 579 FLASH->CR |= CR_MER_Set;
mbed_official 52:a51c77007319 580 FLASH->CR |= CR_STRT_Set;
mbed_official 52:a51c77007319 581
mbed_official 52:a51c77007319 582 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 583 status = FLASH_WaitForLastBank1Operation(EraseTimeout);
mbed_official 52:a51c77007319 584
mbed_official 52:a51c77007319 585 /* Disable the MER Bit */
mbed_official 52:a51c77007319 586 FLASH->CR &= CR_MER_Reset;
mbed_official 52:a51c77007319 587 }
mbed_official 52:a51c77007319 588 /* Return the Erase Status */
mbed_official 52:a51c77007319 589 return status;
mbed_official 52:a51c77007319 590 }
mbed_official 52:a51c77007319 591
mbed_official 52:a51c77007319 592 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 593 /**
mbed_official 52:a51c77007319 594 * @brief Erases all Bank2 FLASH pages.
mbed_official 52:a51c77007319 595 * @note This function can be used only for STM32F10x_XL density devices.
mbed_official 52:a51c77007319 596 * @param None
mbed_official 52:a51c77007319 597 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 598 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 599 */
mbed_official 52:a51c77007319 600 FLASH_Status FLASH_EraseAllBank2Pages(void)
mbed_official 52:a51c77007319 601 {
mbed_official 52:a51c77007319 602 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 603 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 604 status = FLASH_WaitForLastBank2Operation(EraseTimeout);
mbed_official 52:a51c77007319 605
mbed_official 52:a51c77007319 606 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 607 {
mbed_official 52:a51c77007319 608 /* if the previous operation is completed, proceed to erase all pages */
mbed_official 52:a51c77007319 609 FLASH->CR2 |= CR_MER_Set;
mbed_official 52:a51c77007319 610 FLASH->CR2 |= CR_STRT_Set;
mbed_official 52:a51c77007319 611
mbed_official 52:a51c77007319 612 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 613 status = FLASH_WaitForLastBank2Operation(EraseTimeout);
mbed_official 52:a51c77007319 614
mbed_official 52:a51c77007319 615 /* Disable the MER Bit */
mbed_official 52:a51c77007319 616 FLASH->CR2 &= CR_MER_Reset;
mbed_official 52:a51c77007319 617 }
mbed_official 52:a51c77007319 618 /* Return the Erase Status */
mbed_official 52:a51c77007319 619 return status;
mbed_official 52:a51c77007319 620 }
mbed_official 52:a51c77007319 621 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 622
mbed_official 52:a51c77007319 623 /**
mbed_official 52:a51c77007319 624 * @brief Erases the FLASH option bytes.
mbed_official 52:a51c77007319 625 * @note This functions erases all option bytes except the Read protection (RDP).
mbed_official 52:a51c77007319 626 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 627 * @param None
mbed_official 52:a51c77007319 628 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 629 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 630 */
mbed_official 52:a51c77007319 631 FLASH_Status FLASH_EraseOptionBytes(void)
mbed_official 52:a51c77007319 632 {
mbed_official 52:a51c77007319 633 uint16_t rdptmp = RDP_Key;
mbed_official 52:a51c77007319 634
mbed_official 52:a51c77007319 635 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 636
mbed_official 52:a51c77007319 637 /* Get the actual read protection Option Byte value */
mbed_official 52:a51c77007319 638 if(FLASH_GetReadOutProtectionStatus() != RESET)
mbed_official 52:a51c77007319 639 {
mbed_official 52:a51c77007319 640 rdptmp = 0x00;
mbed_official 52:a51c77007319 641 }
mbed_official 52:a51c77007319 642
mbed_official 52:a51c77007319 643 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 644 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 645 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 646 {
mbed_official 52:a51c77007319 647 /* Authorize the small information block programming */
mbed_official 52:a51c77007319 648 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 649 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 650
mbed_official 52:a51c77007319 651 /* if the previous operation is completed, proceed to erase the option bytes */
mbed_official 52:a51c77007319 652 FLASH->CR |= CR_OPTER_Set;
mbed_official 52:a51c77007319 653 FLASH->CR |= CR_STRT_Set;
mbed_official 52:a51c77007319 654 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 655 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 656
mbed_official 52:a51c77007319 657 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 658 {
mbed_official 52:a51c77007319 659 /* if the erase operation is completed, disable the OPTER Bit */
mbed_official 52:a51c77007319 660 FLASH->CR &= CR_OPTER_Reset;
mbed_official 52:a51c77007319 661
mbed_official 52:a51c77007319 662 /* Enable the Option Bytes Programming operation */
mbed_official 52:a51c77007319 663 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 664 /* Restore the last read protection Option Byte value */
mbed_official 52:a51c77007319 665 OB->RDP = (uint16_t)rdptmp;
mbed_official 52:a51c77007319 666 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 667 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 668
mbed_official 52:a51c77007319 669 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 670 {
mbed_official 52:a51c77007319 671 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 672 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 673 }
mbed_official 52:a51c77007319 674 }
mbed_official 52:a51c77007319 675 else
mbed_official 52:a51c77007319 676 {
mbed_official 52:a51c77007319 677 if (status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 678 {
mbed_official 52:a51c77007319 679 /* Disable the OPTPG Bit */
mbed_official 52:a51c77007319 680 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 681 }
mbed_official 52:a51c77007319 682 }
mbed_official 52:a51c77007319 683 }
mbed_official 52:a51c77007319 684 /* Return the erase status */
mbed_official 52:a51c77007319 685 return status;
mbed_official 52:a51c77007319 686 }
mbed_official 52:a51c77007319 687
mbed_official 52:a51c77007319 688 /**
mbed_official 52:a51c77007319 689 * @brief Programs a word at a specified address.
mbed_official 52:a51c77007319 690 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 691 * @param Address: specifies the address to be programmed.
mbed_official 52:a51c77007319 692 * @param Data: specifies the data to be programmed.
mbed_official 52:a51c77007319 693 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 694 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 695 */
mbed_official 52:a51c77007319 696 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
mbed_official 52:a51c77007319 697 {
mbed_official 52:a51c77007319 698 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 699 __IO uint32_t tmp = 0;
mbed_official 52:a51c77007319 700
mbed_official 52:a51c77007319 701 /* Check the parameters */
mbed_official 52:a51c77007319 702 assert_param(IS_FLASH_ADDRESS(Address));
mbed_official 52:a51c77007319 703
mbed_official 52:a51c77007319 704 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 705 if(Address < FLASH_BANK1_END_ADDRESS - 2)
mbed_official 52:a51c77007319 706 {
mbed_official 52:a51c77007319 707 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 708 status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
mbed_official 52:a51c77007319 709 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 710 {
mbed_official 52:a51c77007319 711 /* if the previous operation is completed, proceed to program the new first
mbed_official 52:a51c77007319 712 half word */
mbed_official 52:a51c77007319 713 FLASH->CR |= CR_PG_Set;
mbed_official 52:a51c77007319 714
mbed_official 52:a51c77007319 715 *(__IO uint16_t*)Address = (uint16_t)Data;
mbed_official 52:a51c77007319 716 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 717 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 718
mbed_official 52:a51c77007319 719 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 720 {
mbed_official 52:a51c77007319 721 /* if the previous operation is completed, proceed to program the new second
mbed_official 52:a51c77007319 722 half word */
mbed_official 52:a51c77007319 723 tmp = Address + 2;
mbed_official 52:a51c77007319 724
mbed_official 52:a51c77007319 725 *(__IO uint16_t*) tmp = Data >> 16;
mbed_official 52:a51c77007319 726
mbed_official 52:a51c77007319 727 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 728 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 729
mbed_official 52:a51c77007319 730 /* Disable the PG Bit */
mbed_official 52:a51c77007319 731 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 732 }
mbed_official 52:a51c77007319 733 else
mbed_official 52:a51c77007319 734 {
mbed_official 52:a51c77007319 735 /* Disable the PG Bit */
mbed_official 52:a51c77007319 736 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 737 }
mbed_official 52:a51c77007319 738 }
mbed_official 52:a51c77007319 739 }
mbed_official 52:a51c77007319 740 else if(Address == (FLASH_BANK1_END_ADDRESS - 1))
mbed_official 52:a51c77007319 741 {
mbed_official 52:a51c77007319 742 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 743 status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
mbed_official 52:a51c77007319 744
mbed_official 52:a51c77007319 745 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 746 {
mbed_official 52:a51c77007319 747 /* if the previous operation is completed, proceed to program the new first
mbed_official 52:a51c77007319 748 half word */
mbed_official 52:a51c77007319 749 FLASH->CR |= CR_PG_Set;
mbed_official 52:a51c77007319 750
mbed_official 52:a51c77007319 751 *(__IO uint16_t*)Address = (uint16_t)Data;
mbed_official 52:a51c77007319 752
mbed_official 52:a51c77007319 753 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 754 status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
mbed_official 52:a51c77007319 755
mbed_official 52:a51c77007319 756 /* Disable the PG Bit */
mbed_official 52:a51c77007319 757 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 758 }
mbed_official 52:a51c77007319 759 else
mbed_official 52:a51c77007319 760 {
mbed_official 52:a51c77007319 761 /* Disable the PG Bit */
mbed_official 52:a51c77007319 762 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 763 }
mbed_official 52:a51c77007319 764
mbed_official 52:a51c77007319 765 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 766 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 767
mbed_official 52:a51c77007319 768 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 769 {
mbed_official 52:a51c77007319 770 /* if the previous operation is completed, proceed to program the new second
mbed_official 52:a51c77007319 771 half word */
mbed_official 52:a51c77007319 772 FLASH->CR2 |= CR_PG_Set;
mbed_official 52:a51c77007319 773 tmp = Address + 2;
mbed_official 52:a51c77007319 774
mbed_official 52:a51c77007319 775 *(__IO uint16_t*) tmp = Data >> 16;
mbed_official 52:a51c77007319 776
mbed_official 52:a51c77007319 777 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 778 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 779
mbed_official 52:a51c77007319 780 /* Disable the PG Bit */
mbed_official 52:a51c77007319 781 FLASH->CR2 &= CR_PG_Reset;
mbed_official 52:a51c77007319 782 }
mbed_official 52:a51c77007319 783 else
mbed_official 52:a51c77007319 784 {
mbed_official 52:a51c77007319 785 /* Disable the PG Bit */
mbed_official 52:a51c77007319 786 FLASH->CR2 &= CR_PG_Reset;
mbed_official 52:a51c77007319 787 }
mbed_official 52:a51c77007319 788 }
mbed_official 52:a51c77007319 789 else
mbed_official 52:a51c77007319 790 {
mbed_official 52:a51c77007319 791 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 792 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 793
mbed_official 52:a51c77007319 794 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 795 {
mbed_official 52:a51c77007319 796 /* if the previous operation is completed, proceed to program the new first
mbed_official 52:a51c77007319 797 half word */
mbed_official 52:a51c77007319 798 FLASH->CR2 |= CR_PG_Set;
mbed_official 52:a51c77007319 799
mbed_official 52:a51c77007319 800 *(__IO uint16_t*)Address = (uint16_t)Data;
mbed_official 52:a51c77007319 801 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 802 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 803
mbed_official 52:a51c77007319 804 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 805 {
mbed_official 52:a51c77007319 806 /* if the previous operation is completed, proceed to program the new second
mbed_official 52:a51c77007319 807 half word */
mbed_official 52:a51c77007319 808 tmp = Address + 2;
mbed_official 52:a51c77007319 809
mbed_official 52:a51c77007319 810 *(__IO uint16_t*) tmp = Data >> 16;
mbed_official 52:a51c77007319 811
mbed_official 52:a51c77007319 812 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 813 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 814
mbed_official 52:a51c77007319 815 /* Disable the PG Bit */
mbed_official 52:a51c77007319 816 FLASH->CR2 &= CR_PG_Reset;
mbed_official 52:a51c77007319 817 }
mbed_official 52:a51c77007319 818 else
mbed_official 52:a51c77007319 819 {
mbed_official 52:a51c77007319 820 /* Disable the PG Bit */
mbed_official 52:a51c77007319 821 FLASH->CR2 &= CR_PG_Reset;
mbed_official 52:a51c77007319 822 }
mbed_official 52:a51c77007319 823 }
mbed_official 52:a51c77007319 824 }
mbed_official 52:a51c77007319 825 #else
mbed_official 52:a51c77007319 826 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 827 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 828
mbed_official 52:a51c77007319 829 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 830 {
mbed_official 52:a51c77007319 831 /* if the previous operation is completed, proceed to program the new first
mbed_official 52:a51c77007319 832 half word */
mbed_official 52:a51c77007319 833 FLASH->CR |= CR_PG_Set;
mbed_official 52:a51c77007319 834
mbed_official 52:a51c77007319 835 *(__IO uint16_t*)Address = (uint16_t)Data;
mbed_official 52:a51c77007319 836 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 837 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 838
mbed_official 52:a51c77007319 839 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 840 {
mbed_official 52:a51c77007319 841 /* if the previous operation is completed, proceed to program the new second
mbed_official 52:a51c77007319 842 half word */
mbed_official 52:a51c77007319 843 tmp = Address + 2;
mbed_official 52:a51c77007319 844
mbed_official 52:a51c77007319 845 *(__IO uint16_t*) tmp = Data >> 16;
mbed_official 52:a51c77007319 846
mbed_official 52:a51c77007319 847 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 848 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 849
mbed_official 52:a51c77007319 850 /* Disable the PG Bit */
mbed_official 52:a51c77007319 851 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 852 }
mbed_official 52:a51c77007319 853 else
mbed_official 52:a51c77007319 854 {
mbed_official 52:a51c77007319 855 /* Disable the PG Bit */
mbed_official 52:a51c77007319 856 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 857 }
mbed_official 52:a51c77007319 858 }
mbed_official 52:a51c77007319 859 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 860
mbed_official 52:a51c77007319 861 /* Return the Program Status */
mbed_official 52:a51c77007319 862 return status;
mbed_official 52:a51c77007319 863 }
mbed_official 52:a51c77007319 864
mbed_official 52:a51c77007319 865 /**
mbed_official 52:a51c77007319 866 * @brief Programs a half word at a specified address.
mbed_official 52:a51c77007319 867 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 868 * @param Address: specifies the address to be programmed.
mbed_official 52:a51c77007319 869 * @param Data: specifies the data to be programmed.
mbed_official 52:a51c77007319 870 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 871 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 872 */
mbed_official 52:a51c77007319 873 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
mbed_official 52:a51c77007319 874 {
mbed_official 52:a51c77007319 875 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 876 /* Check the parameters */
mbed_official 52:a51c77007319 877 assert_param(IS_FLASH_ADDRESS(Address));
mbed_official 52:a51c77007319 878
mbed_official 52:a51c77007319 879 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 880 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 881 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 882
mbed_official 52:a51c77007319 883 if(Address < FLASH_BANK1_END_ADDRESS)
mbed_official 52:a51c77007319 884 {
mbed_official 52:a51c77007319 885 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 886 {
mbed_official 52:a51c77007319 887 /* if the previous operation is completed, proceed to program the new data */
mbed_official 52:a51c77007319 888 FLASH->CR |= CR_PG_Set;
mbed_official 52:a51c77007319 889
mbed_official 52:a51c77007319 890 *(__IO uint16_t*)Address = Data;
mbed_official 52:a51c77007319 891 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 892 status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
mbed_official 52:a51c77007319 893
mbed_official 52:a51c77007319 894 /* Disable the PG Bit */
mbed_official 52:a51c77007319 895 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 896 }
mbed_official 52:a51c77007319 897 }
mbed_official 52:a51c77007319 898 else
mbed_official 52:a51c77007319 899 {
mbed_official 52:a51c77007319 900 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 901 {
mbed_official 52:a51c77007319 902 /* if the previous operation is completed, proceed to program the new data */
mbed_official 52:a51c77007319 903 FLASH->CR2 |= CR_PG_Set;
mbed_official 52:a51c77007319 904
mbed_official 52:a51c77007319 905 *(__IO uint16_t*)Address = Data;
mbed_official 52:a51c77007319 906 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 907 status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
mbed_official 52:a51c77007319 908
mbed_official 52:a51c77007319 909 /* Disable the PG Bit */
mbed_official 52:a51c77007319 910 FLASH->CR2 &= CR_PG_Reset;
mbed_official 52:a51c77007319 911 }
mbed_official 52:a51c77007319 912 }
mbed_official 52:a51c77007319 913 #else
mbed_official 52:a51c77007319 914 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 915 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 916
mbed_official 52:a51c77007319 917 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 918 {
mbed_official 52:a51c77007319 919 /* if the previous operation is completed, proceed to program the new data */
mbed_official 52:a51c77007319 920 FLASH->CR |= CR_PG_Set;
mbed_official 52:a51c77007319 921
mbed_official 52:a51c77007319 922 *(__IO uint16_t*)Address = Data;
mbed_official 52:a51c77007319 923 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 924 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 925
mbed_official 52:a51c77007319 926 /* Disable the PG Bit */
mbed_official 52:a51c77007319 927 FLASH->CR &= CR_PG_Reset;
mbed_official 52:a51c77007319 928 }
mbed_official 52:a51c77007319 929 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 930
mbed_official 52:a51c77007319 931 /* Return the Program Status */
mbed_official 52:a51c77007319 932 return status;
mbed_official 52:a51c77007319 933 }
mbed_official 52:a51c77007319 934
mbed_official 52:a51c77007319 935 /**
mbed_official 52:a51c77007319 936 * @brief Programs a half word at a specified Option Byte Data address.
mbed_official 52:a51c77007319 937 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 938 * @param Address: specifies the address to be programmed.
mbed_official 52:a51c77007319 939 * This parameter can be 0x1FFFF804 or 0x1FFFF806.
mbed_official 52:a51c77007319 940 * @param Data: specifies the data to be programmed.
mbed_official 52:a51c77007319 941 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 942 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 943 */
mbed_official 52:a51c77007319 944 FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)
mbed_official 52:a51c77007319 945 {
mbed_official 52:a51c77007319 946 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 947 /* Check the parameters */
mbed_official 52:a51c77007319 948 assert_param(IS_OB_DATA_ADDRESS(Address));
mbed_official 52:a51c77007319 949 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 950
mbed_official 52:a51c77007319 951 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 952 {
mbed_official 52:a51c77007319 953 /* Authorize the small information block programming */
mbed_official 52:a51c77007319 954 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 955 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 956 /* Enables the Option Bytes Programming operation */
mbed_official 52:a51c77007319 957 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 958 *(__IO uint16_t*)Address = Data;
mbed_official 52:a51c77007319 959
mbed_official 52:a51c77007319 960 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 961 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 962 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 963 {
mbed_official 52:a51c77007319 964 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 965 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 966 }
mbed_official 52:a51c77007319 967 }
mbed_official 52:a51c77007319 968 /* Return the Option Byte Data Program Status */
mbed_official 52:a51c77007319 969 return status;
mbed_official 52:a51c77007319 970 }
mbed_official 52:a51c77007319 971
mbed_official 52:a51c77007319 972 /**
mbed_official 52:a51c77007319 973 * @brief Write protects the desired pages
mbed_official 52:a51c77007319 974 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 975 * @param FLASH_Pages: specifies the address of the pages to be write protected.
mbed_official 52:a51c77007319 976 * This parameter can be:
mbed_official 52:a51c77007319 977 * @arg For @b STM32_Low-density_devices: value between FLASH_WRProt_Pages0to3 and FLASH_WRProt_Pages28to31
mbed_official 52:a51c77007319 978 * @arg For @b STM32_Medium-density_devices: value between FLASH_WRProt_Pages0to3
mbed_official 52:a51c77007319 979 * and FLASH_WRProt_Pages124to127
mbed_official 52:a51c77007319 980 * @arg For @b STM32_High-density_devices: value between FLASH_WRProt_Pages0to1 and
mbed_official 52:a51c77007319 981 * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to255
mbed_official 52:a51c77007319 982 * @arg For @b STM32_Connectivity_line_devices: value between FLASH_WRProt_Pages0to1 and
mbed_official 52:a51c77007319 983 * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to127
mbed_official 52:a51c77007319 984 * @arg For @b STM32_XL-density_devices: value between FLASH_WRProt_Pages0to1 and
mbed_official 52:a51c77007319 985 * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to511
mbed_official 52:a51c77007319 986 * @arg FLASH_WRProt_AllPages
mbed_official 52:a51c77007319 987 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 988 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 989 */
mbed_official 52:a51c77007319 990 FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages)
mbed_official 52:a51c77007319 991 {
mbed_official 52:a51c77007319 992 uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
mbed_official 52:a51c77007319 993
mbed_official 52:a51c77007319 994 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 995
mbed_official 52:a51c77007319 996 /* Check the parameters */
mbed_official 52:a51c77007319 997 assert_param(IS_FLASH_WRPROT_PAGE(FLASH_Pages));
mbed_official 52:a51c77007319 998
mbed_official 52:a51c77007319 999 FLASH_Pages = (uint32_t)(~FLASH_Pages);
mbed_official 52:a51c77007319 1000 WRP0_Data = (uint16_t)(FLASH_Pages & WRP0_Mask);
mbed_official 52:a51c77007319 1001 WRP1_Data = (uint16_t)((FLASH_Pages & WRP1_Mask) >> 8);
mbed_official 52:a51c77007319 1002 WRP2_Data = (uint16_t)((FLASH_Pages & WRP2_Mask) >> 16);
mbed_official 52:a51c77007319 1003 WRP3_Data = (uint16_t)((FLASH_Pages & WRP3_Mask) >> 24);
mbed_official 52:a51c77007319 1004
mbed_official 52:a51c77007319 1005 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1006 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1007
mbed_official 52:a51c77007319 1008 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 1009 {
mbed_official 52:a51c77007319 1010 /* Authorizes the small information block programming */
mbed_official 52:a51c77007319 1011 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 1012 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 1013 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 1014 if(WRP0_Data != 0xFF)
mbed_official 52:a51c77007319 1015 {
mbed_official 52:a51c77007319 1016 OB->WRP0 = WRP0_Data;
mbed_official 52:a51c77007319 1017
mbed_official 52:a51c77007319 1018 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1019 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1020 }
mbed_official 52:a51c77007319 1021 if((status == FLASH_COMPLETE) && (WRP1_Data != 0xFF))
mbed_official 52:a51c77007319 1022 {
mbed_official 52:a51c77007319 1023 OB->WRP1 = WRP1_Data;
mbed_official 52:a51c77007319 1024
mbed_official 52:a51c77007319 1025 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1026 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1027 }
mbed_official 52:a51c77007319 1028 if((status == FLASH_COMPLETE) && (WRP2_Data != 0xFF))
mbed_official 52:a51c77007319 1029 {
mbed_official 52:a51c77007319 1030 OB->WRP2 = WRP2_Data;
mbed_official 52:a51c77007319 1031
mbed_official 52:a51c77007319 1032 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1033 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1034 }
mbed_official 52:a51c77007319 1035
mbed_official 52:a51c77007319 1036 if((status == FLASH_COMPLETE)&& (WRP3_Data != 0xFF))
mbed_official 52:a51c77007319 1037 {
mbed_official 52:a51c77007319 1038 OB->WRP3 = WRP3_Data;
mbed_official 52:a51c77007319 1039
mbed_official 52:a51c77007319 1040 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1041 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1042 }
mbed_official 52:a51c77007319 1043
mbed_official 52:a51c77007319 1044 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 1045 {
mbed_official 52:a51c77007319 1046 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 1047 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 1048 }
mbed_official 52:a51c77007319 1049 }
mbed_official 52:a51c77007319 1050 /* Return the write protection operation Status */
mbed_official 52:a51c77007319 1051 return status;
mbed_official 52:a51c77007319 1052 }
mbed_official 52:a51c77007319 1053
mbed_official 52:a51c77007319 1054 /**
mbed_official 52:a51c77007319 1055 * @brief Enables or disables the read out protection.
mbed_official 52:a51c77007319 1056 * @note If the user has already programmed the other option bytes before calling
mbed_official 52:a51c77007319 1057 * this function, he must re-program them since this function erases all option bytes.
mbed_official 52:a51c77007319 1058 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1059 * @param Newstate: new state of the ReadOut Protection.
mbed_official 52:a51c77007319 1060 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 1061 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1062 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1063 */
mbed_official 52:a51c77007319 1064 FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
mbed_official 52:a51c77007319 1065 {
mbed_official 52:a51c77007319 1066 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1067 /* Check the parameters */
mbed_official 52:a51c77007319 1068 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 1069 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 1070 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 1071 {
mbed_official 52:a51c77007319 1072 /* Authorizes the small information block programming */
mbed_official 52:a51c77007319 1073 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 1074 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 1075 FLASH->CR |= CR_OPTER_Set;
mbed_official 52:a51c77007319 1076 FLASH->CR |= CR_STRT_Set;
mbed_official 52:a51c77007319 1077 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1078 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 1079 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 1080 {
mbed_official 52:a51c77007319 1081 /* if the erase operation is completed, disable the OPTER Bit */
mbed_official 52:a51c77007319 1082 FLASH->CR &= CR_OPTER_Reset;
mbed_official 52:a51c77007319 1083 /* Enable the Option Bytes Programming operation */
mbed_official 52:a51c77007319 1084 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 1085 if(NewState != DISABLE)
mbed_official 52:a51c77007319 1086 {
mbed_official 52:a51c77007319 1087 OB->RDP = 0x00;
mbed_official 52:a51c77007319 1088 }
mbed_official 52:a51c77007319 1089 else
mbed_official 52:a51c77007319 1090 {
mbed_official 52:a51c77007319 1091 OB->RDP = RDP_Key;
mbed_official 52:a51c77007319 1092 }
mbed_official 52:a51c77007319 1093 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1094 status = FLASH_WaitForLastOperation(EraseTimeout);
mbed_official 52:a51c77007319 1095
mbed_official 52:a51c77007319 1096 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 1097 {
mbed_official 52:a51c77007319 1098 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 1099 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 1100 }
mbed_official 52:a51c77007319 1101 }
mbed_official 52:a51c77007319 1102 else
mbed_official 52:a51c77007319 1103 {
mbed_official 52:a51c77007319 1104 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 1105 {
mbed_official 52:a51c77007319 1106 /* Disable the OPTER Bit */
mbed_official 52:a51c77007319 1107 FLASH->CR &= CR_OPTER_Reset;
mbed_official 52:a51c77007319 1108 }
mbed_official 52:a51c77007319 1109 }
mbed_official 52:a51c77007319 1110 }
mbed_official 52:a51c77007319 1111 /* Return the protection operation Status */
mbed_official 52:a51c77007319 1112 return status;
mbed_official 52:a51c77007319 1113 }
mbed_official 52:a51c77007319 1114
mbed_official 52:a51c77007319 1115 /**
mbed_official 52:a51c77007319 1116 * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
mbed_official 52:a51c77007319 1117 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1118 * @param OB_IWDG: Selects the IWDG mode
mbed_official 52:a51c77007319 1119 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 1120 * @arg OB_IWDG_SW: Software IWDG selected
mbed_official 52:a51c77007319 1121 * @arg OB_IWDG_HW: Hardware IWDG selected
mbed_official 52:a51c77007319 1122 * @param OB_STOP: Reset event when entering STOP mode.
mbed_official 52:a51c77007319 1123 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 1124 * @arg OB_STOP_NoRST: No reset generated when entering in STOP
mbed_official 52:a51c77007319 1125 * @arg OB_STOP_RST: Reset generated when entering in STOP
mbed_official 52:a51c77007319 1126 * @param OB_STDBY: Reset event when entering Standby mode.
mbed_official 52:a51c77007319 1127 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 1128 * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
mbed_official 52:a51c77007319 1129 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
mbed_official 52:a51c77007319 1130 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1131 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1132 */
mbed_official 52:a51c77007319 1133 FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY)
mbed_official 52:a51c77007319 1134 {
mbed_official 52:a51c77007319 1135 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1136
mbed_official 52:a51c77007319 1137 /* Check the parameters */
mbed_official 52:a51c77007319 1138 assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
mbed_official 52:a51c77007319 1139 assert_param(IS_OB_STOP_SOURCE(OB_STOP));
mbed_official 52:a51c77007319 1140 assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
mbed_official 52:a51c77007319 1141
mbed_official 52:a51c77007319 1142 /* Authorize the small information block programming */
mbed_official 52:a51c77007319 1143 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 1144 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 1145
mbed_official 52:a51c77007319 1146 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1147 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1148
mbed_official 52:a51c77007319 1149 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 1150 {
mbed_official 52:a51c77007319 1151 /* Enable the Option Bytes Programming operation */
mbed_official 52:a51c77007319 1152 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 1153
mbed_official 52:a51c77007319 1154 OB->USER = OB_IWDG | (uint16_t)(OB_STOP | (uint16_t)(OB_STDBY | ((uint16_t)0xF8)));
mbed_official 52:a51c77007319 1155
mbed_official 52:a51c77007319 1156 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1157 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1158 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 1159 {
mbed_official 52:a51c77007319 1160 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 1161 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 1162 }
mbed_official 52:a51c77007319 1163 }
mbed_official 52:a51c77007319 1164 /* Return the Option Byte program Status */
mbed_official 52:a51c77007319 1165 return status;
mbed_official 52:a51c77007319 1166 }
mbed_official 52:a51c77007319 1167
mbed_official 52:a51c77007319 1168 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1169 /**
mbed_official 52:a51c77007319 1170 * @brief Configures to boot from Bank1 or Bank2.
mbed_official 52:a51c77007319 1171 * @note This function can be used only for STM32F10x_XL density devices.
mbed_official 52:a51c77007319 1172 * @param FLASH_BOOT: select the FLASH Bank to boot from.
mbed_official 52:a51c77007319 1173 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 1174 * @arg FLASH_BOOT_Bank1: At startup, if boot pins are set in boot from user Flash
mbed_official 52:a51c77007319 1175 * position and this parameter is selected the device will boot from Bank1(Default).
mbed_official 52:a51c77007319 1176 * @arg FLASH_BOOT_Bank2: At startup, if boot pins are set in boot from user Flash
mbed_official 52:a51c77007319 1177 * position and this parameter is selected the device will boot from Bank2 or Bank1,
mbed_official 52:a51c77007319 1178 * depending on the activation of the bank. The active banks are checked in
mbed_official 52:a51c77007319 1179 * the following order: Bank2, followed by Bank1.
mbed_official 52:a51c77007319 1180 * The active bank is recognized by the value programmed at the base address
mbed_official 52:a51c77007319 1181 * of the respective bank (corresponding to the initial stack pointer value
mbed_official 52:a51c77007319 1182 * in the interrupt vector table).
mbed_official 52:a51c77007319 1183 * For more information, please refer to AN2606 from www.st.com.
mbed_official 52:a51c77007319 1184 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1185 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1186 */
mbed_official 52:a51c77007319 1187 FLASH_Status FLASH_BootConfig(uint16_t FLASH_BOOT)
mbed_official 52:a51c77007319 1188 {
mbed_official 52:a51c77007319 1189 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1190 assert_param(IS_FLASH_BOOT(FLASH_BOOT));
mbed_official 52:a51c77007319 1191 /* Authorize the small information block programming */
mbed_official 52:a51c77007319 1192 FLASH->OPTKEYR = FLASH_KEY1;
mbed_official 52:a51c77007319 1193 FLASH->OPTKEYR = FLASH_KEY2;
mbed_official 52:a51c77007319 1194
mbed_official 52:a51c77007319 1195 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1196 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1197
mbed_official 52:a51c77007319 1198 if(status == FLASH_COMPLETE)
mbed_official 52:a51c77007319 1199 {
mbed_official 52:a51c77007319 1200 /* Enable the Option Bytes Programming operation */
mbed_official 52:a51c77007319 1201 FLASH->CR |= CR_OPTPG_Set;
mbed_official 52:a51c77007319 1202
mbed_official 52:a51c77007319 1203 if(FLASH_BOOT == FLASH_BOOT_Bank1)
mbed_official 52:a51c77007319 1204 {
mbed_official 52:a51c77007319 1205 OB->USER |= OB_USER_BFB2;
mbed_official 52:a51c77007319 1206 }
mbed_official 52:a51c77007319 1207 else
mbed_official 52:a51c77007319 1208 {
mbed_official 52:a51c77007319 1209 OB->USER &= (uint16_t)(~(uint16_t)(OB_USER_BFB2));
mbed_official 52:a51c77007319 1210 }
mbed_official 52:a51c77007319 1211 /* Wait for last operation to be completed */
mbed_official 52:a51c77007319 1212 status = FLASH_WaitForLastOperation(ProgramTimeout);
mbed_official 52:a51c77007319 1213 if(status != FLASH_TIMEOUT)
mbed_official 52:a51c77007319 1214 {
mbed_official 52:a51c77007319 1215 /* if the program operation is completed, disable the OPTPG Bit */
mbed_official 52:a51c77007319 1216 FLASH->CR &= CR_OPTPG_Reset;
mbed_official 52:a51c77007319 1217 }
mbed_official 52:a51c77007319 1218 }
mbed_official 52:a51c77007319 1219 /* Return the Option Byte program Status */
mbed_official 52:a51c77007319 1220 return status;
mbed_official 52:a51c77007319 1221 }
mbed_official 52:a51c77007319 1222 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1223
mbed_official 52:a51c77007319 1224 /**
mbed_official 52:a51c77007319 1225 * @brief Returns the FLASH User Option Bytes values.
mbed_official 52:a51c77007319 1226 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1227 * @param None
mbed_official 52:a51c77007319 1228 * @retval The FLASH User Option Bytes values:IWDG_SW(Bit0), RST_STOP(Bit1)
mbed_official 52:a51c77007319 1229 * and RST_STDBY(Bit2).
mbed_official 52:a51c77007319 1230 */
mbed_official 52:a51c77007319 1231 uint32_t FLASH_GetUserOptionByte(void)
mbed_official 52:a51c77007319 1232 {
mbed_official 52:a51c77007319 1233 /* Return the User Option Byte */
mbed_official 52:a51c77007319 1234 return (uint32_t)(FLASH->OBR >> 2);
mbed_official 52:a51c77007319 1235 }
mbed_official 52:a51c77007319 1236
mbed_official 52:a51c77007319 1237 /**
mbed_official 52:a51c77007319 1238 * @brief Returns the FLASH Write Protection Option Bytes Register value.
mbed_official 52:a51c77007319 1239 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1240 * @param None
mbed_official 52:a51c77007319 1241 * @retval The FLASH Write Protection Option Bytes Register value
mbed_official 52:a51c77007319 1242 */
mbed_official 52:a51c77007319 1243 uint32_t FLASH_GetWriteProtectionOptionByte(void)
mbed_official 52:a51c77007319 1244 {
mbed_official 52:a51c77007319 1245 /* Return the Flash write protection Register value */
mbed_official 52:a51c77007319 1246 return (uint32_t)(FLASH->WRPR);
mbed_official 52:a51c77007319 1247 }
mbed_official 52:a51c77007319 1248
mbed_official 52:a51c77007319 1249 /**
mbed_official 52:a51c77007319 1250 * @brief Checks whether the FLASH Read Out Protection Status is set or not.
mbed_official 52:a51c77007319 1251 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1252 * @param None
mbed_official 52:a51c77007319 1253 * @retval FLASH ReadOut Protection Status(SET or RESET)
mbed_official 52:a51c77007319 1254 */
mbed_official 52:a51c77007319 1255 FlagStatus FLASH_GetReadOutProtectionStatus(void)
mbed_official 52:a51c77007319 1256 {
mbed_official 52:a51c77007319 1257 FlagStatus readoutstatus = RESET;
mbed_official 52:a51c77007319 1258 if ((FLASH->OBR & RDPRT_Mask) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1259 {
mbed_official 52:a51c77007319 1260 readoutstatus = SET;
mbed_official 52:a51c77007319 1261 }
mbed_official 52:a51c77007319 1262 else
mbed_official 52:a51c77007319 1263 {
mbed_official 52:a51c77007319 1264 readoutstatus = RESET;
mbed_official 52:a51c77007319 1265 }
mbed_official 52:a51c77007319 1266 return readoutstatus;
mbed_official 52:a51c77007319 1267 }
mbed_official 52:a51c77007319 1268
mbed_official 52:a51c77007319 1269 /**
mbed_official 52:a51c77007319 1270 * @brief Checks whether the FLASH Prefetch Buffer status is set or not.
mbed_official 52:a51c77007319 1271 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1272 * @param None
mbed_official 52:a51c77007319 1273 * @retval FLASH Prefetch Buffer Status (SET or RESET).
mbed_official 52:a51c77007319 1274 */
mbed_official 52:a51c77007319 1275 FlagStatus FLASH_GetPrefetchBufferStatus(void)
mbed_official 52:a51c77007319 1276 {
mbed_official 52:a51c77007319 1277 FlagStatus bitstatus = RESET;
mbed_official 52:a51c77007319 1278
mbed_official 52:a51c77007319 1279 if ((FLASH->ACR & ACR_PRFTBS_Mask) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1280 {
mbed_official 52:a51c77007319 1281 bitstatus = SET;
mbed_official 52:a51c77007319 1282 }
mbed_official 52:a51c77007319 1283 else
mbed_official 52:a51c77007319 1284 {
mbed_official 52:a51c77007319 1285 bitstatus = RESET;
mbed_official 52:a51c77007319 1286 }
mbed_official 52:a51c77007319 1287 /* Return the new state of FLASH Prefetch Buffer Status (SET or RESET) */
mbed_official 52:a51c77007319 1288 return bitstatus;
mbed_official 52:a51c77007319 1289 }
mbed_official 52:a51c77007319 1290
mbed_official 52:a51c77007319 1291 /**
mbed_official 52:a51c77007319 1292 * @brief Enables or disables the specified FLASH interrupts.
mbed_official 52:a51c77007319 1293 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1294 * - For STM32F10X_XL devices, enables or disables the specified FLASH interrupts
mbed_official 52:a51c77007319 1295 for Bank1 and Bank2.
mbed_official 52:a51c77007319 1296 * - For other devices it enables or disables the specified FLASH interrupts for Bank1.
mbed_official 52:a51c77007319 1297 * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or disabled.
mbed_official 52:a51c77007319 1298 * This parameter can be any combination of the following values:
mbed_official 52:a51c77007319 1299 * @arg FLASH_IT_ERROR: FLASH Error Interrupt
mbed_official 52:a51c77007319 1300 * @arg FLASH_IT_EOP: FLASH end of operation Interrupt
mbed_official 52:a51c77007319 1301 * @param NewState: new state of the specified Flash interrupts.
mbed_official 52:a51c77007319 1302 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 1303 * @retval None
mbed_official 52:a51c77007319 1304 */
mbed_official 52:a51c77007319 1305 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
mbed_official 52:a51c77007319 1306 {
mbed_official 52:a51c77007319 1307 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1308 /* Check the parameters */
mbed_official 52:a51c77007319 1309 assert_param(IS_FLASH_IT(FLASH_IT));
mbed_official 52:a51c77007319 1310 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 1311
mbed_official 52:a51c77007319 1312 if((FLASH_IT & 0x80000000) != 0x0)
mbed_official 52:a51c77007319 1313 {
mbed_official 52:a51c77007319 1314 if(NewState != DISABLE)
mbed_official 52:a51c77007319 1315 {
mbed_official 52:a51c77007319 1316 /* Enable the interrupt sources */
mbed_official 52:a51c77007319 1317 FLASH->CR2 |= (FLASH_IT & 0x7FFFFFFF);
mbed_official 52:a51c77007319 1318 }
mbed_official 52:a51c77007319 1319 else
mbed_official 52:a51c77007319 1320 {
mbed_official 52:a51c77007319 1321 /* Disable the interrupt sources */
mbed_official 52:a51c77007319 1322 FLASH->CR2 &= ~(uint32_t)(FLASH_IT & 0x7FFFFFFF);
mbed_official 52:a51c77007319 1323 }
mbed_official 52:a51c77007319 1324 }
mbed_official 52:a51c77007319 1325 else
mbed_official 52:a51c77007319 1326 {
mbed_official 52:a51c77007319 1327 if(NewState != DISABLE)
mbed_official 52:a51c77007319 1328 {
mbed_official 52:a51c77007319 1329 /* Enable the interrupt sources */
mbed_official 52:a51c77007319 1330 FLASH->CR |= FLASH_IT;
mbed_official 52:a51c77007319 1331 }
mbed_official 52:a51c77007319 1332 else
mbed_official 52:a51c77007319 1333 {
mbed_official 52:a51c77007319 1334 /* Disable the interrupt sources */
mbed_official 52:a51c77007319 1335 FLASH->CR &= ~(uint32_t)FLASH_IT;
mbed_official 52:a51c77007319 1336 }
mbed_official 52:a51c77007319 1337 }
mbed_official 52:a51c77007319 1338 #else
mbed_official 52:a51c77007319 1339 /* Check the parameters */
mbed_official 52:a51c77007319 1340 assert_param(IS_FLASH_IT(FLASH_IT));
mbed_official 52:a51c77007319 1341 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 1342
mbed_official 52:a51c77007319 1343 if(NewState != DISABLE)
mbed_official 52:a51c77007319 1344 {
mbed_official 52:a51c77007319 1345 /* Enable the interrupt sources */
mbed_official 52:a51c77007319 1346 FLASH->CR |= FLASH_IT;
mbed_official 52:a51c77007319 1347 }
mbed_official 52:a51c77007319 1348 else
mbed_official 52:a51c77007319 1349 {
mbed_official 52:a51c77007319 1350 /* Disable the interrupt sources */
mbed_official 52:a51c77007319 1351 FLASH->CR &= ~(uint32_t)FLASH_IT;
mbed_official 52:a51c77007319 1352 }
mbed_official 52:a51c77007319 1353 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1354 }
mbed_official 52:a51c77007319 1355
mbed_official 52:a51c77007319 1356 /**
mbed_official 52:a51c77007319 1357 * @brief Checks whether the specified FLASH flag is set or not.
mbed_official 52:a51c77007319 1358 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1359 * - For STM32F10X_XL devices, this function checks whether the specified
mbed_official 52:a51c77007319 1360 * Bank1 or Bank2 flag is set or not.
mbed_official 52:a51c77007319 1361 * - For other devices, it checks whether the specified Bank1 flag is
mbed_official 52:a51c77007319 1362 * set or not.
mbed_official 52:a51c77007319 1363 * @param FLASH_FLAG: specifies the FLASH flag to check.
mbed_official 52:a51c77007319 1364 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 1365 * @arg FLASH_FLAG_BSY: FLASH Busy flag
mbed_official 52:a51c77007319 1366 * @arg FLASH_FLAG_PGERR: FLASH Program error flag
mbed_official 52:a51c77007319 1367 * @arg FLASH_FLAG_WRPRTERR: FLASH Write protected error flag
mbed_official 52:a51c77007319 1368 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
mbed_official 52:a51c77007319 1369 * @arg FLASH_FLAG_OPTERR: FLASH Option Byte error flag
mbed_official 52:a51c77007319 1370 * @retval The new state of FLASH_FLAG (SET or RESET).
mbed_official 52:a51c77007319 1371 */
mbed_official 52:a51c77007319 1372 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
mbed_official 52:a51c77007319 1373 {
mbed_official 52:a51c77007319 1374 FlagStatus bitstatus = RESET;
mbed_official 52:a51c77007319 1375
mbed_official 52:a51c77007319 1376 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1377 /* Check the parameters */
mbed_official 52:a51c77007319 1378 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)) ;
mbed_official 52:a51c77007319 1379 if(FLASH_FLAG == FLASH_FLAG_OPTERR)
mbed_official 52:a51c77007319 1380 {
mbed_official 52:a51c77007319 1381 if((FLASH->OBR & FLASH_FLAG_OPTERR) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1382 {
mbed_official 52:a51c77007319 1383 bitstatus = SET;
mbed_official 52:a51c77007319 1384 }
mbed_official 52:a51c77007319 1385 else
mbed_official 52:a51c77007319 1386 {
mbed_official 52:a51c77007319 1387 bitstatus = RESET;
mbed_official 52:a51c77007319 1388 }
mbed_official 52:a51c77007319 1389 }
mbed_official 52:a51c77007319 1390 else
mbed_official 52:a51c77007319 1391 {
mbed_official 52:a51c77007319 1392 if((FLASH_FLAG & 0x80000000) != 0x0)
mbed_official 52:a51c77007319 1393 {
mbed_official 52:a51c77007319 1394 if((FLASH->SR2 & FLASH_FLAG) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1395 {
mbed_official 52:a51c77007319 1396 bitstatus = SET;
mbed_official 52:a51c77007319 1397 }
mbed_official 52:a51c77007319 1398 else
mbed_official 52:a51c77007319 1399 {
mbed_official 52:a51c77007319 1400 bitstatus = RESET;
mbed_official 52:a51c77007319 1401 }
mbed_official 52:a51c77007319 1402 }
mbed_official 52:a51c77007319 1403 else
mbed_official 52:a51c77007319 1404 {
mbed_official 52:a51c77007319 1405 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1406 {
mbed_official 52:a51c77007319 1407 bitstatus = SET;
mbed_official 52:a51c77007319 1408 }
mbed_official 52:a51c77007319 1409 else
mbed_official 52:a51c77007319 1410 {
mbed_official 52:a51c77007319 1411 bitstatus = RESET;
mbed_official 52:a51c77007319 1412 }
mbed_official 52:a51c77007319 1413 }
mbed_official 52:a51c77007319 1414 }
mbed_official 52:a51c77007319 1415 #else
mbed_official 52:a51c77007319 1416 /* Check the parameters */
mbed_official 52:a51c77007319 1417 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)) ;
mbed_official 52:a51c77007319 1418 if(FLASH_FLAG == FLASH_FLAG_OPTERR)
mbed_official 52:a51c77007319 1419 {
mbed_official 52:a51c77007319 1420 if((FLASH->OBR & FLASH_FLAG_OPTERR) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1421 {
mbed_official 52:a51c77007319 1422 bitstatus = SET;
mbed_official 52:a51c77007319 1423 }
mbed_official 52:a51c77007319 1424 else
mbed_official 52:a51c77007319 1425 {
mbed_official 52:a51c77007319 1426 bitstatus = RESET;
mbed_official 52:a51c77007319 1427 }
mbed_official 52:a51c77007319 1428 }
mbed_official 52:a51c77007319 1429 else
mbed_official 52:a51c77007319 1430 {
mbed_official 52:a51c77007319 1431 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
mbed_official 52:a51c77007319 1432 {
mbed_official 52:a51c77007319 1433 bitstatus = SET;
mbed_official 52:a51c77007319 1434 }
mbed_official 52:a51c77007319 1435 else
mbed_official 52:a51c77007319 1436 {
mbed_official 52:a51c77007319 1437 bitstatus = RESET;
mbed_official 52:a51c77007319 1438 }
mbed_official 52:a51c77007319 1439 }
mbed_official 52:a51c77007319 1440 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1441
mbed_official 52:a51c77007319 1442 /* Return the new state of FLASH_FLAG (SET or RESET) */
mbed_official 52:a51c77007319 1443 return bitstatus;
mbed_official 52:a51c77007319 1444 }
mbed_official 52:a51c77007319 1445
mbed_official 52:a51c77007319 1446 /**
mbed_official 52:a51c77007319 1447 * @brief Clears the FLASH's pending flags.
mbed_official 52:a51c77007319 1448 * @note This function can be used for all STM32F10x devices.
mbed_official 52:a51c77007319 1449 * - For STM32F10X_XL devices, this function clears Bank1 or Bank2’s pending flags
mbed_official 52:a51c77007319 1450 * - For other devices, it clears Bank1’s pending flags.
mbed_official 52:a51c77007319 1451 * @param FLASH_FLAG: specifies the FLASH flags to clear.
mbed_official 52:a51c77007319 1452 * This parameter can be any combination of the following values:
mbed_official 52:a51c77007319 1453 * @arg FLASH_FLAG_PGERR: FLASH Program error flag
mbed_official 52:a51c77007319 1454 * @arg FLASH_FLAG_WRPRTERR: FLASH Write protected error flag
mbed_official 52:a51c77007319 1455 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
mbed_official 52:a51c77007319 1456 * @retval None
mbed_official 52:a51c77007319 1457 */
mbed_official 52:a51c77007319 1458 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
mbed_official 52:a51c77007319 1459 {
mbed_official 52:a51c77007319 1460 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1461 /* Check the parameters */
mbed_official 52:a51c77007319 1462 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)) ;
mbed_official 52:a51c77007319 1463
mbed_official 52:a51c77007319 1464 if((FLASH_FLAG & 0x80000000) != 0x0)
mbed_official 52:a51c77007319 1465 {
mbed_official 52:a51c77007319 1466 /* Clear the flags */
mbed_official 52:a51c77007319 1467 FLASH->SR2 = FLASH_FLAG;
mbed_official 52:a51c77007319 1468 }
mbed_official 52:a51c77007319 1469 else
mbed_official 52:a51c77007319 1470 {
mbed_official 52:a51c77007319 1471 /* Clear the flags */
mbed_official 52:a51c77007319 1472 FLASH->SR = FLASH_FLAG;
mbed_official 52:a51c77007319 1473 }
mbed_official 52:a51c77007319 1474
mbed_official 52:a51c77007319 1475 #else
mbed_official 52:a51c77007319 1476 /* Check the parameters */
mbed_official 52:a51c77007319 1477 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)) ;
mbed_official 52:a51c77007319 1478
mbed_official 52:a51c77007319 1479 /* Clear the flags */
mbed_official 52:a51c77007319 1480 FLASH->SR = FLASH_FLAG;
mbed_official 52:a51c77007319 1481 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1482 }
mbed_official 52:a51c77007319 1483
mbed_official 52:a51c77007319 1484 /**
mbed_official 52:a51c77007319 1485 * @brief Returns the FLASH Status.
mbed_official 52:a51c77007319 1486 * @note This function can be used for all STM32F10x devices, it is equivalent
mbed_official 52:a51c77007319 1487 * to FLASH_GetBank1Status function.
mbed_official 52:a51c77007319 1488 * @param None
mbed_official 52:a51c77007319 1489 * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1490 * FLASH_ERROR_WRP or FLASH_COMPLETE
mbed_official 52:a51c77007319 1491 */
mbed_official 52:a51c77007319 1492 FLASH_Status FLASH_GetStatus(void)
mbed_official 52:a51c77007319 1493 {
mbed_official 52:a51c77007319 1494 FLASH_Status flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1495
mbed_official 52:a51c77007319 1496 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
mbed_official 52:a51c77007319 1497 {
mbed_official 52:a51c77007319 1498 flashstatus = FLASH_BUSY;
mbed_official 52:a51c77007319 1499 }
mbed_official 52:a51c77007319 1500 else
mbed_official 52:a51c77007319 1501 {
mbed_official 52:a51c77007319 1502 if((FLASH->SR & FLASH_FLAG_PGERR) != 0)
mbed_official 52:a51c77007319 1503 {
mbed_official 52:a51c77007319 1504 flashstatus = FLASH_ERROR_PG;
mbed_official 52:a51c77007319 1505 }
mbed_official 52:a51c77007319 1506 else
mbed_official 52:a51c77007319 1507 {
mbed_official 52:a51c77007319 1508 if((FLASH->SR & FLASH_FLAG_WRPRTERR) != 0 )
mbed_official 52:a51c77007319 1509 {
mbed_official 52:a51c77007319 1510 flashstatus = FLASH_ERROR_WRP;
mbed_official 52:a51c77007319 1511 }
mbed_official 52:a51c77007319 1512 else
mbed_official 52:a51c77007319 1513 {
mbed_official 52:a51c77007319 1514 flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1515 }
mbed_official 52:a51c77007319 1516 }
mbed_official 52:a51c77007319 1517 }
mbed_official 52:a51c77007319 1518 /* Return the Flash Status */
mbed_official 52:a51c77007319 1519 return flashstatus;
mbed_official 52:a51c77007319 1520 }
mbed_official 52:a51c77007319 1521
mbed_official 52:a51c77007319 1522 /**
mbed_official 52:a51c77007319 1523 * @brief Returns the FLASH Bank1 Status.
mbed_official 52:a51c77007319 1524 * @note This function can be used for all STM32F10x devices, it is equivalent
mbed_official 52:a51c77007319 1525 * to FLASH_GetStatus function.
mbed_official 52:a51c77007319 1526 * @param None
mbed_official 52:a51c77007319 1527 * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1528 * FLASH_ERROR_WRP or FLASH_COMPLETE
mbed_official 52:a51c77007319 1529 */
mbed_official 52:a51c77007319 1530 FLASH_Status FLASH_GetBank1Status(void)
mbed_official 52:a51c77007319 1531 {
mbed_official 52:a51c77007319 1532 FLASH_Status flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1533
mbed_official 52:a51c77007319 1534 if((FLASH->SR & FLASH_FLAG_BANK1_BSY) == FLASH_FLAG_BSY)
mbed_official 52:a51c77007319 1535 {
mbed_official 52:a51c77007319 1536 flashstatus = FLASH_BUSY;
mbed_official 52:a51c77007319 1537 }
mbed_official 52:a51c77007319 1538 else
mbed_official 52:a51c77007319 1539 {
mbed_official 52:a51c77007319 1540 if((FLASH->SR & FLASH_FLAG_BANK1_PGERR) != 0)
mbed_official 52:a51c77007319 1541 {
mbed_official 52:a51c77007319 1542 flashstatus = FLASH_ERROR_PG;
mbed_official 52:a51c77007319 1543 }
mbed_official 52:a51c77007319 1544 else
mbed_official 52:a51c77007319 1545 {
mbed_official 52:a51c77007319 1546 if((FLASH->SR & FLASH_FLAG_BANK1_WRPRTERR) != 0 )
mbed_official 52:a51c77007319 1547 {
mbed_official 52:a51c77007319 1548 flashstatus = FLASH_ERROR_WRP;
mbed_official 52:a51c77007319 1549 }
mbed_official 52:a51c77007319 1550 else
mbed_official 52:a51c77007319 1551 {
mbed_official 52:a51c77007319 1552 flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1553 }
mbed_official 52:a51c77007319 1554 }
mbed_official 52:a51c77007319 1555 }
mbed_official 52:a51c77007319 1556 /* Return the Flash Status */
mbed_official 52:a51c77007319 1557 return flashstatus;
mbed_official 52:a51c77007319 1558 }
mbed_official 52:a51c77007319 1559
mbed_official 52:a51c77007319 1560 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1561 /**
mbed_official 52:a51c77007319 1562 * @brief Returns the FLASH Bank2 Status.
mbed_official 52:a51c77007319 1563 * @note This function can be used for STM32F10x_XL density devices.
mbed_official 52:a51c77007319 1564 * @param None
mbed_official 52:a51c77007319 1565 * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1566 * FLASH_ERROR_WRP or FLASH_COMPLETE
mbed_official 52:a51c77007319 1567 */
mbed_official 52:a51c77007319 1568 FLASH_Status FLASH_GetBank2Status(void)
mbed_official 52:a51c77007319 1569 {
mbed_official 52:a51c77007319 1570 FLASH_Status flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1571
mbed_official 52:a51c77007319 1572 if((FLASH->SR2 & (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF)) == (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF))
mbed_official 52:a51c77007319 1573 {
mbed_official 52:a51c77007319 1574 flashstatus = FLASH_BUSY;
mbed_official 52:a51c77007319 1575 }
mbed_official 52:a51c77007319 1576 else
mbed_official 52:a51c77007319 1577 {
mbed_official 52:a51c77007319 1578 if((FLASH->SR2 & (FLASH_FLAG_BANK2_PGERR & 0x7FFFFFFF)) != 0)
mbed_official 52:a51c77007319 1579 {
mbed_official 52:a51c77007319 1580 flashstatus = FLASH_ERROR_PG;
mbed_official 52:a51c77007319 1581 }
mbed_official 52:a51c77007319 1582 else
mbed_official 52:a51c77007319 1583 {
mbed_official 52:a51c77007319 1584 if((FLASH->SR2 & (FLASH_FLAG_BANK2_WRPRTERR & 0x7FFFFFFF)) != 0 )
mbed_official 52:a51c77007319 1585 {
mbed_official 52:a51c77007319 1586 flashstatus = FLASH_ERROR_WRP;
mbed_official 52:a51c77007319 1587 }
mbed_official 52:a51c77007319 1588 else
mbed_official 52:a51c77007319 1589 {
mbed_official 52:a51c77007319 1590 flashstatus = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1591 }
mbed_official 52:a51c77007319 1592 }
mbed_official 52:a51c77007319 1593 }
mbed_official 52:a51c77007319 1594 /* Return the Flash Status */
mbed_official 52:a51c77007319 1595 return flashstatus;
mbed_official 52:a51c77007319 1596 }
mbed_official 52:a51c77007319 1597 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1598 /**
mbed_official 52:a51c77007319 1599 * @brief Waits for a Flash operation to complete or a TIMEOUT to occur.
mbed_official 52:a51c77007319 1600 * @note This function can be used for all STM32F10x devices,
mbed_official 52:a51c77007319 1601 * it is equivalent to FLASH_WaitForLastBank1Operation.
mbed_official 52:a51c77007319 1602 * - For STM32F10X_XL devices this function waits for a Bank1 Flash operation
mbed_official 52:a51c77007319 1603 * to complete or a TIMEOUT to occur.
mbed_official 52:a51c77007319 1604 * - For all other devices it waits for a Flash operation to complete
mbed_official 52:a51c77007319 1605 * or a TIMEOUT to occur.
mbed_official 52:a51c77007319 1606 * @param Timeout: FLASH programming Timeout
mbed_official 52:a51c77007319 1607 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1608 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1609 */
mbed_official 52:a51c77007319 1610 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
mbed_official 52:a51c77007319 1611 {
mbed_official 52:a51c77007319 1612 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1613
mbed_official 52:a51c77007319 1614 /* Check for the Flash Status */
mbed_official 52:a51c77007319 1615 status = FLASH_GetBank1Status();
mbed_official 52:a51c77007319 1616 /* Wait for a Flash operation to complete or a TIMEOUT to occur */
mbed_official 52:a51c77007319 1617 while((status == FLASH_BUSY) && (Timeout != 0x00))
mbed_official 52:a51c77007319 1618 {
mbed_official 52:a51c77007319 1619 status = FLASH_GetBank1Status();
mbed_official 52:a51c77007319 1620 Timeout--;
mbed_official 52:a51c77007319 1621 }
mbed_official 52:a51c77007319 1622 if(Timeout == 0x00 )
mbed_official 52:a51c77007319 1623 {
mbed_official 52:a51c77007319 1624 status = FLASH_TIMEOUT;
mbed_official 52:a51c77007319 1625 }
mbed_official 52:a51c77007319 1626 /* Return the operation status */
mbed_official 52:a51c77007319 1627 return status;
mbed_official 52:a51c77007319 1628 }
mbed_official 52:a51c77007319 1629
mbed_official 52:a51c77007319 1630 /**
mbed_official 52:a51c77007319 1631 * @brief Waits for a Flash operation on Bank1 to complete or a TIMEOUT to occur.
mbed_official 52:a51c77007319 1632 * @note This function can be used for all STM32F10x devices,
mbed_official 52:a51c77007319 1633 * it is equivalent to FLASH_WaitForLastOperation.
mbed_official 52:a51c77007319 1634 * @param Timeout: FLASH programming Timeout
mbed_official 52:a51c77007319 1635 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1636 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1637 */
mbed_official 52:a51c77007319 1638 FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout)
mbed_official 52:a51c77007319 1639 {
mbed_official 52:a51c77007319 1640 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1641
mbed_official 52:a51c77007319 1642 /* Check for the Flash Status */
mbed_official 52:a51c77007319 1643 status = FLASH_GetBank1Status();
mbed_official 52:a51c77007319 1644 /* Wait for a Flash operation to complete or a TIMEOUT to occur */
mbed_official 52:a51c77007319 1645 while((status == FLASH_FLAG_BANK1_BSY) && (Timeout != 0x00))
mbed_official 52:a51c77007319 1646 {
mbed_official 52:a51c77007319 1647 status = FLASH_GetBank1Status();
mbed_official 52:a51c77007319 1648 Timeout--;
mbed_official 52:a51c77007319 1649 }
mbed_official 52:a51c77007319 1650 if(Timeout == 0x00 )
mbed_official 52:a51c77007319 1651 {
mbed_official 52:a51c77007319 1652 status = FLASH_TIMEOUT;
mbed_official 52:a51c77007319 1653 }
mbed_official 52:a51c77007319 1654 /* Return the operation status */
mbed_official 52:a51c77007319 1655 return status;
mbed_official 52:a51c77007319 1656 }
mbed_official 52:a51c77007319 1657
mbed_official 52:a51c77007319 1658 #ifdef STM32F10X_XL
mbed_official 52:a51c77007319 1659 /**
mbed_official 52:a51c77007319 1660 * @brief Waits for a Flash operation on Bank2 to complete or a TIMEOUT to occur.
mbed_official 52:a51c77007319 1661 * @note This function can be used only for STM32F10x_XL density devices.
mbed_official 52:a51c77007319 1662 * @param Timeout: FLASH programming Timeout
mbed_official 52:a51c77007319 1663 * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
mbed_official 52:a51c77007319 1664 * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
mbed_official 52:a51c77007319 1665 */
mbed_official 52:a51c77007319 1666 FLASH_Status FLASH_WaitForLastBank2Operation(uint32_t Timeout)
mbed_official 52:a51c77007319 1667 {
mbed_official 52:a51c77007319 1668 FLASH_Status status = FLASH_COMPLETE;
mbed_official 52:a51c77007319 1669
mbed_official 52:a51c77007319 1670 /* Check for the Flash Status */
mbed_official 52:a51c77007319 1671 status = FLASH_GetBank2Status();
mbed_official 52:a51c77007319 1672 /* Wait for a Flash operation to complete or a TIMEOUT to occur */
mbed_official 52:a51c77007319 1673 while((status == (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF)) && (Timeout != 0x00))
mbed_official 52:a51c77007319 1674 {
mbed_official 52:a51c77007319 1675 status = FLASH_GetBank2Status();
mbed_official 52:a51c77007319 1676 Timeout--;
mbed_official 52:a51c77007319 1677 }
mbed_official 52:a51c77007319 1678 if(Timeout == 0x00 )
mbed_official 52:a51c77007319 1679 {
mbed_official 52:a51c77007319 1680 status = FLASH_TIMEOUT;
mbed_official 52:a51c77007319 1681 }
mbed_official 52:a51c77007319 1682 /* Return the operation status */
mbed_official 52:a51c77007319 1683 return status;
mbed_official 52:a51c77007319 1684 }
mbed_official 52:a51c77007319 1685 #endif /* STM32F10X_XL */
mbed_official 52:a51c77007319 1686
mbed_official 52:a51c77007319 1687 /**
mbed_official 52:a51c77007319 1688 * @}
mbed_official 52:a51c77007319 1689 */
mbed_official 52:a51c77007319 1690
mbed_official 52:a51c77007319 1691 /**
mbed_official 52:a51c77007319 1692 * @}
mbed_official 52:a51c77007319 1693 */
mbed_official 52:a51c77007319 1694
mbed_official 52:a51c77007319 1695 /**
mbed_official 52:a51c77007319 1696 * @}
mbed_official 52:a51c77007319 1697 */
mbed_official 52:a51c77007319 1698
mbed_official 52:a51c77007319 1699 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/