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