mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_flash.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 237:f3da66175598
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_flash.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief FLASH HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the internal FLASH memory: |
mbed_official | 237:f3da66175598 | 11 | * + Program operations functions |
mbed_official | 237:f3da66175598 | 12 | * + Memory Control functions |
mbed_official | 237:f3da66175598 | 13 | * + Peripheral State functions |
mbed_official | 237:f3da66175598 | 14 | * |
mbed_official | 237:f3da66175598 | 15 | @verbatim |
mbed_official | 237:f3da66175598 | 16 | ============================================================================== |
mbed_official | 237:f3da66175598 | 17 | ##### FLASH peripheral features ##### |
mbed_official | 237:f3da66175598 | 18 | ============================================================================== |
mbed_official | 237:f3da66175598 | 19 | |
mbed_official | 237:f3da66175598 | 20 | [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses |
mbed_official | 237:f3da66175598 | 21 | to the Flash memory. It implements the erase and program Flash memory operations |
mbed_official | 237:f3da66175598 | 22 | and the read and write protection mechanisms. |
mbed_official | 237:f3da66175598 | 23 | |
mbed_official | 237:f3da66175598 | 24 | [..] The Flash memory interface accelerates code execution with a system of instruction |
mbed_official | 237:f3da66175598 | 25 | prefetch. |
mbed_official | 237:f3da66175598 | 26 | |
mbed_official | 237:f3da66175598 | 27 | [..] The FLASH main features are: |
mbed_official | 237:f3da66175598 | 28 | (+) Flash memory read operations |
mbed_official | 237:f3da66175598 | 29 | (+) Flash memory program/erase operations |
mbed_official | 237:f3da66175598 | 30 | (+) Read / write protections |
mbed_official | 237:f3da66175598 | 31 | (+) Prefetch on I-Code |
mbed_official | 237:f3da66175598 | 32 | |
mbed_official | 237:f3da66175598 | 33 | |
mbed_official | 237:f3da66175598 | 34 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 35 | ============================================================================== |
mbed_official | 237:f3da66175598 | 36 | [..] |
mbed_official | 237:f3da66175598 | 37 | This driver provides functions and macros to configure and program the FLASH |
mbed_official | 237:f3da66175598 | 38 | memory of all STM32F3xx devices. These functions are split in 3 groups: |
mbed_official | 237:f3da66175598 | 39 | |
mbed_official | 237:f3da66175598 | 40 | (#) FLASH Memory I/O Programming functions: this group includes all needed |
mbed_official | 237:f3da66175598 | 41 | functions to erase and program the main memory: |
mbed_official | 237:f3da66175598 | 42 | (++) Lock and Unlock the FLASH interface |
mbed_official | 237:f3da66175598 | 43 | (++) Erase function: Erase page, erase all pages |
mbed_official | 237:f3da66175598 | 44 | (++) Program functions: half word and word |
mbed_official | 237:f3da66175598 | 45 | |
mbed_official | 237:f3da66175598 | 46 | (#) Option Bytes Programming functions: this group includes all needed |
mbed_official | 237:f3da66175598 | 47 | functions to manage the Option Bytes: |
mbed_official | 237:f3da66175598 | 48 | (++) Lock and Unlock the Option Bytes |
mbed_official | 237:f3da66175598 | 49 | (++) Erase Option Bytes |
mbed_official | 237:f3da66175598 | 50 | (++) Set/Reset the write protection |
mbed_official | 237:f3da66175598 | 51 | (++) Set the Read protection Level |
mbed_official | 237:f3da66175598 | 52 | (++) Program the user Option Bytes |
mbed_official | 237:f3da66175598 | 53 | (++) Program the data Option Bytes |
mbed_official | 237:f3da66175598 | 54 | (++) Launch the Option Bytes loader |
mbed_official | 237:f3da66175598 | 55 | |
mbed_official | 237:f3da66175598 | 56 | (#) Interrupts and flags management functions : this group |
mbed_official | 237:f3da66175598 | 57 | includes all needed functions to: |
mbed_official | 237:f3da66175598 | 58 | (++) Handle FLASH interrupts |
mbed_official | 237:f3da66175598 | 59 | (++) Wait for last FLASH operation according to its status |
mbed_official | 237:f3da66175598 | 60 | (++) Get error flag status |
mbed_official | 237:f3da66175598 | 61 | |
mbed_official | 237:f3da66175598 | 62 | [..] In addition to these function, this driver includes a set of macros allowing |
mbed_official | 237:f3da66175598 | 63 | to handle the following operations: |
mbed_official | 237:f3da66175598 | 64 | |
mbed_official | 237:f3da66175598 | 65 | (+) Set the latency |
mbed_official | 237:f3da66175598 | 66 | (+) Enable/Disable the prefetch buffer |
mbed_official | 237:f3da66175598 | 67 | (+) Enable/Disable the half cycle access |
mbed_official | 237:f3da66175598 | 68 | (+) Enable/Disable the FLASH interrupts |
mbed_official | 237:f3da66175598 | 69 | (+) Monitor the FLASH flags status |
mbed_official | 237:f3da66175598 | 70 | |
mbed_official | 237:f3da66175598 | 71 | @endverbatim |
mbed_official | 237:f3da66175598 | 72 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 73 | * @attention |
mbed_official | 237:f3da66175598 | 74 | * |
mbed_official | 237:f3da66175598 | 75 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 76 | * |
mbed_official | 237:f3da66175598 | 77 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 78 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 79 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 80 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 81 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 82 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 83 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 84 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 85 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 86 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 87 | * |
mbed_official | 237:f3da66175598 | 88 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 89 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 90 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 91 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 92 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 93 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 94 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 95 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 96 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 97 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 98 | * |
mbed_official | 237:f3da66175598 | 99 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 100 | */ |
mbed_official | 237:f3da66175598 | 101 | |
mbed_official | 237:f3da66175598 | 102 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 103 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 104 | |
mbed_official | 237:f3da66175598 | 105 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 106 | * @{ |
mbed_official | 237:f3da66175598 | 107 | */ |
mbed_official | 237:f3da66175598 | 108 | |
mbed_official | 237:f3da66175598 | 109 | /** @defgroup FLASH |
mbed_official | 237:f3da66175598 | 110 | * @brief FLASH HAL module driver |
mbed_official | 237:f3da66175598 | 111 | * @{ |
mbed_official | 237:f3da66175598 | 112 | */ |
mbed_official | 237:f3da66175598 | 113 | |
mbed_official | 237:f3da66175598 | 114 | #ifdef HAL_FLASH_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 115 | |
mbed_official | 237:f3da66175598 | 116 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 117 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 118 | #define HAL_FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ |
mbed_official | 237:f3da66175598 | 119 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 120 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 121 | /* Variables used for Erase pages under interruption*/ |
mbed_official | 237:f3da66175598 | 122 | FLASH_ProcessTypeDef pFlash; |
mbed_official | 237:f3da66175598 | 123 | |
mbed_official | 237:f3da66175598 | 124 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 125 | /* Erase operations */ |
mbed_official | 237:f3da66175598 | 126 | void FLASH_PageErase(uint32_t PageAddress); |
mbed_official | 237:f3da66175598 | 127 | |
mbed_official | 237:f3da66175598 | 128 | /* Program operations */ |
mbed_official | 237:f3da66175598 | 129 | static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 237:f3da66175598 | 130 | |
mbed_official | 237:f3da66175598 | 131 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
mbed_official | 237:f3da66175598 | 132 | static void FLASH_SetErrorCode(void); |
mbed_official | 237:f3da66175598 | 133 | |
mbed_official | 237:f3da66175598 | 134 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 135 | |
mbed_official | 237:f3da66175598 | 136 | /** @defgroup FLASH_Private_Functions |
mbed_official | 237:f3da66175598 | 137 | * @{ |
mbed_official | 237:f3da66175598 | 138 | */ |
mbed_official | 237:f3da66175598 | 139 | |
mbed_official | 237:f3da66175598 | 140 | /** @defgroup HAL_FLASH_Group1 Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 141 | * @brief Initialization and Configuration functions |
mbed_official | 237:f3da66175598 | 142 | * |
mbed_official | 237:f3da66175598 | 143 | @verbatim |
mbed_official | 237:f3da66175598 | 144 | =============================================================================== |
mbed_official | 237:f3da66175598 | 145 | ##### Initialization and de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 146 | =============================================================================== |
mbed_official | 237:f3da66175598 | 147 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 148 | |
mbed_official | 237:f3da66175598 | 149 | @endverbatim |
mbed_official | 237:f3da66175598 | 150 | * @{ |
mbed_official | 237:f3da66175598 | 151 | */ |
mbed_official | 237:f3da66175598 | 152 | |
mbed_official | 237:f3da66175598 | 153 | |
mbed_official | 237:f3da66175598 | 154 | /** |
mbed_official | 237:f3da66175598 | 155 | * @} |
mbed_official | 237:f3da66175598 | 156 | */ |
mbed_official | 237:f3da66175598 | 157 | |
mbed_official | 237:f3da66175598 | 158 | /** @defgroup HAL_FLASH_Group2 I/O operation functions |
mbed_official | 237:f3da66175598 | 159 | * @brief Data transfers functions |
mbed_official | 237:f3da66175598 | 160 | * |
mbed_official | 237:f3da66175598 | 161 | @verbatim |
mbed_official | 237:f3da66175598 | 162 | =============================================================================== |
mbed_official | 237:f3da66175598 | 163 | ##### IO operation functions ##### |
mbed_official | 237:f3da66175598 | 164 | =============================================================================== |
mbed_official | 237:f3da66175598 | 165 | [..] |
mbed_official | 237:f3da66175598 | 166 | This subsection provides a set of functions allowing to manage the FLASH |
mbed_official | 237:f3da66175598 | 167 | program operations (write/erase). |
mbed_official | 237:f3da66175598 | 168 | |
mbed_official | 237:f3da66175598 | 169 | @endverbatim |
mbed_official | 237:f3da66175598 | 170 | * @{ |
mbed_official | 237:f3da66175598 | 171 | */ |
mbed_official | 237:f3da66175598 | 172 | |
mbed_official | 237:f3da66175598 | 173 | /** |
mbed_official | 237:f3da66175598 | 174 | * @brief Program halfword, word or double word at a specified address |
mbed_official | 237:f3da66175598 | 175 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
mbed_official | 237:f3da66175598 | 176 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
mbed_official | 237:f3da66175598 | 177 | * |
mbed_official | 237:f3da66175598 | 178 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 237:f3da66175598 | 179 | * the erase operation is performed before the program one. |
mbed_official | 237:f3da66175598 | 180 | * |
mbed_official | 237:f3da66175598 | 181 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 237:f3da66175598 | 182 | * This parameter can be a value of @ref FLASH_Type_Program |
mbed_official | 237:f3da66175598 | 183 | * @param Address: Specifies the address to be programmed. |
mbed_official | 237:f3da66175598 | 184 | * @param Data: Specifies the data to be programmed |
mbed_official | 237:f3da66175598 | 185 | * |
mbed_official | 237:f3da66175598 | 186 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 237:f3da66175598 | 187 | */ |
mbed_official | 237:f3da66175598 | 188 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
mbed_official | 237:f3da66175598 | 189 | { |
mbed_official | 237:f3da66175598 | 190 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 191 | uint8_t index = 0; |
mbed_official | 237:f3da66175598 | 192 | uint8_t nbiterations = 0; |
mbed_official | 237:f3da66175598 | 193 | |
mbed_official | 237:f3da66175598 | 194 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 195 | __HAL_LOCK(&pFlash); |
mbed_official | 237:f3da66175598 | 196 | |
mbed_official | 237:f3da66175598 | 197 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 198 | assert_param(IS_TYPEPROGRAM(TypeProgram)); |
mbed_official | 237:f3da66175598 | 199 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
mbed_official | 237:f3da66175598 | 200 | |
mbed_official | 237:f3da66175598 | 201 | /* Wait for last operation to be completed */ |
mbed_official | 237:f3da66175598 | 202 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE); |
mbed_official | 237:f3da66175598 | 203 | |
mbed_official | 237:f3da66175598 | 204 | if(status == HAL_OK) |
mbed_official | 237:f3da66175598 | 205 | { |
mbed_official | 237:f3da66175598 | 206 | if(TypeProgram == TYPEPROGRAM_HALFWORD) |
mbed_official | 237:f3da66175598 | 207 | { |
mbed_official | 237:f3da66175598 | 208 | /* Program halfword (16-bit) at a specified address. */ |
mbed_official | 237:f3da66175598 | 209 | nbiterations = 1; |
mbed_official | 237:f3da66175598 | 210 | } |
mbed_official | 237:f3da66175598 | 211 | else if(TypeProgram == TYPEPROGRAM_WORD) |
mbed_official | 237:f3da66175598 | 212 | { |
mbed_official | 237:f3da66175598 | 213 | /* Program word (32-bit = 2*16-bit) at a specified address. */ |
mbed_official | 237:f3da66175598 | 214 | nbiterations = 2; |
mbed_official | 237:f3da66175598 | 215 | } |
mbed_official | 237:f3da66175598 | 216 | else |
mbed_official | 237:f3da66175598 | 217 | { |
mbed_official | 237:f3da66175598 | 218 | /* Program double word (64-bit = 4*16-bit) at a specified address. */ |
mbed_official | 237:f3da66175598 | 219 | nbiterations = 4; |
mbed_official | 237:f3da66175598 | 220 | } |
mbed_official | 237:f3da66175598 | 221 | |
mbed_official | 237:f3da66175598 | 222 | for (index = 0; index < nbiterations; index++) |
mbed_official | 237:f3da66175598 | 223 | { |
mbed_official | 237:f3da66175598 | 224 | FLASH_Program_HalfWord((Address + (2*index)), (uint16_t)(Data >> (16*index))); |
mbed_official | 237:f3da66175598 | 225 | |
mbed_official | 237:f3da66175598 | 226 | /* Wait for last operation to be completed */ |
mbed_official | 237:f3da66175598 | 227 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE); |
mbed_official | 237:f3da66175598 | 228 | |
mbed_official | 237:f3da66175598 | 229 | /* Check FLASH End of Operation flag */ |
mbed_official | 237:f3da66175598 | 230 | if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) |
mbed_official | 237:f3da66175598 | 231 | { |
mbed_official | 237:f3da66175598 | 232 | /* Clear FLASH End of Operation pending bit */ |
mbed_official | 237:f3da66175598 | 233 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); |
mbed_official | 237:f3da66175598 | 234 | } |
mbed_official | 237:f3da66175598 | 235 | |
mbed_official | 237:f3da66175598 | 236 | /* If the program operation is completed, disable the PG Bit */ |
mbed_official | 237:f3da66175598 | 237 | CLEAR_BIT(FLASH->CR, FLASH_CR_PG); |
mbed_official | 237:f3da66175598 | 238 | } |
mbed_official | 237:f3da66175598 | 239 | } |
mbed_official | 237:f3da66175598 | 240 | |
mbed_official | 237:f3da66175598 | 241 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 242 | __HAL_UNLOCK(&pFlash); |
mbed_official | 237:f3da66175598 | 243 | |
mbed_official | 237:f3da66175598 | 244 | return status; |
mbed_official | 237:f3da66175598 | 245 | } |
mbed_official | 237:f3da66175598 | 246 | |
mbed_official | 237:f3da66175598 | 247 | /** |
mbed_official | 237:f3da66175598 | 248 | * @brief Program halfword, word or double word at a specified address with interrupt enabled. |
mbed_official | 237:f3da66175598 | 249 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
mbed_official | 237:f3da66175598 | 250 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
mbed_official | 237:f3da66175598 | 251 | * |
mbed_official | 237:f3da66175598 | 252 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 237:f3da66175598 | 253 | * the erase operation is performed before the program one. |
mbed_official | 237:f3da66175598 | 254 | * |
mbed_official | 237:f3da66175598 | 255 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 237:f3da66175598 | 256 | * This parameter can be a value of @ref FLASH_Type_Program |
mbed_official | 237:f3da66175598 | 257 | * @param Address: Specifies the address to be programmed. |
mbed_official | 237:f3da66175598 | 258 | * @param Data: Specifies the data to be programmed |
mbed_official | 237:f3da66175598 | 259 | * |
mbed_official | 237:f3da66175598 | 260 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 237:f3da66175598 | 261 | */ |
mbed_official | 237:f3da66175598 | 262 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
mbed_official | 237:f3da66175598 | 263 | { |
mbed_official | 237:f3da66175598 | 264 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 265 | |
mbed_official | 237:f3da66175598 | 266 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 267 | __HAL_LOCK(&pFlash); |
mbed_official | 237:f3da66175598 | 268 | |
mbed_official | 237:f3da66175598 | 269 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 270 | assert_param(IS_TYPEPROGRAM(TypeProgram)); |
mbed_official | 237:f3da66175598 | 271 | assert_param(IS_FLASH_PROGRAM_ADDRESS(Address)); |
mbed_official | 237:f3da66175598 | 272 | |
mbed_official | 237:f3da66175598 | 273 | /* Enable End of FLASH Operation and Error source interrupts */ |
mbed_official | 237:f3da66175598 | 274 | __HAL_FLASH_ENABLE_IT((FLASH_IT_EOP | FLASH_IT_ERR)); |
mbed_official | 237:f3da66175598 | 275 | |
mbed_official | 237:f3da66175598 | 276 | pFlash.Address = Address; |
mbed_official | 237:f3da66175598 | 277 | pFlash.Data = Data; |
mbed_official | 237:f3da66175598 | 278 | |
mbed_official | 237:f3da66175598 | 279 | if(TypeProgram == TYPEPROGRAM_HALFWORD) |
mbed_official | 237:f3da66175598 | 280 | { |
mbed_official | 237:f3da66175598 | 281 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD; |
mbed_official | 237:f3da66175598 | 282 | /*Program halfword (16-bit) at a specified address.*/ |
mbed_official | 237:f3da66175598 | 283 | pFlash.DataRemaining = 1; |
mbed_official | 237:f3da66175598 | 284 | } |
mbed_official | 237:f3da66175598 | 285 | else if(TypeProgram == TYPEPROGRAM_WORD) |
mbed_official | 237:f3da66175598 | 286 | { |
mbed_official | 237:f3da66175598 | 287 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD; |
mbed_official | 237:f3da66175598 | 288 | /*Program word (32-bit : 2*16-bit) at a specified address.*/ |
mbed_official | 237:f3da66175598 | 289 | pFlash.DataRemaining = 2; |
mbed_official | 237:f3da66175598 | 290 | } |
mbed_official | 237:f3da66175598 | 291 | else |
mbed_official | 237:f3da66175598 | 292 | { |
mbed_official | 237:f3da66175598 | 293 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD; |
mbed_official | 237:f3da66175598 | 294 | /*Program double word (64-bit : 4*16-bit) at a specified address.*/ |
mbed_official | 237:f3da66175598 | 295 | pFlash.DataRemaining = 4; |
mbed_official | 237:f3da66175598 | 296 | } |
mbed_official | 237:f3da66175598 | 297 | |
mbed_official | 237:f3da66175598 | 298 | /*Program halfword (16-bit) at a specified address.*/ |
mbed_official | 237:f3da66175598 | 299 | FLASH_Program_HalfWord(Address, (uint16_t)Data); |
mbed_official | 237:f3da66175598 | 300 | |
mbed_official | 237:f3da66175598 | 301 | return status; |
mbed_official | 237:f3da66175598 | 302 | } |
mbed_official | 237:f3da66175598 | 303 | |
mbed_official | 237:f3da66175598 | 304 | /** |
mbed_official | 237:f3da66175598 | 305 | * @brief This function handles FLASH interrupt request. |
mbed_official | 237:f3da66175598 | 306 | * @param None |
mbed_official | 237:f3da66175598 | 307 | * @retval None |
mbed_official | 237:f3da66175598 | 308 | */ |
mbed_official | 237:f3da66175598 | 309 | void HAL_FLASH_IRQHandler(void) |
mbed_official | 237:f3da66175598 | 310 | { |
mbed_official | 237:f3da66175598 | 311 | uint32_t addresstmp; |
mbed_official | 237:f3da66175598 | 312 | /* If the operation is completed, disable the PG, PER and MER Bits */ |
mbed_official | 237:f3da66175598 | 313 | CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER)); |
mbed_official | 237:f3da66175598 | 314 | |
mbed_official | 237:f3da66175598 | 315 | /* Check FLASH End of Operation flag */ |
mbed_official | 237:f3da66175598 | 316 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) |
mbed_official | 237:f3da66175598 | 317 | { |
mbed_official | 237:f3da66175598 | 318 | /* Clear FLASH End of Operation pending bit */ |
mbed_official | 237:f3da66175598 | 319 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); |
mbed_official | 237:f3da66175598 | 320 | |
mbed_official | 237:f3da66175598 | 321 | if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) |
mbed_official | 237:f3da66175598 | 322 | { |
mbed_official | 237:f3da66175598 | 323 | /* Nb of pages to erased can be decreased */ |
mbed_official | 237:f3da66175598 | 324 | pFlash.DataRemaining--; |
mbed_official | 237:f3da66175598 | 325 | |
mbed_official | 237:f3da66175598 | 326 | /* Indicate user which page address has been erased*/ |
mbed_official | 237:f3da66175598 | 327 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
mbed_official | 237:f3da66175598 | 328 | |
mbed_official | 237:f3da66175598 | 329 | /* Check if there are still pages to erase*/ |
mbed_official | 237:f3da66175598 | 330 | if(pFlash.DataRemaining != 0) |
mbed_official | 237:f3da66175598 | 331 | { |
mbed_official | 237:f3da66175598 | 332 | /* Increment page address to next page */ |
mbed_official | 237:f3da66175598 | 333 | pFlash.Address += FLASH_PAGE_SIZE; |
mbed_official | 237:f3da66175598 | 334 | addresstmp = pFlash.Address; |
mbed_official | 237:f3da66175598 | 335 | FLASH_PageErase(addresstmp); |
mbed_official | 237:f3da66175598 | 336 | } |
mbed_official | 237:f3da66175598 | 337 | else |
mbed_official | 237:f3da66175598 | 338 | { |
mbed_official | 237:f3da66175598 | 339 | /*No more pages to Erase*/ |
mbed_official | 237:f3da66175598 | 340 | |
mbed_official | 237:f3da66175598 | 341 | /*Reset Address and stop Erase pages procedure*/ |
mbed_official | 237:f3da66175598 | 342 | pFlash.Address = 0xFFFFFFFF; |
mbed_official | 237:f3da66175598 | 343 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 237:f3da66175598 | 344 | } |
mbed_official | 237:f3da66175598 | 345 | } |
mbed_official | 237:f3da66175598 | 346 | else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) |
mbed_official | 237:f3da66175598 | 347 | { |
mbed_official | 237:f3da66175598 | 348 | /*MassErase ended. Return the selected bank*/ |
mbed_official | 237:f3da66175598 | 349 | /* FLASH EOP interrupt user callback */ |
mbed_official | 237:f3da66175598 | 350 | HAL_FLASH_EndOfOperationCallback(0); |
mbed_official | 237:f3da66175598 | 351 | |
mbed_official | 237:f3da66175598 | 352 | /* Stop Mass Erase procedure*/ |
mbed_official | 237:f3da66175598 | 353 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 237:f3da66175598 | 354 | } |
mbed_official | 237:f3da66175598 | 355 | else |
mbed_official | 237:f3da66175598 | 356 | { |
mbed_official | 237:f3da66175598 | 357 | /* Nb of 16-bit data to program can be decreased */ |
mbed_official | 237:f3da66175598 | 358 | pFlash.DataRemaining--; |
mbed_official | 237:f3da66175598 | 359 | |
mbed_official | 237:f3da66175598 | 360 | /* Check if there are still 16-bit data to program */ |
mbed_official | 237:f3da66175598 | 361 | if(pFlash.DataRemaining != 0) |
mbed_official | 237:f3da66175598 | 362 | { |
mbed_official | 237:f3da66175598 | 363 | /* Increment address to 16-bit */ |
mbed_official | 237:f3da66175598 | 364 | pFlash.Address += 2; |
mbed_official | 237:f3da66175598 | 365 | addresstmp = pFlash.Address; |
mbed_official | 237:f3da66175598 | 366 | |
mbed_official | 237:f3da66175598 | 367 | /* Shift to have next 16-bit data */ |
mbed_official | 237:f3da66175598 | 368 | pFlash.Data = (pFlash.Data >> 16); |
mbed_official | 237:f3da66175598 | 369 | |
mbed_official | 237:f3da66175598 | 370 | /*Program halfword (16-bit) at a specified address.*/ |
mbed_official | 237:f3da66175598 | 371 | FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data); |
mbed_official | 237:f3da66175598 | 372 | } |
mbed_official | 237:f3da66175598 | 373 | else |
mbed_official | 237:f3da66175598 | 374 | { |
mbed_official | 237:f3da66175598 | 375 | /*Program ended. Return the selected address*/ |
mbed_official | 237:f3da66175598 | 376 | /* FLASH EOP interrupt user callback */ |
mbed_official | 237:f3da66175598 | 377 | if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) |
mbed_official | 237:f3da66175598 | 378 | { |
mbed_official | 237:f3da66175598 | 379 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
mbed_official | 237:f3da66175598 | 380 | } |
mbed_official | 237:f3da66175598 | 381 | else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) |
mbed_official | 237:f3da66175598 | 382 | { |
mbed_official | 237:f3da66175598 | 383 | HAL_FLASH_EndOfOperationCallback(pFlash.Address-2); |
mbed_official | 237:f3da66175598 | 384 | } |
mbed_official | 237:f3da66175598 | 385 | else |
mbed_official | 237:f3da66175598 | 386 | { |
mbed_official | 237:f3da66175598 | 387 | HAL_FLASH_EndOfOperationCallback(pFlash.Address-6); |
mbed_official | 237:f3da66175598 | 388 | } |
mbed_official | 237:f3da66175598 | 389 | |
mbed_official | 237:f3da66175598 | 390 | /* Reset Address and stop Program procedure*/ |
mbed_official | 237:f3da66175598 | 391 | pFlash.Address = 0xFFFFFFFF; |
mbed_official | 237:f3da66175598 | 392 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 237:f3da66175598 | 393 | } |
mbed_official | 237:f3da66175598 | 394 | } |
mbed_official | 237:f3da66175598 | 395 | } |
mbed_official | 237:f3da66175598 | 396 | |
mbed_official | 237:f3da66175598 | 397 | /* Check FLASH operation error flags */ |
mbed_official | 237:f3da66175598 | 398 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR)) |
mbed_official | 237:f3da66175598 | 399 | { |
mbed_official | 237:f3da66175598 | 400 | /*Save the Error code*/ |
mbed_official | 237:f3da66175598 | 401 | FLASH_SetErrorCode(); |
mbed_official | 237:f3da66175598 | 402 | |
mbed_official | 237:f3da66175598 | 403 | /* FLASH error interrupt user callback */ |
mbed_official | 237:f3da66175598 | 404 | HAL_FLASH_OperationErrorCallback(pFlash.Address); |
mbed_official | 237:f3da66175598 | 405 | |
mbed_official | 237:f3da66175598 | 406 | /* Clear FLASH error pending bits */ |
mbed_official | 237:f3da66175598 | 407 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); |
mbed_official | 237:f3da66175598 | 408 | |
mbed_official | 237:f3da66175598 | 409 | /* Reset address and stop the procedure ongoing*/ |
mbed_official | 237:f3da66175598 | 410 | pFlash.Address = 0xFFFFFFFF; |
mbed_official | 237:f3da66175598 | 411 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 237:f3da66175598 | 412 | } |
mbed_official | 237:f3da66175598 | 413 | |
mbed_official | 237:f3da66175598 | 414 | if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE) |
mbed_official | 237:f3da66175598 | 415 | { |
mbed_official | 237:f3da66175598 | 416 | /* Disable End of FLASH Operation and Error source interrupts */ |
mbed_official | 237:f3da66175598 | 417 | __HAL_FLASH_DISABLE_IT((FLASH_IT_EOP | FLASH_IT_ERR)); |
mbed_official | 237:f3da66175598 | 418 | |
mbed_official | 237:f3da66175598 | 419 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 420 | __HAL_UNLOCK(&pFlash); |
mbed_official | 237:f3da66175598 | 421 | } |
mbed_official | 237:f3da66175598 | 422 | } |
mbed_official | 237:f3da66175598 | 423 | |
mbed_official | 237:f3da66175598 | 424 | |
mbed_official | 237:f3da66175598 | 425 | /** |
mbed_official | 237:f3da66175598 | 426 | * @brief FLASH end of operation interrupt callback |
mbed_official | 237:f3da66175598 | 427 | * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure |
mbed_official | 237:f3da66175598 | 428 | * - Mass Erase: No return value expected |
mbed_official | 237:f3da66175598 | 429 | * - Pages Erase: Address of the page which has been erased |
mbed_official | 237:f3da66175598 | 430 | * - Program: Address which was selected for data program |
mbed_official | 237:f3da66175598 | 431 | * @retval none |
mbed_official | 237:f3da66175598 | 432 | */ |
mbed_official | 237:f3da66175598 | 433 | __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue) |
mbed_official | 237:f3da66175598 | 434 | { |
mbed_official | 237:f3da66175598 | 435 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 436 | the HAL_FLASH_EndOfOperationCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 437 | */ |
mbed_official | 237:f3da66175598 | 438 | } |
mbed_official | 237:f3da66175598 | 439 | |
mbed_official | 237:f3da66175598 | 440 | /** |
mbed_official | 237:f3da66175598 | 441 | * @brief FLASH operation error interrupt callback |
mbed_official | 237:f3da66175598 | 442 | * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure |
mbed_official | 237:f3da66175598 | 443 | * - Mass Erase: No return value expected |
mbed_official | 237:f3da66175598 | 444 | * - Pages Erase: Address of the page which returned an error |
mbed_official | 237:f3da66175598 | 445 | * - Program: Address which was selected for data program |
mbed_official | 237:f3da66175598 | 446 | * @retval none |
mbed_official | 237:f3da66175598 | 447 | */ |
mbed_official | 237:f3da66175598 | 448 | __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue) |
mbed_official | 237:f3da66175598 | 449 | { |
mbed_official | 237:f3da66175598 | 450 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 451 | the HAL_FLASH_OperationErrorCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 452 | */ |
mbed_official | 237:f3da66175598 | 453 | } |
mbed_official | 237:f3da66175598 | 454 | |
mbed_official | 237:f3da66175598 | 455 | /** |
mbed_official | 237:f3da66175598 | 456 | * @} |
mbed_official | 237:f3da66175598 | 457 | */ |
mbed_official | 237:f3da66175598 | 458 | |
mbed_official | 237:f3da66175598 | 459 | /** @defgroup HAL_FLASH_Group3 Peripheral Control functions |
mbed_official | 237:f3da66175598 | 460 | * @brief management functions |
mbed_official | 237:f3da66175598 | 461 | * |
mbed_official | 237:f3da66175598 | 462 | @verbatim |
mbed_official | 237:f3da66175598 | 463 | =============================================================================== |
mbed_official | 237:f3da66175598 | 464 | ##### Peripheral Control functions ##### |
mbed_official | 237:f3da66175598 | 465 | =============================================================================== |
mbed_official | 237:f3da66175598 | 466 | [..] |
mbed_official | 237:f3da66175598 | 467 | This subsection provides a set of functions allowing to control the FLASH |
mbed_official | 237:f3da66175598 | 468 | memory operations. |
mbed_official | 237:f3da66175598 | 469 | |
mbed_official | 237:f3da66175598 | 470 | @endverbatim |
mbed_official | 237:f3da66175598 | 471 | * @{ |
mbed_official | 237:f3da66175598 | 472 | */ |
mbed_official | 237:f3da66175598 | 473 | |
mbed_official | 237:f3da66175598 | 474 | /** |
mbed_official | 237:f3da66175598 | 475 | * @brief Unlock the FLASH control register access |
mbed_official | 237:f3da66175598 | 476 | * @param None |
mbed_official | 237:f3da66175598 | 477 | * @retval HAL Status |
mbed_official | 237:f3da66175598 | 478 | */ |
mbed_official | 237:f3da66175598 | 479 | HAL_StatusTypeDef HAL_FLASH_Unlock(void) |
mbed_official | 237:f3da66175598 | 480 | { |
mbed_official | 237:f3da66175598 | 481 | if((READ_BIT(FLASH->CR, FLASH_CR_LOCK)) != RESET) |
mbed_official | 237:f3da66175598 | 482 | { |
mbed_official | 237:f3da66175598 | 483 | /* Authorize the FLASH Registers access */ |
mbed_official | 237:f3da66175598 | 484 | WRITE_REG(FLASH->KEYR, FLASH_KEY1); |
mbed_official | 237:f3da66175598 | 485 | WRITE_REG(FLASH->KEYR, FLASH_KEY2); |
mbed_official | 237:f3da66175598 | 486 | } |
mbed_official | 237:f3da66175598 | 487 | else |
mbed_official | 237:f3da66175598 | 488 | { |
mbed_official | 237:f3da66175598 | 489 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 490 | } |
mbed_official | 237:f3da66175598 | 491 | |
mbed_official | 237:f3da66175598 | 492 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 493 | } |
mbed_official | 237:f3da66175598 | 494 | |
mbed_official | 237:f3da66175598 | 495 | /** |
mbed_official | 237:f3da66175598 | 496 | * @brief Locks the FLASH control register access |
mbed_official | 237:f3da66175598 | 497 | * @param None |
mbed_official | 237:f3da66175598 | 498 | * @retval HAL Status |
mbed_official | 237:f3da66175598 | 499 | */ |
mbed_official | 237:f3da66175598 | 500 | HAL_StatusTypeDef HAL_FLASH_Lock(void) |
mbed_official | 237:f3da66175598 | 501 | { |
mbed_official | 237:f3da66175598 | 502 | /* Set the LOCK Bit to lock the FLASH Registers access */ |
mbed_official | 237:f3da66175598 | 503 | SET_BIT(FLASH->CR, FLASH_CR_LOCK); |
mbed_official | 237:f3da66175598 | 504 | |
mbed_official | 237:f3da66175598 | 505 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 506 | } |
mbed_official | 237:f3da66175598 | 507 | |
mbed_official | 237:f3da66175598 | 508 | |
mbed_official | 237:f3da66175598 | 509 | /** |
mbed_official | 237:f3da66175598 | 510 | * @brief Unlock the FLASH Option Control Registers access. |
mbed_official | 237:f3da66175598 | 511 | * @param None |
mbed_official | 237:f3da66175598 | 512 | * @retval HAL Status |
mbed_official | 237:f3da66175598 | 513 | */ |
mbed_official | 237:f3da66175598 | 514 | HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void) |
mbed_official | 237:f3da66175598 | 515 | { |
mbed_official | 237:f3da66175598 | 516 | if((READ_BIT(FLASH->CR, FLASH_CR_OPTWRE)) == RESET) |
mbed_official | 237:f3da66175598 | 517 | { |
mbed_official | 237:f3da66175598 | 518 | /* Authorizes the Option Byte register programming */ |
mbed_official | 237:f3da66175598 | 519 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1); |
mbed_official | 237:f3da66175598 | 520 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2); |
mbed_official | 237:f3da66175598 | 521 | } |
mbed_official | 237:f3da66175598 | 522 | else |
mbed_official | 237:f3da66175598 | 523 | { |
mbed_official | 237:f3da66175598 | 524 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 525 | } |
mbed_official | 237:f3da66175598 | 526 | |
mbed_official | 237:f3da66175598 | 527 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 528 | } |
mbed_official | 237:f3da66175598 | 529 | |
mbed_official | 237:f3da66175598 | 530 | /** |
mbed_official | 237:f3da66175598 | 531 | * @brief Lock the FLASH Option Control Registers access. |
mbed_official | 237:f3da66175598 | 532 | * @param None |
mbed_official | 237:f3da66175598 | 533 | * @retval HAL Status |
mbed_official | 237:f3da66175598 | 534 | */ |
mbed_official | 237:f3da66175598 | 535 | HAL_StatusTypeDef HAL_FLASH_OB_Lock(void) |
mbed_official | 237:f3da66175598 | 536 | { |
mbed_official | 237:f3da66175598 | 537 | /* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */ |
mbed_official | 237:f3da66175598 | 538 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE); |
mbed_official | 237:f3da66175598 | 539 | |
mbed_official | 237:f3da66175598 | 540 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 541 | } |
mbed_official | 237:f3da66175598 | 542 | |
mbed_official | 237:f3da66175598 | 543 | /** |
mbed_official | 237:f3da66175598 | 544 | * @brief Launch the option byte loading. |
mbed_official | 237:f3da66175598 | 545 | * @param None |
mbed_official | 237:f3da66175598 | 546 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 547 | */ |
mbed_official | 237:f3da66175598 | 548 | HAL_StatusTypeDef HAL_FLASH_OB_Launch(void) |
mbed_official | 237:f3da66175598 | 549 | { |
mbed_official | 237:f3da66175598 | 550 | /* Set the bit to force the option byte reloading */ |
mbed_official | 237:f3da66175598 | 551 | SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); |
mbed_official | 237:f3da66175598 | 552 | |
mbed_official | 237:f3da66175598 | 553 | /* Wait for last operation to be completed */ |
mbed_official | 237:f3da66175598 | 554 | return(FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 237:f3da66175598 | 555 | } |
mbed_official | 237:f3da66175598 | 556 | |
mbed_official | 237:f3da66175598 | 557 | /** |
mbed_official | 237:f3da66175598 | 558 | * @} |
mbed_official | 237:f3da66175598 | 559 | */ |
mbed_official | 237:f3da66175598 | 560 | |
mbed_official | 237:f3da66175598 | 561 | |
mbed_official | 237:f3da66175598 | 562 | /** @defgroup HAL_FLASH_Group4 Peripheral State functions |
mbed_official | 237:f3da66175598 | 563 | * @brief Peripheral State functions |
mbed_official | 237:f3da66175598 | 564 | * |
mbed_official | 237:f3da66175598 | 565 | @verbatim |
mbed_official | 237:f3da66175598 | 566 | =============================================================================== |
mbed_official | 237:f3da66175598 | 567 | ##### Peripheral State functions ##### |
mbed_official | 237:f3da66175598 | 568 | =============================================================================== |
mbed_official | 237:f3da66175598 | 569 | [..] |
mbed_official | 237:f3da66175598 | 570 | This subsection permit to get in run-time the status of the FLASH peripheral. |
mbed_official | 237:f3da66175598 | 571 | |
mbed_official | 237:f3da66175598 | 572 | @endverbatim |
mbed_official | 237:f3da66175598 | 573 | * @{ |
mbed_official | 237:f3da66175598 | 574 | */ |
mbed_official | 237:f3da66175598 | 575 | |
mbed_official | 237:f3da66175598 | 576 | /** |
mbed_official | 237:f3da66175598 | 577 | * @brief Get the specific FLASH error flag. |
mbed_official | 237:f3da66175598 | 578 | * @param None |
mbed_official | 237:f3da66175598 | 579 | * @retval FLASH_ErrorCode: The returned value can be: |
mbed_official | 237:f3da66175598 | 580 | * @arg FLASH_ERROR_PG: FLASH Programming error flag |
mbed_official | 237:f3da66175598 | 581 | * @arg FLASH_ERROR_WRP: FLASH Write protected error flag |
mbed_official | 237:f3da66175598 | 582 | */ |
mbed_official | 237:f3da66175598 | 583 | FLASH_ErrorTypeDef HAL_FLASH_GetError(void) |
mbed_official | 237:f3da66175598 | 584 | { |
mbed_official | 237:f3da66175598 | 585 | return pFlash.ErrorCode; |
mbed_official | 237:f3da66175598 | 586 | } |
mbed_official | 237:f3da66175598 | 587 | |
mbed_official | 237:f3da66175598 | 588 | /** |
mbed_official | 237:f3da66175598 | 589 | * @} |
mbed_official | 237:f3da66175598 | 590 | */ |
mbed_official | 237:f3da66175598 | 591 | |
mbed_official | 237:f3da66175598 | 592 | /** |
mbed_official | 237:f3da66175598 | 593 | * @brief Program a half-word (16-bit) at a specified address. |
mbed_official | 237:f3da66175598 | 594 | * @param Address: specifies the address to be programmed. |
mbed_official | 237:f3da66175598 | 595 | * @param Data: specifies the data to be programmed. |
mbed_official | 237:f3da66175598 | 596 | * @retval None |
mbed_official | 237:f3da66175598 | 597 | */ |
mbed_official | 237:f3da66175598 | 598 | static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 237:f3da66175598 | 599 | { |
mbed_official | 237:f3da66175598 | 600 | /* Clear pending flags (if any) */ |
mbed_official | 237:f3da66175598 | 601 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); |
mbed_official | 237:f3da66175598 | 602 | |
mbed_official | 237:f3da66175598 | 603 | /* Proceed to program the new data */ |
mbed_official | 237:f3da66175598 | 604 | SET_BIT(FLASH->CR, FLASH_CR_PG); |
mbed_official | 237:f3da66175598 | 605 | |
mbed_official | 237:f3da66175598 | 606 | *(__IO uint16_t*)Address = Data; |
mbed_official | 237:f3da66175598 | 607 | } |
mbed_official | 237:f3da66175598 | 608 | |
mbed_official | 237:f3da66175598 | 609 | /** |
mbed_official | 237:f3da66175598 | 610 | * @brief Wait for a FLASH operation to complete. |
mbed_official | 237:f3da66175598 | 611 | * @param Timeout: maximum flash operationtimeout |
mbed_official | 237:f3da66175598 | 612 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 237:f3da66175598 | 613 | */ |
mbed_official | 237:f3da66175598 | 614 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 615 | { |
mbed_official | 237:f3da66175598 | 616 | /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset. |
mbed_official | 237:f3da66175598 | 617 | Even if the FLASH operation fails, the BUSY flag will be reset and an error |
mbed_official | 237:f3da66175598 | 618 | flag will be set */ |
mbed_official | 237:f3da66175598 | 619 | |
mbed_official | 237:f3da66175598 | 620 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 621 | |
mbed_official | 237:f3da66175598 | 622 | while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) |
mbed_official | 237:f3da66175598 | 623 | { |
mbed_official | 237:f3da66175598 | 624 | if (Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 625 | { |
mbed_official | 237:f3da66175598 | 626 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 627 | { |
mbed_official | 237:f3da66175598 | 628 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 629 | } |
mbed_official | 237:f3da66175598 | 630 | } |
mbed_official | 237:f3da66175598 | 631 | } |
mbed_official | 237:f3da66175598 | 632 | |
mbed_official | 237:f3da66175598 | 633 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR)) |
mbed_official | 237:f3da66175598 | 634 | { |
mbed_official | 237:f3da66175598 | 635 | /*Save the error code*/ |
mbed_official | 237:f3da66175598 | 636 | FLASH_SetErrorCode(); |
mbed_official | 237:f3da66175598 | 637 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 638 | } |
mbed_official | 237:f3da66175598 | 639 | |
mbed_official | 237:f3da66175598 | 640 | /* If there is an error flag set */ |
mbed_official | 237:f3da66175598 | 641 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 642 | |
mbed_official | 237:f3da66175598 | 643 | } |
mbed_official | 237:f3da66175598 | 644 | |
mbed_official | 237:f3da66175598 | 645 | /** |
mbed_official | 237:f3da66175598 | 646 | * @brief Erase the specified FLASH memory page |
mbed_official | 237:f3da66175598 | 647 | * @param PageAddress: FLASH page to erase |
mbed_official | 237:f3da66175598 | 648 | * The value of this parameter depend on device used within the same series |
mbed_official | 237:f3da66175598 | 649 | * |
mbed_official | 237:f3da66175598 | 650 | * @retval None |
mbed_official | 237:f3da66175598 | 651 | */ |
mbed_official | 237:f3da66175598 | 652 | void FLASH_PageErase(uint32_t PageAddress) |
mbed_official | 237:f3da66175598 | 653 | { |
mbed_official | 237:f3da66175598 | 654 | /* Clear pending flags (if any) */ |
mbed_official | 237:f3da66175598 | 655 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); |
mbed_official | 237:f3da66175598 | 656 | |
mbed_official | 237:f3da66175598 | 657 | /* Proceed to erase the page */ |
mbed_official | 237:f3da66175598 | 658 | SET_BIT(FLASH->CR, FLASH_CR_PER); |
mbed_official | 237:f3da66175598 | 659 | WRITE_REG(FLASH->AR, PageAddress); |
mbed_official | 237:f3da66175598 | 660 | SET_BIT(FLASH->CR, FLASH_CR_STRT); |
mbed_official | 237:f3da66175598 | 661 | } |
mbed_official | 237:f3da66175598 | 662 | |
mbed_official | 237:f3da66175598 | 663 | /** |
mbed_official | 237:f3da66175598 | 664 | * @brief Set the specific FLASH error flag. |
mbed_official | 237:f3da66175598 | 665 | * @param None |
mbed_official | 237:f3da66175598 | 666 | * @retval None |
mbed_official | 237:f3da66175598 | 667 | */ |
mbed_official | 237:f3da66175598 | 668 | static void FLASH_SetErrorCode(void) |
mbed_official | 237:f3da66175598 | 669 | { |
mbed_official | 237:f3da66175598 | 670 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) |
mbed_official | 237:f3da66175598 | 671 | { |
mbed_official | 237:f3da66175598 | 672 | pFlash.ErrorCode = FLASH_ERROR_WRP; |
mbed_official | 237:f3da66175598 | 673 | } |
mbed_official | 237:f3da66175598 | 674 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR)) |
mbed_official | 237:f3da66175598 | 675 | { |
mbed_official | 237:f3da66175598 | 676 | pFlash.ErrorCode |= FLASH_ERROR_PG; |
mbed_official | 237:f3da66175598 | 677 | } |
mbed_official | 237:f3da66175598 | 678 | } |
mbed_official | 237:f3da66175598 | 679 | |
mbed_official | 237:f3da66175598 | 680 | /** |
mbed_official | 237:f3da66175598 | 681 | * @} |
mbed_official | 237:f3da66175598 | 682 | */ |
mbed_official | 237:f3da66175598 | 683 | |
mbed_official | 237:f3da66175598 | 684 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 685 | |
mbed_official | 237:f3da66175598 | 686 | /** |
mbed_official | 237:f3da66175598 | 687 | * @} |
mbed_official | 237:f3da66175598 | 688 | */ |
mbed_official | 237:f3da66175598 | 689 | |
mbed_official | 237:f3da66175598 | 690 | /** |
mbed_official | 237:f3da66175598 | 691 | * @} |
mbed_official | 237:f3da66175598 | 692 | */ |
mbed_official | 237:f3da66175598 | 693 | |
mbed_official | 237:f3da66175598 | 694 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |