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