mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_flash.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 155:8435094ec241
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 155:8435094ec241 | 1 | /** |
mbed_official | 155:8435094ec241 | 2 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 3 | * @file stm32f30x_flash.c |
mbed_official | 155:8435094ec241 | 4 | * @author MCD Application Team |
mbed_official | 155:8435094ec241 | 5 | * @version V1.1.0 |
mbed_official | 155:8435094ec241 | 6 | * @date 27-February-2014 |
mbed_official | 155:8435094ec241 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 155:8435094ec241 | 8 | * functionalities of the FLASH peripheral: |
mbed_official | 155:8435094ec241 | 9 | * + FLASH Interface configuration |
mbed_official | 155:8435094ec241 | 10 | * + FLASH Memory Programming |
mbed_official | 155:8435094ec241 | 11 | * + Option Bytes Programming |
mbed_official | 155:8435094ec241 | 12 | * + Interrupts and flags management |
mbed_official | 155:8435094ec241 | 13 | * |
mbed_official | 155:8435094ec241 | 14 | @verbatim |
mbed_official | 155:8435094ec241 | 15 | |
mbed_official | 155:8435094ec241 | 16 | =============================================================================== |
mbed_official | 155:8435094ec241 | 17 | ##### How to use this driver ##### |
mbed_official | 155:8435094ec241 | 18 | =============================================================================== |
mbed_official | 155:8435094ec241 | 19 | [..] This driver provides functions to configure and program the FLASH |
mbed_official | 155:8435094ec241 | 20 | memory of all STM32F30x devices. These functions are split in 4 groups: |
mbed_official | 155:8435094ec241 | 21 | (#) FLASH Interface configuration functions: this group includes the |
mbed_official | 155:8435094ec241 | 22 | management of following features: |
mbed_official | 155:8435094ec241 | 23 | (++) Set the latency. |
mbed_official | 155:8435094ec241 | 24 | (++) Enable/Disable the Half Cycle Access. |
mbed_official | 155:8435094ec241 | 25 | (++) Enable/Disable the prefetch buffer. |
mbed_official | 155:8435094ec241 | 26 | (#) FLASH Memory Programming functions: this group includes all needed |
mbed_official | 155:8435094ec241 | 27 | functions to erase and program the main memory: |
mbed_official | 155:8435094ec241 | 28 | (++) Lock and Unlock the FLASH interface. |
mbed_official | 155:8435094ec241 | 29 | (++) Erase function: Erase page, erase all pages. |
mbed_official | 155:8435094ec241 | 30 | (++) Program functions: Half Word and Word write. |
mbed_official | 155:8435094ec241 | 31 | (#) FLASH Option Bytes Programming functions: this group includes all |
mbed_official | 155:8435094ec241 | 32 | needed functions to manage the Option Bytes: |
mbed_official | 155:8435094ec241 | 33 | (++) Lock and Unlock the Flash Option bytes. |
mbed_official | 155:8435094ec241 | 34 | (++) Launch the Option Bytes loader |
mbed_official | 155:8435094ec241 | 35 | (++) Erase the Option Bytes |
mbed_official | 155:8435094ec241 | 36 | (++) Set/Reset the write protection |
mbed_official | 155:8435094ec241 | 37 | (++) Set the Read protection Level |
mbed_official | 155:8435094ec241 | 38 | (++) Program the user option Bytes |
mbed_official | 155:8435094ec241 | 39 | (++) Set/Reset the BOOT1 bit |
mbed_official | 155:8435094ec241 | 40 | (++) Enable/Disable the VDDA Analog Monitoring |
mbed_official | 155:8435094ec241 | 41 | (++) Enable/Disable the SRAM parity |
mbed_official | 155:8435094ec241 | 42 | (++) Get the user option bytes |
mbed_official | 155:8435094ec241 | 43 | (++) Get the Write protection |
mbed_official | 155:8435094ec241 | 44 | (++) Get the read protection status |
mbed_official | 155:8435094ec241 | 45 | (#) FLASH Interrupts and flags management functions: this group includes |
mbed_official | 155:8435094ec241 | 46 | all needed functions to: |
mbed_official | 155:8435094ec241 | 47 | (++) Enable/Disable the FLASH interrupt sources. |
mbed_official | 155:8435094ec241 | 48 | (++) Get flags status. |
mbed_official | 155:8435094ec241 | 49 | (++) Clear flags. |
mbed_official | 155:8435094ec241 | 50 | (++) Get FLASH operation status. |
mbed_official | 155:8435094ec241 | 51 | (++) Wait for last FLASH operation. |
mbed_official | 155:8435094ec241 | 52 | |
mbed_official | 155:8435094ec241 | 53 | @endverbatim |
mbed_official | 155:8435094ec241 | 54 | |
mbed_official | 155:8435094ec241 | 55 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 56 | * @attention |
mbed_official | 155:8435094ec241 | 57 | * |
mbed_official | 155:8435094ec241 | 58 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 155:8435094ec241 | 59 | * |
mbed_official | 155:8435094ec241 | 60 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 155:8435094ec241 | 61 | * are permitted provided that the following conditions are met: |
mbed_official | 155:8435094ec241 | 62 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 155:8435094ec241 | 63 | * this list of conditions and the following disclaimer. |
mbed_official | 155:8435094ec241 | 64 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 155:8435094ec241 | 65 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 155:8435094ec241 | 66 | * and/or other materials provided with the distribution. |
mbed_official | 155:8435094ec241 | 67 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 155:8435094ec241 | 68 | * may be used to endorse or promote products derived from this software |
mbed_official | 155:8435094ec241 | 69 | * without specific prior written permission. |
mbed_official | 155:8435094ec241 | 70 | * |
mbed_official | 155:8435094ec241 | 71 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 155:8435094ec241 | 72 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 155:8435094ec241 | 73 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 155:8435094ec241 | 74 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 155:8435094ec241 | 75 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 155:8435094ec241 | 76 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 155:8435094ec241 | 77 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 155:8435094ec241 | 78 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 155:8435094ec241 | 79 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 155:8435094ec241 | 80 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 155:8435094ec241 | 81 | * |
mbed_official | 155:8435094ec241 | 82 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 83 | */ |
mbed_official | 155:8435094ec241 | 84 | |
mbed_official | 155:8435094ec241 | 85 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 86 | #include "stm32f30x_flash.h" |
mbed_official | 155:8435094ec241 | 87 | |
mbed_official | 155:8435094ec241 | 88 | /** @addtogroup STM32F30x_StdPeriph_Driver |
mbed_official | 155:8435094ec241 | 89 | * @{ |
mbed_official | 155:8435094ec241 | 90 | */ |
mbed_official | 155:8435094ec241 | 91 | |
mbed_official | 155:8435094ec241 | 92 | /** @defgroup FLASH |
mbed_official | 155:8435094ec241 | 93 | * @brief FLASH driver modules |
mbed_official | 155:8435094ec241 | 94 | * @{ |
mbed_official | 155:8435094ec241 | 95 | */ |
mbed_official | 155:8435094ec241 | 96 | |
mbed_official | 155:8435094ec241 | 97 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 98 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 99 | |
mbed_official | 155:8435094ec241 | 100 | /* FLASH Mask */ |
mbed_official | 155:8435094ec241 | 101 | #define RDPRT_MASK ((uint32_t)0x00000002) |
mbed_official | 155:8435094ec241 | 102 | #define WRP01_MASK ((uint32_t)0x0000FFFF) |
mbed_official | 155:8435094ec241 | 103 | #define WRP23_MASK ((uint32_t)0xFFFF0000) |
mbed_official | 155:8435094ec241 | 104 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 105 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 106 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 107 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 108 | |
mbed_official | 155:8435094ec241 | 109 | /** @defgroup FLASH_Private_Functions |
mbed_official | 155:8435094ec241 | 110 | * @{ |
mbed_official | 155:8435094ec241 | 111 | */ |
mbed_official | 155:8435094ec241 | 112 | |
mbed_official | 155:8435094ec241 | 113 | /** @defgroup FLASH_Group1 FLASH Interface configuration functions |
mbed_official | 155:8435094ec241 | 114 | * @brief FLASH Interface configuration functions |
mbed_official | 155:8435094ec241 | 115 | * |
mbed_official | 155:8435094ec241 | 116 | |
mbed_official | 155:8435094ec241 | 117 | @verbatim |
mbed_official | 155:8435094ec241 | 118 | =============================================================================== |
mbed_official | 155:8435094ec241 | 119 | ##### FLASH Interface configuration functions ##### |
mbed_official | 155:8435094ec241 | 120 | =============================================================================== |
mbed_official | 155:8435094ec241 | 121 | [..] This group includes the following functions: |
mbed_official | 155:8435094ec241 | 122 | (+) void FLASH_SetLatency(uint32_t FLASH_Latency); |
mbed_official | 155:8435094ec241 | 123 | (+) void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess); |
mbed_official | 155:8435094ec241 | 124 | (+) void FLASH_PrefetchBufferCmd(FunctionalState NewState); |
mbed_official | 155:8435094ec241 | 125 | [..] The unlock sequence is not needed for these functions. |
mbed_official | 155:8435094ec241 | 126 | |
mbed_official | 155:8435094ec241 | 127 | @endverbatim |
mbed_official | 155:8435094ec241 | 128 | * @{ |
mbed_official | 155:8435094ec241 | 129 | */ |
mbed_official | 155:8435094ec241 | 130 | |
mbed_official | 155:8435094ec241 | 131 | /** |
mbed_official | 155:8435094ec241 | 132 | * @brief Sets the code latency value. |
mbed_official | 155:8435094ec241 | 133 | * @param FLASH_Latency: specifies the FLASH Latency value. |
mbed_official | 155:8435094ec241 | 134 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 135 | * @arg FLASH_Latency_0: FLASH Zero Latency cycle |
mbed_official | 155:8435094ec241 | 136 | * @arg FLASH_Latency_1: FLASH One Latency cycle |
mbed_official | 155:8435094ec241 | 137 | * @arg FLASH_Latency_2: FLASH Two Latency cycles |
mbed_official | 155:8435094ec241 | 138 | * @retval None |
mbed_official | 155:8435094ec241 | 139 | */ |
mbed_official | 155:8435094ec241 | 140 | void FLASH_SetLatency(uint32_t FLASH_Latency) |
mbed_official | 155:8435094ec241 | 141 | { |
mbed_official | 155:8435094ec241 | 142 | uint32_t tmpreg = 0; |
mbed_official | 155:8435094ec241 | 143 | |
mbed_official | 155:8435094ec241 | 144 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 145 | assert_param(IS_FLASH_LATENCY(FLASH_Latency)); |
mbed_official | 155:8435094ec241 | 146 | |
mbed_official | 155:8435094ec241 | 147 | /* Read the ACR register */ |
mbed_official | 155:8435094ec241 | 148 | tmpreg = FLASH->ACR; |
mbed_official | 155:8435094ec241 | 149 | |
mbed_official | 155:8435094ec241 | 150 | /* Sets the Latency value */ |
mbed_official | 155:8435094ec241 | 151 | tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY)); |
mbed_official | 155:8435094ec241 | 152 | tmpreg |= FLASH_Latency; |
mbed_official | 155:8435094ec241 | 153 | |
mbed_official | 155:8435094ec241 | 154 | /* Write the ACR register */ |
mbed_official | 155:8435094ec241 | 155 | FLASH->ACR = tmpreg; |
mbed_official | 155:8435094ec241 | 156 | } |
mbed_official | 155:8435094ec241 | 157 | |
mbed_official | 155:8435094ec241 | 158 | /** |
mbed_official | 155:8435094ec241 | 159 | * @brief Enables or disables the Half cycle flash access. |
mbed_official | 155:8435094ec241 | 160 | * @param FLASH_HalfCycleAccess: specifies the FLASH Half cycle Access mode. |
mbed_official | 155:8435094ec241 | 161 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 162 | * @arg FLASH_HalfCycleAccess_Enable: FLASH Half Cycle Enable |
mbed_official | 155:8435094ec241 | 163 | * @arg FLASH_HalfCycleAccess_Disable: FLASH Half Cycle Disable |
mbed_official | 155:8435094ec241 | 164 | * @retval None |
mbed_official | 155:8435094ec241 | 165 | */ |
mbed_official | 155:8435094ec241 | 166 | void FLASH_HalfCycleAccessCmd(FunctionalState NewState) |
mbed_official | 155:8435094ec241 | 167 | { |
mbed_official | 155:8435094ec241 | 168 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 169 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 155:8435094ec241 | 170 | |
mbed_official | 155:8435094ec241 | 171 | if(NewState != DISABLE) |
mbed_official | 155:8435094ec241 | 172 | { |
mbed_official | 155:8435094ec241 | 173 | FLASH->ACR |= FLASH_ACR_HLFCYA; |
mbed_official | 155:8435094ec241 | 174 | } |
mbed_official | 155:8435094ec241 | 175 | else |
mbed_official | 155:8435094ec241 | 176 | { |
mbed_official | 155:8435094ec241 | 177 | FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_HLFCYA)); |
mbed_official | 155:8435094ec241 | 178 | } |
mbed_official | 155:8435094ec241 | 179 | } |
mbed_official | 155:8435094ec241 | 180 | |
mbed_official | 155:8435094ec241 | 181 | /** |
mbed_official | 155:8435094ec241 | 182 | * @brief Enables or disables the Prefetch Buffer. |
mbed_official | 155:8435094ec241 | 183 | * @param NewState: new state of the Prefetch Buffer. |
mbed_official | 155:8435094ec241 | 184 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 155:8435094ec241 | 185 | * @retval None |
mbed_official | 155:8435094ec241 | 186 | */ |
mbed_official | 155:8435094ec241 | 187 | void FLASH_PrefetchBufferCmd(FunctionalState NewState) |
mbed_official | 155:8435094ec241 | 188 | { |
mbed_official | 155:8435094ec241 | 189 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 190 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 155:8435094ec241 | 191 | |
mbed_official | 155:8435094ec241 | 192 | if(NewState != DISABLE) |
mbed_official | 155:8435094ec241 | 193 | { |
mbed_official | 155:8435094ec241 | 194 | FLASH->ACR |= FLASH_ACR_PRFTBE; |
mbed_official | 155:8435094ec241 | 195 | } |
mbed_official | 155:8435094ec241 | 196 | else |
mbed_official | 155:8435094ec241 | 197 | { |
mbed_official | 155:8435094ec241 | 198 | FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTBE)); |
mbed_official | 155:8435094ec241 | 199 | } |
mbed_official | 155:8435094ec241 | 200 | } |
mbed_official | 155:8435094ec241 | 201 | |
mbed_official | 155:8435094ec241 | 202 | /** |
mbed_official | 155:8435094ec241 | 203 | * @} |
mbed_official | 155:8435094ec241 | 204 | */ |
mbed_official | 155:8435094ec241 | 205 | |
mbed_official | 155:8435094ec241 | 206 | /** @defgroup FLASH_Group2 FLASH Memory Programming functions |
mbed_official | 155:8435094ec241 | 207 | * @brief FLASH Memory Programming functions |
mbed_official | 155:8435094ec241 | 208 | * |
mbed_official | 155:8435094ec241 | 209 | @verbatim |
mbed_official | 155:8435094ec241 | 210 | =============================================================================== |
mbed_official | 155:8435094ec241 | 211 | ##### FLASH Memory Programming functions ##### |
mbed_official | 155:8435094ec241 | 212 | =============================================================================== |
mbed_official | 155:8435094ec241 | 213 | [..] This group includes the following functions: |
mbed_official | 155:8435094ec241 | 214 | (+) void FLASH_Unlock(void); |
mbed_official | 155:8435094ec241 | 215 | (+) void FLASH_Lock(void); |
mbed_official | 155:8435094ec241 | 216 | (+) FLASH_Status FLASH_ErasePage(uint32_t Page_Address); |
mbed_official | 155:8435094ec241 | 217 | (+) FLASH_Status FLASH_EraseAllPages(void); |
mbed_official | 155:8435094ec241 | 218 | (+) FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 155:8435094ec241 | 219 | (+) FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 155:8435094ec241 | 220 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 155:8435094ec241 | 221 | (#) Call the FLASH_Unlock() function to enable the FLASH control register |
mbed_official | 155:8435094ec241 | 222 | program memory access. |
mbed_official | 155:8435094ec241 | 223 | (#) Call the desired function to erase page or program data. |
mbed_official | 155:8435094ec241 | 224 | (#) Call the FLASH_Lock() function to disable the FLASH control register |
mbed_official | 155:8435094ec241 | 225 | access (recommended to protect the FLASH memory against possible |
mbed_official | 155:8435094ec241 | 226 | unwanted operation). |
mbed_official | 155:8435094ec241 | 227 | |
mbed_official | 155:8435094ec241 | 228 | @endverbatim |
mbed_official | 155:8435094ec241 | 229 | * @{ |
mbed_official | 155:8435094ec241 | 230 | */ |
mbed_official | 155:8435094ec241 | 231 | |
mbed_official | 155:8435094ec241 | 232 | /** |
mbed_official | 155:8435094ec241 | 233 | * @brief Unlocks the FLASH control register access |
mbed_official | 155:8435094ec241 | 234 | * @param None |
mbed_official | 155:8435094ec241 | 235 | * @retval None |
mbed_official | 155:8435094ec241 | 236 | */ |
mbed_official | 155:8435094ec241 | 237 | void FLASH_Unlock(void) |
mbed_official | 155:8435094ec241 | 238 | { |
mbed_official | 155:8435094ec241 | 239 | if((FLASH->CR & FLASH_CR_LOCK) != RESET) |
mbed_official | 155:8435094ec241 | 240 | { |
mbed_official | 155:8435094ec241 | 241 | /* Authorize the FLASH Registers access */ |
mbed_official | 155:8435094ec241 | 242 | FLASH->KEYR = FLASH_KEY1; |
mbed_official | 155:8435094ec241 | 243 | FLASH->KEYR = FLASH_KEY2; |
mbed_official | 155:8435094ec241 | 244 | } |
mbed_official | 155:8435094ec241 | 245 | } |
mbed_official | 155:8435094ec241 | 246 | |
mbed_official | 155:8435094ec241 | 247 | /** |
mbed_official | 155:8435094ec241 | 248 | * @brief Locks the FLASH control register access |
mbed_official | 155:8435094ec241 | 249 | * @param None |
mbed_official | 155:8435094ec241 | 250 | * @retval None |
mbed_official | 155:8435094ec241 | 251 | */ |
mbed_official | 155:8435094ec241 | 252 | void FLASH_Lock(void) |
mbed_official | 155:8435094ec241 | 253 | { |
mbed_official | 155:8435094ec241 | 254 | /* Set the LOCK Bit to lock the FLASH Registers access */ |
mbed_official | 155:8435094ec241 | 255 | FLASH->CR |= FLASH_CR_LOCK; |
mbed_official | 155:8435094ec241 | 256 | } |
mbed_official | 155:8435094ec241 | 257 | |
mbed_official | 155:8435094ec241 | 258 | /** |
mbed_official | 155:8435094ec241 | 259 | * @brief Erases a specified page in program memory. |
mbed_official | 155:8435094ec241 | 260 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 155:8435094ec241 | 261 | * must be called before. |
mbed_official | 155:8435094ec241 | 262 | * @note Call the FLASH_Lock() to disable the flash memory access |
mbed_official | 155:8435094ec241 | 263 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 264 | * @param Page_Address: The page address in program memory to be erased. |
mbed_official | 155:8435094ec241 | 265 | * @note A Page is erased in the Program memory only if the address to load |
mbed_official | 155:8435094ec241 | 266 | * is the start address of a page (multiple of 1024 bytes). |
mbed_official | 155:8435094ec241 | 267 | * @retval FLASH Status: The returned value can be: |
mbed_official | 155:8435094ec241 | 268 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 269 | */ |
mbed_official | 155:8435094ec241 | 270 | FLASH_Status FLASH_ErasePage(uint32_t Page_Address) |
mbed_official | 155:8435094ec241 | 271 | { |
mbed_official | 155:8435094ec241 | 272 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 273 | |
mbed_official | 155:8435094ec241 | 274 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 275 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address)); |
mbed_official | 155:8435094ec241 | 276 | |
mbed_official | 155:8435094ec241 | 277 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 278 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 279 | |
mbed_official | 155:8435094ec241 | 280 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 281 | { |
mbed_official | 155:8435094ec241 | 282 | /* If the previous operation is completed, proceed to erase the page */ |
mbed_official | 155:8435094ec241 | 283 | FLASH->CR |= FLASH_CR_PER; |
mbed_official | 155:8435094ec241 | 284 | FLASH->AR = Page_Address; |
mbed_official | 155:8435094ec241 | 285 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 155:8435094ec241 | 286 | |
mbed_official | 155:8435094ec241 | 287 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 288 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 289 | |
mbed_official | 155:8435094ec241 | 290 | /* Disable the PER Bit */ |
mbed_official | 155:8435094ec241 | 291 | FLASH->CR &= ~FLASH_CR_PER; |
mbed_official | 155:8435094ec241 | 292 | } |
mbed_official | 155:8435094ec241 | 293 | |
mbed_official | 155:8435094ec241 | 294 | /* Return the Erase Status */ |
mbed_official | 155:8435094ec241 | 295 | return status; |
mbed_official | 155:8435094ec241 | 296 | } |
mbed_official | 155:8435094ec241 | 297 | |
mbed_official | 155:8435094ec241 | 298 | /** |
mbed_official | 155:8435094ec241 | 299 | * @brief Erases all FLASH pages. |
mbed_official | 155:8435094ec241 | 300 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 155:8435094ec241 | 301 | * must be called before. |
mbed_official | 155:8435094ec241 | 302 | * all the FLASH_Lock() to disable the flash memory access |
mbed_official | 155:8435094ec241 | 303 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 304 | * @param None |
mbed_official | 155:8435094ec241 | 305 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 306 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 307 | */ |
mbed_official | 155:8435094ec241 | 308 | FLASH_Status FLASH_EraseAllPages(void) |
mbed_official | 155:8435094ec241 | 309 | { |
mbed_official | 155:8435094ec241 | 310 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 311 | |
mbed_official | 155:8435094ec241 | 312 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 313 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 314 | |
mbed_official | 155:8435094ec241 | 315 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 316 | { |
mbed_official | 155:8435094ec241 | 317 | /* if the previous operation is completed, proceed to erase all pages */ |
mbed_official | 155:8435094ec241 | 318 | FLASH->CR |= FLASH_CR_MER; |
mbed_official | 155:8435094ec241 | 319 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 155:8435094ec241 | 320 | |
mbed_official | 155:8435094ec241 | 321 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 322 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 323 | |
mbed_official | 155:8435094ec241 | 324 | /* Disable the MER Bit */ |
mbed_official | 155:8435094ec241 | 325 | FLASH->CR &= ~FLASH_CR_MER; |
mbed_official | 155:8435094ec241 | 326 | } |
mbed_official | 155:8435094ec241 | 327 | |
mbed_official | 155:8435094ec241 | 328 | /* Return the Erase Status */ |
mbed_official | 155:8435094ec241 | 329 | return status; |
mbed_official | 155:8435094ec241 | 330 | } |
mbed_official | 155:8435094ec241 | 331 | |
mbed_official | 155:8435094ec241 | 332 | /** |
mbed_official | 155:8435094ec241 | 333 | * @brief Programs a word at a specified address. |
mbed_official | 155:8435094ec241 | 334 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 155:8435094ec241 | 335 | * must be called before. |
mbed_official | 155:8435094ec241 | 336 | * Call the FLASH_Lock() to disable the flash memory access |
mbed_official | 155:8435094ec241 | 337 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 338 | * @param Address: specifies the address to be programmed. |
mbed_official | 155:8435094ec241 | 339 | * @param Data: specifies the data to be programmed. |
mbed_official | 155:8435094ec241 | 340 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 341 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 342 | */ |
mbed_official | 155:8435094ec241 | 343 | FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 155:8435094ec241 | 344 | { |
mbed_official | 155:8435094ec241 | 345 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 346 | __IO uint32_t tmp = 0; |
mbed_official | 155:8435094ec241 | 347 | |
mbed_official | 155:8435094ec241 | 348 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 349 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
mbed_official | 155:8435094ec241 | 350 | |
mbed_official | 155:8435094ec241 | 351 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 352 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 353 | |
mbed_official | 155:8435094ec241 | 354 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 355 | { |
mbed_official | 155:8435094ec241 | 356 | /* If the previous operation is completed, proceed to program the new first |
mbed_official | 155:8435094ec241 | 357 | half word */ |
mbed_official | 155:8435094ec241 | 358 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 155:8435094ec241 | 359 | |
mbed_official | 155:8435094ec241 | 360 | *(__IO uint16_t*)Address = (uint16_t)Data; |
mbed_official | 155:8435094ec241 | 361 | |
mbed_official | 155:8435094ec241 | 362 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 363 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 364 | |
mbed_official | 155:8435094ec241 | 365 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 366 | { |
mbed_official | 155:8435094ec241 | 367 | /* If the previous operation is completed, proceed to program the new second |
mbed_official | 155:8435094ec241 | 368 | half word */ |
mbed_official | 155:8435094ec241 | 369 | tmp = Address + 2; |
mbed_official | 155:8435094ec241 | 370 | |
mbed_official | 155:8435094ec241 | 371 | *(__IO uint16_t*) tmp = Data >> 16; |
mbed_official | 155:8435094ec241 | 372 | |
mbed_official | 155:8435094ec241 | 373 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 374 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 375 | |
mbed_official | 155:8435094ec241 | 376 | /* Disable the PG Bit */ |
mbed_official | 155:8435094ec241 | 377 | FLASH->CR &= ~FLASH_CR_PG; |
mbed_official | 155:8435094ec241 | 378 | } |
mbed_official | 155:8435094ec241 | 379 | else |
mbed_official | 155:8435094ec241 | 380 | { |
mbed_official | 155:8435094ec241 | 381 | /* Disable the PG Bit */ |
mbed_official | 155:8435094ec241 | 382 | FLASH->CR &= ~FLASH_CR_PG; |
mbed_official | 155:8435094ec241 | 383 | } |
mbed_official | 155:8435094ec241 | 384 | } |
mbed_official | 155:8435094ec241 | 385 | |
mbed_official | 155:8435094ec241 | 386 | /* Return the Program Status */ |
mbed_official | 155:8435094ec241 | 387 | return status; |
mbed_official | 155:8435094ec241 | 388 | } |
mbed_official | 155:8435094ec241 | 389 | |
mbed_official | 155:8435094ec241 | 390 | /** |
mbed_official | 155:8435094ec241 | 391 | * @brief Programs a half word at a specified address. |
mbed_official | 155:8435094ec241 | 392 | * @note To correctly run this function, the FLASH_Unlock() function |
mbed_official | 155:8435094ec241 | 393 | * must be called before. |
mbed_official | 155:8435094ec241 | 394 | * Call the FLASH_Lock() to disable the flash memory access |
mbed_official | 155:8435094ec241 | 395 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 396 | * @param Address: specifies the address to be programmed. |
mbed_official | 155:8435094ec241 | 397 | * @param Data: specifies the data to be programmed. |
mbed_official | 155:8435094ec241 | 398 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 399 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 400 | */ |
mbed_official | 155:8435094ec241 | 401 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 155:8435094ec241 | 402 | { |
mbed_official | 155:8435094ec241 | 403 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 404 | |
mbed_official | 155:8435094ec241 | 405 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 406 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
mbed_official | 155:8435094ec241 | 407 | |
mbed_official | 155:8435094ec241 | 408 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 409 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 410 | |
mbed_official | 155:8435094ec241 | 411 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 412 | { |
mbed_official | 155:8435094ec241 | 413 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 155:8435094ec241 | 414 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 155:8435094ec241 | 415 | |
mbed_official | 155:8435094ec241 | 416 | *(__IO uint16_t*)Address = Data; |
mbed_official | 155:8435094ec241 | 417 | |
mbed_official | 155:8435094ec241 | 418 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 419 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 420 | |
mbed_official | 155:8435094ec241 | 421 | /* Disable the PG Bit */ |
mbed_official | 155:8435094ec241 | 422 | FLASH->CR &= ~FLASH_CR_PG; |
mbed_official | 155:8435094ec241 | 423 | } |
mbed_official | 155:8435094ec241 | 424 | |
mbed_official | 155:8435094ec241 | 425 | /* Return the Program Status */ |
mbed_official | 155:8435094ec241 | 426 | return status; |
mbed_official | 155:8435094ec241 | 427 | } |
mbed_official | 155:8435094ec241 | 428 | |
mbed_official | 155:8435094ec241 | 429 | /** |
mbed_official | 155:8435094ec241 | 430 | * @} |
mbed_official | 155:8435094ec241 | 431 | */ |
mbed_official | 155:8435094ec241 | 432 | |
mbed_official | 155:8435094ec241 | 433 | /** @defgroup FLASH_Group3 Option Bytes Programming functions |
mbed_official | 155:8435094ec241 | 434 | * @brief Option Bytes Programming functions |
mbed_official | 155:8435094ec241 | 435 | * |
mbed_official | 155:8435094ec241 | 436 | @verbatim |
mbed_official | 155:8435094ec241 | 437 | =============================================================================== |
mbed_official | 155:8435094ec241 | 438 | ##### Option Bytes Programming functions ##### |
mbed_official | 155:8435094ec241 | 439 | =============================================================================== |
mbed_official | 155:8435094ec241 | 440 | [..] This group includes the following functions: |
mbed_official | 155:8435094ec241 | 441 | (+) void FLASH_OB_Unlock(void); |
mbed_official | 155:8435094ec241 | 442 | (+) void FLASH_OB_Lock(void); |
mbed_official | 155:8435094ec241 | 443 | (+) void FLASH_OB_Erase(void); |
mbed_official | 155:8435094ec241 | 444 | (+) FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 155:8435094ec241 | 445 | (+) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP); |
mbed_official | 155:8435094ec241 | 446 | (+) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); |
mbed_official | 155:8435094ec241 | 447 | (+) FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1); |
mbed_official | 155:8435094ec241 | 448 | (+) FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG); |
mbed_official | 155:8435094ec241 | 449 | (+) FLASH_Status FLASH_OB_SRMParityConfig(uint8_t OB_SRAM_Parity); |
mbed_official | 155:8435094ec241 | 450 | (+) FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER); |
mbed_official | 155:8435094ec241 | 451 | (+) FLASH_Status FLASH_OB_Launch(void); |
mbed_official | 155:8435094ec241 | 452 | (+) uint32_t FLASH_OB_GetUser(void); |
mbed_official | 155:8435094ec241 | 453 | (+) uint8_t FLASH_OB_GetWRP(void); |
mbed_official | 155:8435094ec241 | 454 | (+) uint8_t FLASH_OB_GetRDP(void); |
mbed_official | 155:8435094ec241 | 455 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 155:8435094ec241 | 456 | (#) Call the FLASH_OB_Unlock() function to enable the FLASH option control |
mbed_official | 155:8435094ec241 | 457 | register access. |
mbed_official | 155:8435094ec241 | 458 | (#) Call one or several functions to program the desired Option Bytes: |
mbed_official | 155:8435094ec241 | 459 | (++) void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 155:8435094ec241 | 460 | => to Enable/Disable the desired sector write protection. |
mbed_official | 155:8435094ec241 | 461 | (++) FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the |
mbed_official | 155:8435094ec241 | 462 | desired read Protection Level. |
mbed_official | 155:8435094ec241 | 463 | (++) FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); |
mbed_official | 155:8435094ec241 | 464 | => to configure the user Option Bytes. |
mbed_official | 155:8435094ec241 | 465 | (++) FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1); |
mbed_official | 155:8435094ec241 | 466 | => to set the boot1 mode |
mbed_official | 155:8435094ec241 | 467 | (++) FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG); |
mbed_official | 155:8435094ec241 | 468 | => to Enable/Disable the VDDA monotoring. |
mbed_official | 155:8435094ec241 | 469 | (++) FLASH_Status FLASH_OB_SRMParityConfig(uint8_t OB_SRAM_Parity); |
mbed_official | 155:8435094ec241 | 470 | => to Enable/Disable the SRAM Parity check. |
mbed_official | 155:8435094ec241 | 471 | (++) FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER); |
mbed_official | 155:8435094ec241 | 472 | => to write all user option bytes: OB_IWDG, OB_STOP, OB_STDBY, |
mbed_official | 155:8435094ec241 | 473 | OB_BOOT1, OB_VDDA_ANALOG and OB_VDD_SD12. |
mbed_official | 155:8435094ec241 | 474 | (#) Once all needed Option Bytes to be programmed are correctly written, |
mbed_official | 155:8435094ec241 | 475 | call the FLASH_OB_Launch() function to launch the Option Bytes |
mbed_official | 155:8435094ec241 | 476 | programming process. |
mbed_official | 155:8435094ec241 | 477 | (#@) When changing the IWDG mode from HW to SW or from SW to HW, a system |
mbed_official | 155:8435094ec241 | 478 | reset is needed to make the change effective. |
mbed_official | 155:8435094ec241 | 479 | (#) Call the FLASH_OB_Lock() function to disable the FLASH option control |
mbed_official | 155:8435094ec241 | 480 | register access (recommended to protect the Option Bytes against |
mbed_official | 155:8435094ec241 | 481 | possible unwanted operations). |
mbed_official | 155:8435094ec241 | 482 | |
mbed_official | 155:8435094ec241 | 483 | @endverbatim |
mbed_official | 155:8435094ec241 | 484 | * @{ |
mbed_official | 155:8435094ec241 | 485 | */ |
mbed_official | 155:8435094ec241 | 486 | |
mbed_official | 155:8435094ec241 | 487 | /** |
mbed_official | 155:8435094ec241 | 488 | * @brief Unlocks the option bytes block access. |
mbed_official | 155:8435094ec241 | 489 | * @param None |
mbed_official | 155:8435094ec241 | 490 | * @retval None |
mbed_official | 155:8435094ec241 | 491 | */ |
mbed_official | 155:8435094ec241 | 492 | void FLASH_OB_Unlock(void) |
mbed_official | 155:8435094ec241 | 493 | { |
mbed_official | 155:8435094ec241 | 494 | if((FLASH->CR & FLASH_CR_OPTWRE) == RESET) |
mbed_official | 155:8435094ec241 | 495 | { |
mbed_official | 155:8435094ec241 | 496 | /* Unlocking the option bytes block access */ |
mbed_official | 155:8435094ec241 | 497 | FLASH->OPTKEYR = FLASH_OPTKEY1; |
mbed_official | 155:8435094ec241 | 498 | FLASH->OPTKEYR = FLASH_OPTKEY2; |
mbed_official | 155:8435094ec241 | 499 | } |
mbed_official | 155:8435094ec241 | 500 | } |
mbed_official | 155:8435094ec241 | 501 | |
mbed_official | 155:8435094ec241 | 502 | /** |
mbed_official | 155:8435094ec241 | 503 | * @brief Locks the option bytes block access. |
mbed_official | 155:8435094ec241 | 504 | * @param None |
mbed_official | 155:8435094ec241 | 505 | * @retval None |
mbed_official | 155:8435094ec241 | 506 | */ |
mbed_official | 155:8435094ec241 | 507 | void FLASH_OB_Lock(void) |
mbed_official | 155:8435094ec241 | 508 | { |
mbed_official | 155:8435094ec241 | 509 | /* Set the OPTWREN Bit to lock the option bytes block access */ |
mbed_official | 155:8435094ec241 | 510 | FLASH->CR &= ~FLASH_CR_OPTWRE; |
mbed_official | 155:8435094ec241 | 511 | } |
mbed_official | 155:8435094ec241 | 512 | |
mbed_official | 155:8435094ec241 | 513 | /** |
mbed_official | 155:8435094ec241 | 514 | * @brief Launch the option byte loading. |
mbed_official | 155:8435094ec241 | 515 | * @param None |
mbed_official | 155:8435094ec241 | 516 | * @retval None |
mbed_official | 155:8435094ec241 | 517 | */ |
mbed_official | 155:8435094ec241 | 518 | void FLASH_OB_Launch(void) |
mbed_official | 155:8435094ec241 | 519 | { |
mbed_official | 155:8435094ec241 | 520 | /* Set the OBL_Launch bit to launch the option byte loading */ |
mbed_official | 155:8435094ec241 | 521 | FLASH->CR |= FLASH_CR_OBL_LAUNCH; |
mbed_official | 155:8435094ec241 | 522 | } |
mbed_official | 155:8435094ec241 | 523 | |
mbed_official | 155:8435094ec241 | 524 | /** |
mbed_official | 155:8435094ec241 | 525 | * @brief Erases the FLASH option bytes. |
mbed_official | 155:8435094ec241 | 526 | * @note This functions erases all option bytes except the Read protection (RDP). |
mbed_official | 155:8435094ec241 | 527 | * @param None |
mbed_official | 155:8435094ec241 | 528 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 529 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 530 | */ |
mbed_official | 155:8435094ec241 | 531 | FLASH_Status FLASH_OB_Erase(void) |
mbed_official | 155:8435094ec241 | 532 | { |
mbed_official | 155:8435094ec241 | 533 | uint16_t rdptmp = OB_RDP_Level_0; |
mbed_official | 155:8435094ec241 | 534 | |
mbed_official | 155:8435094ec241 | 535 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 536 | |
mbed_official | 155:8435094ec241 | 537 | /* Get the actual read protection Option Byte value */ |
mbed_official | 155:8435094ec241 | 538 | if(FLASH_OB_GetRDP() != RESET) |
mbed_official | 155:8435094ec241 | 539 | { |
mbed_official | 155:8435094ec241 | 540 | rdptmp = 0x00; |
mbed_official | 155:8435094ec241 | 541 | } |
mbed_official | 155:8435094ec241 | 542 | |
mbed_official | 155:8435094ec241 | 543 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 544 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 545 | |
mbed_official | 155:8435094ec241 | 546 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 547 | { |
mbed_official | 155:8435094ec241 | 548 | /* If the previous operation is completed, proceed to erase the option bytes */ |
mbed_official | 155:8435094ec241 | 549 | FLASH->CR |= FLASH_CR_OPTER; |
mbed_official | 155:8435094ec241 | 550 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 155:8435094ec241 | 551 | |
mbed_official | 155:8435094ec241 | 552 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 553 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 554 | |
mbed_official | 155:8435094ec241 | 555 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 556 | { |
mbed_official | 155:8435094ec241 | 557 | /* If the erase operation is completed, disable the OPTER Bit */ |
mbed_official | 155:8435094ec241 | 558 | FLASH->CR &= ~FLASH_CR_OPTER; |
mbed_official | 155:8435094ec241 | 559 | |
mbed_official | 155:8435094ec241 | 560 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 561 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 562 | |
mbed_official | 155:8435094ec241 | 563 | /* Restore the last read protection Option Byte value */ |
mbed_official | 155:8435094ec241 | 564 | OB->RDP = (uint16_t)rdptmp; |
mbed_official | 155:8435094ec241 | 565 | |
mbed_official | 155:8435094ec241 | 566 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 567 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 568 | |
mbed_official | 155:8435094ec241 | 569 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 570 | { |
mbed_official | 155:8435094ec241 | 571 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 572 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 573 | } |
mbed_official | 155:8435094ec241 | 574 | } |
mbed_official | 155:8435094ec241 | 575 | else |
mbed_official | 155:8435094ec241 | 576 | { |
mbed_official | 155:8435094ec241 | 577 | if (status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 578 | { |
mbed_official | 155:8435094ec241 | 579 | /* Disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 580 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 581 | } |
mbed_official | 155:8435094ec241 | 582 | } |
mbed_official | 155:8435094ec241 | 583 | } |
mbed_official | 155:8435094ec241 | 584 | /* Return the erase status */ |
mbed_official | 155:8435094ec241 | 585 | return status; |
mbed_official | 155:8435094ec241 | 586 | } |
mbed_official | 155:8435094ec241 | 587 | |
mbed_official | 155:8435094ec241 | 588 | /** |
mbed_official | 155:8435094ec241 | 589 | * @brief Write protects the desired pages |
mbed_official | 155:8435094ec241 | 590 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 155:8435094ec241 | 591 | * must be called before. |
mbed_official | 155:8435094ec241 | 592 | * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes |
mbed_official | 155:8435094ec241 | 593 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 594 | * @param OB_WRP: specifies the address of the pages to be write protected. |
mbed_official | 155:8435094ec241 | 595 | * This parameter can be: |
mbed_official | 155:8435094ec241 | 596 | * @arg value between OB_WRP_Pages0to35 and OB_WRP_Pages60to63 |
mbed_official | 155:8435094ec241 | 597 | * @arg OB_WRP_AllPages |
mbed_official | 155:8435094ec241 | 598 | * @retval FLASH Status: The returned value can be: |
mbed_official | 155:8435094ec241 | 599 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 600 | */ |
mbed_official | 155:8435094ec241 | 601 | FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP) |
mbed_official | 155:8435094ec241 | 602 | { |
mbed_official | 155:8435094ec241 | 603 | uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF; |
mbed_official | 155:8435094ec241 | 604 | |
mbed_official | 155:8435094ec241 | 605 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 606 | |
mbed_official | 155:8435094ec241 | 607 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 608 | assert_param(IS_OB_WRP(OB_WRP)); |
mbed_official | 155:8435094ec241 | 609 | |
mbed_official | 155:8435094ec241 | 610 | OB_WRP = (uint32_t)(~OB_WRP); |
mbed_official | 155:8435094ec241 | 611 | WRP0_Data = (uint16_t)(OB_WRP & OB_WRP0_WRP0); |
mbed_official | 155:8435094ec241 | 612 | WRP1_Data = (uint16_t)((OB_WRP & OB_WRP0_nWRP0) >> 8); |
mbed_official | 155:8435094ec241 | 613 | |
mbed_official | 155:8435094ec241 | 614 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 615 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 616 | |
mbed_official | 155:8435094ec241 | 617 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 618 | { |
mbed_official | 155:8435094ec241 | 619 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 620 | |
mbed_official | 155:8435094ec241 | 621 | if(WRP0_Data != 0xFF) |
mbed_official | 155:8435094ec241 | 622 | { |
mbed_official | 155:8435094ec241 | 623 | OB->WRP0 = WRP0_Data; |
mbed_official | 155:8435094ec241 | 624 | |
mbed_official | 155:8435094ec241 | 625 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 626 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 627 | } |
mbed_official | 155:8435094ec241 | 628 | if((status == FLASH_COMPLETE) && (WRP1_Data != 0xFF)) |
mbed_official | 155:8435094ec241 | 629 | { |
mbed_official | 155:8435094ec241 | 630 | OB->WRP1 = WRP1_Data; |
mbed_official | 155:8435094ec241 | 631 | |
mbed_official | 155:8435094ec241 | 632 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 633 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 634 | } |
mbed_official | 155:8435094ec241 | 635 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 636 | { |
mbed_official | 155:8435094ec241 | 637 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 638 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 639 | } |
mbed_official | 155:8435094ec241 | 640 | } |
mbed_official | 155:8435094ec241 | 641 | /* Return the write protection operation Status */ |
mbed_official | 155:8435094ec241 | 642 | return status; |
mbed_official | 155:8435094ec241 | 643 | } |
mbed_official | 155:8435094ec241 | 644 | |
mbed_official | 155:8435094ec241 | 645 | /** |
mbed_official | 155:8435094ec241 | 646 | * @brief Enables or disables the read out protection. |
mbed_official | 155:8435094ec241 | 647 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 155:8435094ec241 | 648 | * must be called before. |
mbed_official | 155:8435094ec241 | 649 | * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes |
mbed_official | 155:8435094ec241 | 650 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 651 | * @param FLASH_ReadProtection_Level: specifies the read protection level. |
mbed_official | 155:8435094ec241 | 652 | * This parameter can be: |
mbed_official | 155:8435094ec241 | 653 | * @arg OB_RDP_Level_0: No protection |
mbed_official | 155:8435094ec241 | 654 | * @arg OB_RDP_Level_1: Read protection of the memory |
mbed_official | 155:8435094ec241 | 655 | * @arg OB_RDP_Level_2: Chip protection |
mbed_official | 155:8435094ec241 | 656 | * @retval FLASH Status: The returned value can be: |
mbed_official | 155:8435094ec241 | 657 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 658 | */ |
mbed_official | 155:8435094ec241 | 659 | FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP) |
mbed_official | 155:8435094ec241 | 660 | { |
mbed_official | 155:8435094ec241 | 661 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 662 | |
mbed_official | 155:8435094ec241 | 663 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 664 | assert_param(IS_OB_RDP(OB_RDP)); |
mbed_official | 155:8435094ec241 | 665 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 666 | |
mbed_official | 155:8435094ec241 | 667 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 668 | { |
mbed_official | 155:8435094ec241 | 669 | FLASH->CR |= FLASH_CR_OPTER; |
mbed_official | 155:8435094ec241 | 670 | FLASH->CR |= FLASH_CR_STRT; |
mbed_official | 155:8435094ec241 | 671 | |
mbed_official | 155:8435094ec241 | 672 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 673 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 674 | |
mbed_official | 155:8435094ec241 | 675 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 676 | { |
mbed_official | 155:8435094ec241 | 677 | /* If the erase operation is completed, disable the OPTER Bit */ |
mbed_official | 155:8435094ec241 | 678 | FLASH->CR &= ~FLASH_CR_OPTER; |
mbed_official | 155:8435094ec241 | 679 | |
mbed_official | 155:8435094ec241 | 680 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 681 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 682 | |
mbed_official | 155:8435094ec241 | 683 | OB->RDP = OB_RDP; |
mbed_official | 155:8435094ec241 | 684 | |
mbed_official | 155:8435094ec241 | 685 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 686 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 687 | |
mbed_official | 155:8435094ec241 | 688 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 689 | { |
mbed_official | 155:8435094ec241 | 690 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 691 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 692 | } |
mbed_official | 155:8435094ec241 | 693 | } |
mbed_official | 155:8435094ec241 | 694 | else |
mbed_official | 155:8435094ec241 | 695 | { |
mbed_official | 155:8435094ec241 | 696 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 697 | { |
mbed_official | 155:8435094ec241 | 698 | /* Disable the OPTER Bit */ |
mbed_official | 155:8435094ec241 | 699 | FLASH->CR &= ~FLASH_CR_OPTER; |
mbed_official | 155:8435094ec241 | 700 | } |
mbed_official | 155:8435094ec241 | 701 | } |
mbed_official | 155:8435094ec241 | 702 | } |
mbed_official | 155:8435094ec241 | 703 | /* Return the protection operation Status */ |
mbed_official | 155:8435094ec241 | 704 | return status; |
mbed_official | 155:8435094ec241 | 705 | } |
mbed_official | 155:8435094ec241 | 706 | |
mbed_official | 155:8435094ec241 | 707 | /** |
mbed_official | 155:8435094ec241 | 708 | * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
mbed_official | 155:8435094ec241 | 709 | * @param OB_IWDG: Selects the IWDG mode |
mbed_official | 155:8435094ec241 | 710 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 711 | * @arg OB_IWDG_SW: Software IWDG selected |
mbed_official | 155:8435094ec241 | 712 | * @arg OB_IWDG_HW: Hardware IWDG selected |
mbed_official | 155:8435094ec241 | 713 | * @param OB_STOP: Reset event when entering STOP mode. |
mbed_official | 155:8435094ec241 | 714 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 715 | * @arg OB_STOP_NoRST: No reset generated when entering in STOP |
mbed_official | 155:8435094ec241 | 716 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
mbed_official | 155:8435094ec241 | 717 | * @param OB_STDBY: Reset event when entering Standby mode. |
mbed_official | 155:8435094ec241 | 718 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 719 | * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY |
mbed_official | 155:8435094ec241 | 720 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
mbed_official | 155:8435094ec241 | 721 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 722 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 723 | */ |
mbed_official | 155:8435094ec241 | 724 | FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) |
mbed_official | 155:8435094ec241 | 725 | { |
mbed_official | 155:8435094ec241 | 726 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 727 | |
mbed_official | 155:8435094ec241 | 728 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 729 | assert_param(IS_OB_IWDG_SOURCE(OB_IWDG)); |
mbed_official | 155:8435094ec241 | 730 | assert_param(IS_OB_STOP_SOURCE(OB_STOP)); |
mbed_official | 155:8435094ec241 | 731 | assert_param(IS_OB_STDBY_SOURCE(OB_STDBY)); |
mbed_official | 155:8435094ec241 | 732 | |
mbed_official | 155:8435094ec241 | 733 | /* Authorize the small information block programming */ |
mbed_official | 155:8435094ec241 | 734 | FLASH->OPTKEYR = FLASH_KEY1; |
mbed_official | 155:8435094ec241 | 735 | FLASH->OPTKEYR = FLASH_KEY2; |
mbed_official | 155:8435094ec241 | 736 | |
mbed_official | 155:8435094ec241 | 737 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 738 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 739 | |
mbed_official | 155:8435094ec241 | 740 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 741 | { |
mbed_official | 155:8435094ec241 | 742 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 743 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 744 | |
mbed_official | 155:8435094ec241 | 745 | OB->USER = (uint8_t)((uint8_t)(OB_IWDG | OB_STOP) | (uint8_t)(OB_STDBY |0xF8)); |
mbed_official | 155:8435094ec241 | 746 | |
mbed_official | 155:8435094ec241 | 747 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 748 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 749 | |
mbed_official | 155:8435094ec241 | 750 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 751 | { |
mbed_official | 155:8435094ec241 | 752 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 753 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 754 | } |
mbed_official | 155:8435094ec241 | 755 | } |
mbed_official | 155:8435094ec241 | 756 | /* Return the Option Byte program Status */ |
mbed_official | 155:8435094ec241 | 757 | return status; |
mbed_official | 155:8435094ec241 | 758 | } |
mbed_official | 155:8435094ec241 | 759 | |
mbed_official | 155:8435094ec241 | 760 | /** |
mbed_official | 155:8435094ec241 | 761 | * @brief Sets or resets the BOOT1. |
mbed_official | 155:8435094ec241 | 762 | * @param OB_BOOT1: Set or Reset the BOOT1. |
mbed_official | 155:8435094ec241 | 763 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 764 | * @arg OB_BOOT1_RESET: BOOT1 Reset |
mbed_official | 155:8435094ec241 | 765 | * @arg OB_BOOT1_SET: BOOT1 Set |
mbed_official | 155:8435094ec241 | 766 | * @retval None |
mbed_official | 155:8435094ec241 | 767 | */ |
mbed_official | 155:8435094ec241 | 768 | FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1) |
mbed_official | 155:8435094ec241 | 769 | { |
mbed_official | 155:8435094ec241 | 770 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 771 | |
mbed_official | 155:8435094ec241 | 772 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 773 | assert_param(IS_OB_BOOT1(OB_BOOT1)); |
mbed_official | 155:8435094ec241 | 774 | |
mbed_official | 155:8435094ec241 | 775 | /* Authorize the small information block programming */ |
mbed_official | 155:8435094ec241 | 776 | FLASH->OPTKEYR = FLASH_KEY1; |
mbed_official | 155:8435094ec241 | 777 | FLASH->OPTKEYR = FLASH_KEY2; |
mbed_official | 155:8435094ec241 | 778 | |
mbed_official | 155:8435094ec241 | 779 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 780 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 781 | |
mbed_official | 155:8435094ec241 | 782 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 783 | { |
mbed_official | 155:8435094ec241 | 784 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 785 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 786 | |
mbed_official | 155:8435094ec241 | 787 | OB->USER = OB_BOOT1|0xEF; |
mbed_official | 155:8435094ec241 | 788 | |
mbed_official | 155:8435094ec241 | 789 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 790 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 791 | |
mbed_official | 155:8435094ec241 | 792 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 793 | { |
mbed_official | 155:8435094ec241 | 794 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 795 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 796 | } |
mbed_official | 155:8435094ec241 | 797 | } |
mbed_official | 155:8435094ec241 | 798 | /* Return the Option Byte program Status */ |
mbed_official | 155:8435094ec241 | 799 | return status; |
mbed_official | 155:8435094ec241 | 800 | } |
mbed_official | 155:8435094ec241 | 801 | |
mbed_official | 155:8435094ec241 | 802 | /** |
mbed_official | 155:8435094ec241 | 803 | * @brief Sets or resets the analogue monitoring on VDDA Power source. |
mbed_official | 155:8435094ec241 | 804 | * @param OB_VDDA_ANALOG: Selects the analog monitoring on VDDA Power source. |
mbed_official | 155:8435094ec241 | 805 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 806 | * @arg OB_VDDA_ANALOG_ON: Analog monitoring on VDDA Power source ON |
mbed_official | 155:8435094ec241 | 807 | * @arg OB_VDDA_ANALOG_OFF: Analog monitoring on VDDA Power source OFF |
mbed_official | 155:8435094ec241 | 808 | * @retval None |
mbed_official | 155:8435094ec241 | 809 | */ |
mbed_official | 155:8435094ec241 | 810 | FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG) |
mbed_official | 155:8435094ec241 | 811 | { |
mbed_official | 155:8435094ec241 | 812 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 813 | |
mbed_official | 155:8435094ec241 | 814 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 815 | assert_param(IS_OB_VDDA_ANALOG(OB_VDDA_ANALOG)); |
mbed_official | 155:8435094ec241 | 816 | |
mbed_official | 155:8435094ec241 | 817 | /* Authorize the small information block programming */ |
mbed_official | 155:8435094ec241 | 818 | FLASH->OPTKEYR = FLASH_KEY1; |
mbed_official | 155:8435094ec241 | 819 | FLASH->OPTKEYR = FLASH_KEY2; |
mbed_official | 155:8435094ec241 | 820 | |
mbed_official | 155:8435094ec241 | 821 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 822 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 823 | |
mbed_official | 155:8435094ec241 | 824 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 825 | { |
mbed_official | 155:8435094ec241 | 826 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 827 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 828 | |
mbed_official | 155:8435094ec241 | 829 | OB->USER = OB_VDDA_ANALOG |0xDF; |
mbed_official | 155:8435094ec241 | 830 | |
mbed_official | 155:8435094ec241 | 831 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 832 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 833 | |
mbed_official | 155:8435094ec241 | 834 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 835 | { |
mbed_official | 155:8435094ec241 | 836 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 837 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 838 | } |
mbed_official | 155:8435094ec241 | 839 | } |
mbed_official | 155:8435094ec241 | 840 | /* Return the Option Byte program Status */ |
mbed_official | 155:8435094ec241 | 841 | return status; |
mbed_official | 155:8435094ec241 | 842 | } |
mbed_official | 155:8435094ec241 | 843 | |
mbed_official | 155:8435094ec241 | 844 | /** |
mbed_official | 155:8435094ec241 | 845 | * @brief Sets or resets the SRAM partiy. |
mbed_official | 155:8435094ec241 | 846 | * @param OB_SRAM_Parity: Set or Reset the SRAM partiy enable bit. |
mbed_official | 155:8435094ec241 | 847 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 848 | * @arg OB_SRAM_PARITY_SET: Set SRAM partiy. |
mbed_official | 155:8435094ec241 | 849 | * @arg OB_SRAM_PARITY_RESET: Reset SRAM partiy. |
mbed_official | 155:8435094ec241 | 850 | * @retval None |
mbed_official | 155:8435094ec241 | 851 | */ |
mbed_official | 155:8435094ec241 | 852 | FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity) |
mbed_official | 155:8435094ec241 | 853 | { |
mbed_official | 155:8435094ec241 | 854 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 855 | |
mbed_official | 155:8435094ec241 | 856 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 857 | assert_param(IS_OB_SRAM_PARITY(OB_SRAM_Parity)); |
mbed_official | 155:8435094ec241 | 858 | |
mbed_official | 155:8435094ec241 | 859 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 860 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 861 | |
mbed_official | 155:8435094ec241 | 862 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 863 | { |
mbed_official | 155:8435094ec241 | 864 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 865 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 866 | |
mbed_official | 155:8435094ec241 | 867 | OB->USER = OB_SRAM_Parity | 0xBF; |
mbed_official | 155:8435094ec241 | 868 | |
mbed_official | 155:8435094ec241 | 869 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 870 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 871 | |
mbed_official | 155:8435094ec241 | 872 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 873 | { |
mbed_official | 155:8435094ec241 | 874 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 875 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 876 | } |
mbed_official | 155:8435094ec241 | 877 | } |
mbed_official | 155:8435094ec241 | 878 | /* Return the Option Byte program Status */ |
mbed_official | 155:8435094ec241 | 879 | return status; |
mbed_official | 155:8435094ec241 | 880 | } |
mbed_official | 155:8435094ec241 | 881 | |
mbed_official | 155:8435094ec241 | 882 | /** |
mbed_official | 155:8435094ec241 | 883 | * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY/ BOOT1 and OB_VDDA_ANALOG. |
mbed_official | 155:8435094ec241 | 884 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 155:8435094ec241 | 885 | * must be called before. |
mbed_official | 155:8435094ec241 | 886 | * @note Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes |
mbed_official | 155:8435094ec241 | 887 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 888 | * @param OB_USER: Selects all user option bytes |
mbed_official | 155:8435094ec241 | 889 | * This parameter is a combination of the following values: |
mbed_official | 155:8435094ec241 | 890 | * @arg OB_IWDG_SW / OB_IWDG_HW: Software / Hardware WDG selected |
mbed_official | 155:8435094ec241 | 891 | * @arg OB_STOP_NoRST / OB_STOP_RST: No reset / Reset generated when entering in STOP |
mbed_official | 155:8435094ec241 | 892 | * @arg OB_STDBY_NoRST / OB_STDBY_RST: No reset / Reset generated when entering in STANDBY |
mbed_official | 155:8435094ec241 | 893 | * @arg OB_BOOT1_RESET / OB_BOOT1_SET: BOOT1 Reset / Set |
mbed_official | 155:8435094ec241 | 894 | * @arg OB_VDDA_ANALOG_ON / OB_VDDA_ANALOG_OFF: Analog monitoring on VDDA Power source ON / OFF |
mbed_official | 155:8435094ec241 | 895 | * @retval FLASH Status: The returned value can be: |
mbed_official | 155:8435094ec241 | 896 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 897 | */ |
mbed_official | 155:8435094ec241 | 898 | FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER) |
mbed_official | 155:8435094ec241 | 899 | { |
mbed_official | 155:8435094ec241 | 900 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 901 | |
mbed_official | 155:8435094ec241 | 902 | /* Authorize the small information block programming */ |
mbed_official | 155:8435094ec241 | 903 | FLASH->OPTKEYR = FLASH_KEY1; |
mbed_official | 155:8435094ec241 | 904 | FLASH->OPTKEYR = FLASH_KEY2; |
mbed_official | 155:8435094ec241 | 905 | |
mbed_official | 155:8435094ec241 | 906 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 907 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 908 | |
mbed_official | 155:8435094ec241 | 909 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 910 | { |
mbed_official | 155:8435094ec241 | 911 | /* Enable the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 912 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 913 | |
mbed_official | 155:8435094ec241 | 914 | OB->USER = OB_USER | 0x88; |
mbed_official | 155:8435094ec241 | 915 | |
mbed_official | 155:8435094ec241 | 916 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 917 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 918 | |
mbed_official | 155:8435094ec241 | 919 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 920 | { |
mbed_official | 155:8435094ec241 | 921 | /* if the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 922 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 923 | } |
mbed_official | 155:8435094ec241 | 924 | } |
mbed_official | 155:8435094ec241 | 925 | /* Return the Option Byte program Status */ |
mbed_official | 155:8435094ec241 | 926 | return status; |
mbed_official | 155:8435094ec241 | 927 | |
mbed_official | 155:8435094ec241 | 928 | } |
mbed_official | 155:8435094ec241 | 929 | |
mbed_official | 155:8435094ec241 | 930 | /** |
mbed_official | 155:8435094ec241 | 931 | * @brief Programs a half word at a specified Option Byte Data address. |
mbed_official | 155:8435094ec241 | 932 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 155:8435094ec241 | 933 | * must be called before. |
mbed_official | 155:8435094ec241 | 934 | * Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes |
mbed_official | 155:8435094ec241 | 935 | * (recommended to protect the FLASH memory against possible unwanted operation) |
mbed_official | 155:8435094ec241 | 936 | * @param Address: specifies the address to be programmed. |
mbed_official | 155:8435094ec241 | 937 | * This parameter can be 0x1FFFF804 or 0x1FFFF806. |
mbed_official | 155:8435094ec241 | 938 | * @param Data: specifies the data to be programmed. |
mbed_official | 155:8435094ec241 | 939 | * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, |
mbed_official | 155:8435094ec241 | 940 | * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 941 | */ |
mbed_official | 155:8435094ec241 | 942 | FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data) |
mbed_official | 155:8435094ec241 | 943 | { |
mbed_official | 155:8435094ec241 | 944 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 945 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 946 | assert_param(IS_OB_DATA_ADDRESS(Address)); |
mbed_official | 155:8435094ec241 | 947 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 948 | |
mbed_official | 155:8435094ec241 | 949 | if(status == FLASH_COMPLETE) |
mbed_official | 155:8435094ec241 | 950 | { |
mbed_official | 155:8435094ec241 | 951 | /* Enables the Option Bytes Programming operation */ |
mbed_official | 155:8435094ec241 | 952 | FLASH->CR |= FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 953 | *(__IO uint16_t*)Address = Data; |
mbed_official | 155:8435094ec241 | 954 | |
mbed_official | 155:8435094ec241 | 955 | /* Wait for last operation to be completed */ |
mbed_official | 155:8435094ec241 | 956 | status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT); |
mbed_official | 155:8435094ec241 | 957 | |
mbed_official | 155:8435094ec241 | 958 | if(status != FLASH_TIMEOUT) |
mbed_official | 155:8435094ec241 | 959 | { |
mbed_official | 155:8435094ec241 | 960 | /* If the program operation is completed, disable the OPTPG Bit */ |
mbed_official | 155:8435094ec241 | 961 | FLASH->CR &= ~FLASH_CR_OPTPG; |
mbed_official | 155:8435094ec241 | 962 | } |
mbed_official | 155:8435094ec241 | 963 | } |
mbed_official | 155:8435094ec241 | 964 | /* Return the Option Byte Data Program Status */ |
mbed_official | 155:8435094ec241 | 965 | return status; |
mbed_official | 155:8435094ec241 | 966 | } |
mbed_official | 155:8435094ec241 | 967 | |
mbed_official | 155:8435094ec241 | 968 | /** |
mbed_official | 155:8435094ec241 | 969 | * @brief Returns the FLASH User Option Bytes values. |
mbed_official | 155:8435094ec241 | 970 | * @param None |
mbed_official | 155:8435094ec241 | 971 | * @retval The FLASH User Option Bytes . |
mbed_official | 155:8435094ec241 | 972 | */ |
mbed_official | 155:8435094ec241 | 973 | uint8_t FLASH_OB_GetUser(void) |
mbed_official | 155:8435094ec241 | 974 | { |
mbed_official | 155:8435094ec241 | 975 | /* Return the User Option Byte */ |
mbed_official | 155:8435094ec241 | 976 | return (uint8_t)(FLASH->OBR >> 8); |
mbed_official | 155:8435094ec241 | 977 | } |
mbed_official | 155:8435094ec241 | 978 | |
mbed_official | 155:8435094ec241 | 979 | /** |
mbed_official | 155:8435094ec241 | 980 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 155:8435094ec241 | 981 | * @param None |
mbed_official | 155:8435094ec241 | 982 | * @retval The FLASH Write Protection Option Bytes value |
mbed_official | 155:8435094ec241 | 983 | */ |
mbed_official | 155:8435094ec241 | 984 | uint32_t FLASH_OB_GetWRP(void) |
mbed_official | 155:8435094ec241 | 985 | { |
mbed_official | 155:8435094ec241 | 986 | /* Return the FLASH write protection Register value */ |
mbed_official | 155:8435094ec241 | 987 | return (uint32_t)(FLASH->WRPR); |
mbed_official | 155:8435094ec241 | 988 | } |
mbed_official | 155:8435094ec241 | 989 | |
mbed_official | 155:8435094ec241 | 990 | /** |
mbed_official | 155:8435094ec241 | 991 | * @brief Checks whether the FLASH Read out Protection Status is set or not. |
mbed_official | 155:8435094ec241 | 992 | * @param None |
mbed_official | 155:8435094ec241 | 993 | * @retval FLASH ReadOut Protection Status(SET or RESET) |
mbed_official | 155:8435094ec241 | 994 | */ |
mbed_official | 155:8435094ec241 | 995 | FlagStatus FLASH_OB_GetRDP(void) |
mbed_official | 155:8435094ec241 | 996 | { |
mbed_official | 155:8435094ec241 | 997 | FlagStatus readstatus = RESET; |
mbed_official | 155:8435094ec241 | 998 | |
mbed_official | 155:8435094ec241 | 999 | if ((uint8_t)(FLASH->OBR & (FLASH_OBR_RDPRT1 | FLASH_OBR_RDPRT2)) != RESET) |
mbed_official | 155:8435094ec241 | 1000 | { |
mbed_official | 155:8435094ec241 | 1001 | readstatus = SET; |
mbed_official | 155:8435094ec241 | 1002 | } |
mbed_official | 155:8435094ec241 | 1003 | else |
mbed_official | 155:8435094ec241 | 1004 | { |
mbed_official | 155:8435094ec241 | 1005 | readstatus = RESET; |
mbed_official | 155:8435094ec241 | 1006 | } |
mbed_official | 155:8435094ec241 | 1007 | return readstatus; |
mbed_official | 155:8435094ec241 | 1008 | } |
mbed_official | 155:8435094ec241 | 1009 | |
mbed_official | 155:8435094ec241 | 1010 | /** |
mbed_official | 155:8435094ec241 | 1011 | * @} |
mbed_official | 155:8435094ec241 | 1012 | */ |
mbed_official | 155:8435094ec241 | 1013 | |
mbed_official | 155:8435094ec241 | 1014 | /** @defgroup FLASH_Group4 Interrupts and flags management functions |
mbed_official | 155:8435094ec241 | 1015 | * @brief Interrupts and flags management functions |
mbed_official | 155:8435094ec241 | 1016 | * |
mbed_official | 155:8435094ec241 | 1017 | @verbatim |
mbed_official | 155:8435094ec241 | 1018 | =============================================================================== |
mbed_official | 155:8435094ec241 | 1019 | ##### Interrupts and flags management functions ##### |
mbed_official | 155:8435094ec241 | 1020 | =============================================================================== |
mbed_official | 155:8435094ec241 | 1021 | |
mbed_official | 155:8435094ec241 | 1022 | @endverbatim |
mbed_official | 155:8435094ec241 | 1023 | * @{ |
mbed_official | 155:8435094ec241 | 1024 | */ |
mbed_official | 155:8435094ec241 | 1025 | |
mbed_official | 155:8435094ec241 | 1026 | /** |
mbed_official | 155:8435094ec241 | 1027 | * @brief Enables or disables the specified FLASH interrupts. |
mbed_official | 155:8435094ec241 | 1028 | * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or |
mbed_official | 155:8435094ec241 | 1029 | * disabled. |
mbed_official | 155:8435094ec241 | 1030 | * This parameter can be any combination of the following values: |
mbed_official | 155:8435094ec241 | 1031 | * @arg FLASH_IT_EOP: FLASH end of programming Interrupt |
mbed_official | 155:8435094ec241 | 1032 | * @arg FLASH_IT_ERR: FLASH Error Interrupt |
mbed_official | 155:8435094ec241 | 1033 | * @retval None |
mbed_official | 155:8435094ec241 | 1034 | */ |
mbed_official | 155:8435094ec241 | 1035 | void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState) |
mbed_official | 155:8435094ec241 | 1036 | { |
mbed_official | 155:8435094ec241 | 1037 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 1038 | assert_param(IS_FLASH_IT(FLASH_IT)); |
mbed_official | 155:8435094ec241 | 1039 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 155:8435094ec241 | 1040 | |
mbed_official | 155:8435094ec241 | 1041 | if(NewState != DISABLE) |
mbed_official | 155:8435094ec241 | 1042 | { |
mbed_official | 155:8435094ec241 | 1043 | /* Enable the interrupt sources */ |
mbed_official | 155:8435094ec241 | 1044 | FLASH->CR |= FLASH_IT; |
mbed_official | 155:8435094ec241 | 1045 | } |
mbed_official | 155:8435094ec241 | 1046 | else |
mbed_official | 155:8435094ec241 | 1047 | { |
mbed_official | 155:8435094ec241 | 1048 | /* Disable the interrupt sources */ |
mbed_official | 155:8435094ec241 | 1049 | FLASH->CR &= ~(uint32_t)FLASH_IT; |
mbed_official | 155:8435094ec241 | 1050 | } |
mbed_official | 155:8435094ec241 | 1051 | } |
mbed_official | 155:8435094ec241 | 1052 | |
mbed_official | 155:8435094ec241 | 1053 | /** |
mbed_official | 155:8435094ec241 | 1054 | * @brief Checks whether the specified FLASH flag is set or not. |
mbed_official | 155:8435094ec241 | 1055 | * @param FLASH_FLAG: specifies the FLASH flag to check. |
mbed_official | 155:8435094ec241 | 1056 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 1057 | * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag |
mbed_official | 155:8435094ec241 | 1058 | * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag |
mbed_official | 155:8435094ec241 | 1059 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag |
mbed_official | 155:8435094ec241 | 1060 | * @arg FLASH_FLAG_EOP: FLASH End of Programming flag |
mbed_official | 155:8435094ec241 | 1061 | * @retval The new state of FLASH_FLAG (SET or RESET). |
mbed_official | 155:8435094ec241 | 1062 | */ |
mbed_official | 155:8435094ec241 | 1063 | FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG) |
mbed_official | 155:8435094ec241 | 1064 | { |
mbed_official | 155:8435094ec241 | 1065 | FlagStatus bitstatus = RESET; |
mbed_official | 155:8435094ec241 | 1066 | |
mbed_official | 155:8435094ec241 | 1067 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 1068 | assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)); |
mbed_official | 155:8435094ec241 | 1069 | |
mbed_official | 155:8435094ec241 | 1070 | if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET) |
mbed_official | 155:8435094ec241 | 1071 | { |
mbed_official | 155:8435094ec241 | 1072 | bitstatus = SET; |
mbed_official | 155:8435094ec241 | 1073 | } |
mbed_official | 155:8435094ec241 | 1074 | else |
mbed_official | 155:8435094ec241 | 1075 | { |
mbed_official | 155:8435094ec241 | 1076 | bitstatus = RESET; |
mbed_official | 155:8435094ec241 | 1077 | } |
mbed_official | 155:8435094ec241 | 1078 | /* Return the new state of FLASH_FLAG (SET or RESET) */ |
mbed_official | 155:8435094ec241 | 1079 | return bitstatus; |
mbed_official | 155:8435094ec241 | 1080 | } |
mbed_official | 155:8435094ec241 | 1081 | |
mbed_official | 155:8435094ec241 | 1082 | /** |
mbed_official | 155:8435094ec241 | 1083 | * @brief Clears the FLASH's pending flags. |
mbed_official | 155:8435094ec241 | 1084 | * @param FLASH_FLAG: specifies the FLASH flags to clear. |
mbed_official | 155:8435094ec241 | 1085 | * This parameter can be any combination of the following values: |
mbed_official | 155:8435094ec241 | 1086 | * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag |
mbed_official | 155:8435094ec241 | 1087 | * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag |
mbed_official | 155:8435094ec241 | 1088 | * @arg FLASH_FLAG_EOP: FLASH End of Programming flag |
mbed_official | 155:8435094ec241 | 1089 | * @retval None |
mbed_official | 155:8435094ec241 | 1090 | */ |
mbed_official | 155:8435094ec241 | 1091 | void FLASH_ClearFlag(uint32_t FLASH_FLAG) |
mbed_official | 155:8435094ec241 | 1092 | { |
mbed_official | 155:8435094ec241 | 1093 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 1094 | assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)); |
mbed_official | 155:8435094ec241 | 1095 | |
mbed_official | 155:8435094ec241 | 1096 | /* Clear the flags */ |
mbed_official | 155:8435094ec241 | 1097 | FLASH->SR = FLASH_FLAG; |
mbed_official | 155:8435094ec241 | 1098 | } |
mbed_official | 155:8435094ec241 | 1099 | |
mbed_official | 155:8435094ec241 | 1100 | /** |
mbed_official | 155:8435094ec241 | 1101 | * @brief Returns the FLASH Status. |
mbed_official | 155:8435094ec241 | 1102 | * @param None |
mbed_official | 155:8435094ec241 | 1103 | * @retval FLASH Status: The returned value can be: |
mbed_official | 155:8435094ec241 | 1104 | * FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE. |
mbed_official | 155:8435094ec241 | 1105 | */ |
mbed_official | 155:8435094ec241 | 1106 | FLASH_Status FLASH_GetStatus(void) |
mbed_official | 155:8435094ec241 | 1107 | { |
mbed_official | 155:8435094ec241 | 1108 | FLASH_Status FLASHstatus = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 1109 | |
mbed_official | 155:8435094ec241 | 1110 | if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY) |
mbed_official | 155:8435094ec241 | 1111 | { |
mbed_official | 155:8435094ec241 | 1112 | FLASHstatus = FLASH_BUSY; |
mbed_official | 155:8435094ec241 | 1113 | } |
mbed_official | 155:8435094ec241 | 1114 | else |
mbed_official | 155:8435094ec241 | 1115 | { |
mbed_official | 155:8435094ec241 | 1116 | if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00) |
mbed_official | 155:8435094ec241 | 1117 | { |
mbed_official | 155:8435094ec241 | 1118 | FLASHstatus = FLASH_ERROR_WRP; |
mbed_official | 155:8435094ec241 | 1119 | } |
mbed_official | 155:8435094ec241 | 1120 | else |
mbed_official | 155:8435094ec241 | 1121 | { |
mbed_official | 155:8435094ec241 | 1122 | if((FLASH->SR & (uint32_t)(FLASH_SR_PGERR)) != (uint32_t)0x00) |
mbed_official | 155:8435094ec241 | 1123 | { |
mbed_official | 155:8435094ec241 | 1124 | FLASHstatus = FLASH_ERROR_PROGRAM; |
mbed_official | 155:8435094ec241 | 1125 | } |
mbed_official | 155:8435094ec241 | 1126 | else |
mbed_official | 155:8435094ec241 | 1127 | { |
mbed_official | 155:8435094ec241 | 1128 | FLASHstatus = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 1129 | } |
mbed_official | 155:8435094ec241 | 1130 | } |
mbed_official | 155:8435094ec241 | 1131 | } |
mbed_official | 155:8435094ec241 | 1132 | /* Return the FLASH Status */ |
mbed_official | 155:8435094ec241 | 1133 | return FLASHstatus; |
mbed_official | 155:8435094ec241 | 1134 | } |
mbed_official | 155:8435094ec241 | 1135 | |
mbed_official | 155:8435094ec241 | 1136 | /** |
mbed_official | 155:8435094ec241 | 1137 | * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur. |
mbed_official | 155:8435094ec241 | 1138 | * @param Timeout: FLASH programming Timeout |
mbed_official | 155:8435094ec241 | 1139 | * @retval FLASH Status: The returned value can be: FLASH_BUSY, |
mbed_official | 155:8435094ec241 | 1140 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 155:8435094ec241 | 1141 | */ |
mbed_official | 155:8435094ec241 | 1142 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) |
mbed_official | 155:8435094ec241 | 1143 | { |
mbed_official | 155:8435094ec241 | 1144 | FLASH_Status status = FLASH_COMPLETE; |
mbed_official | 155:8435094ec241 | 1145 | |
mbed_official | 155:8435094ec241 | 1146 | /* Check for the FLASH Status */ |
mbed_official | 155:8435094ec241 | 1147 | status = FLASH_GetStatus(); |
mbed_official | 155:8435094ec241 | 1148 | |
mbed_official | 155:8435094ec241 | 1149 | /* Wait for a FLASH operation to complete or a TIMEOUT to occur */ |
mbed_official | 155:8435094ec241 | 1150 | while((status == FLASH_BUSY) && (Timeout != 0x00)) |
mbed_official | 155:8435094ec241 | 1151 | { |
mbed_official | 155:8435094ec241 | 1152 | status = FLASH_GetStatus(); |
mbed_official | 155:8435094ec241 | 1153 | Timeout--; |
mbed_official | 155:8435094ec241 | 1154 | } |
mbed_official | 155:8435094ec241 | 1155 | |
mbed_official | 155:8435094ec241 | 1156 | if(Timeout == 0x00 ) |
mbed_official | 155:8435094ec241 | 1157 | { |
mbed_official | 155:8435094ec241 | 1158 | status = FLASH_TIMEOUT; |
mbed_official | 155:8435094ec241 | 1159 | } |
mbed_official | 155:8435094ec241 | 1160 | /* Return the operation status */ |
mbed_official | 155:8435094ec241 | 1161 | return status; |
mbed_official | 155:8435094ec241 | 1162 | } |
mbed_official | 155:8435094ec241 | 1163 | |
mbed_official | 155:8435094ec241 | 1164 | /** |
mbed_official | 155:8435094ec241 | 1165 | * @} |
mbed_official | 155:8435094ec241 | 1166 | */ |
mbed_official | 155:8435094ec241 | 1167 | |
mbed_official | 155:8435094ec241 | 1168 | /** |
mbed_official | 155:8435094ec241 | 1169 | * @} |
mbed_official | 155:8435094ec241 | 1170 | */ |
mbed_official | 155:8435094ec241 | 1171 | |
mbed_official | 155:8435094ec241 | 1172 | /** |
mbed_official | 155:8435094ec241 | 1173 | * @} |
mbed_official | 155:8435094ec241 | 1174 | */ |
mbed_official | 155:8435094ec241 | 1175 | |
mbed_official | 155:8435094ec241 | 1176 | /** |
mbed_official | 155:8435094ec241 | 1177 | * @} |
mbed_official | 155:8435094ec241 | 1178 | */ |
mbed_official | 155:8435094ec241 | 1179 | |
mbed_official | 155:8435094ec241 | 1180 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |