mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

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

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

Import librarymbed

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

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 610:813dcc80987e 1 /**
mbed_official 610:813dcc80987e 2 ******************************************************************************
mbed_official 610:813dcc80987e 3 * @file stm32l4xx_hal_flash.c
mbed_official 610:813dcc80987e 4 * @author MCD Application Team
mbed_official 610:813dcc80987e 5 * @version V1.0.0
mbed_official 610:813dcc80987e 6 * @date 26-June-2015
mbed_official 610:813dcc80987e 7 * @brief FLASH HAL module driver.
mbed_official 610:813dcc80987e 8 * This file provides firmware functions to manage the following
mbed_official 610:813dcc80987e 9 * functionalities of the internal FLASH memory:
mbed_official 610:813dcc80987e 10 * + Program operations functions
mbed_official 610:813dcc80987e 11 * + Memory Control functions
mbed_official 610:813dcc80987e 12 * + Peripheral Errors functions
mbed_official 610:813dcc80987e 13 *
mbed_official 610:813dcc80987e 14 @verbatim
mbed_official 610:813dcc80987e 15 ==============================================================================
mbed_official 610:813dcc80987e 16 ##### FLASH peripheral features #####
mbed_official 610:813dcc80987e 17 ==============================================================================
mbed_official 610:813dcc80987e 18
mbed_official 610:813dcc80987e 19 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
mbed_official 610:813dcc80987e 20 to the Flash memory. It implements the erase and program Flash memory operations
mbed_official 610:813dcc80987e 21 and the read and write protection mechanisms.
mbed_official 610:813dcc80987e 22
mbed_official 610:813dcc80987e 23 [..] The Flash memory interface accelerates code execution with a system of instruction
mbed_official 610:813dcc80987e 24 prefetch and cache lines.
mbed_official 610:813dcc80987e 25
mbed_official 610:813dcc80987e 26 [..] The FLASH main features are:
mbed_official 610:813dcc80987e 27 (+) Flash memory read operations
mbed_official 610:813dcc80987e 28 (+) Flash memory program/erase operations
mbed_official 610:813dcc80987e 29 (+) Read / write protections
mbed_official 610:813dcc80987e 30 (+) Option bytes programming
mbed_official 610:813dcc80987e 31 (+) Prefetch on I-Code
mbed_official 610:813dcc80987e 32 (+) 32 cache lines of 4*64 bits on I-Code
mbed_official 610:813dcc80987e 33 (+) 8 cache lines of 4*64 bits on D-Code
mbed_official 610:813dcc80987e 34 (+) Error code correction (ECC) : Data in flash are 72-bits word
mbed_official 610:813dcc80987e 35 (8 bits added per double word)
mbed_official 610:813dcc80987e 36
mbed_official 610:813dcc80987e 37
mbed_official 610:813dcc80987e 38 ##### How to use this driver #####
mbed_official 610:813dcc80987e 39 ==============================================================================
mbed_official 610:813dcc80987e 40 [..]
mbed_official 610:813dcc80987e 41 This driver provides functions and macros to configure and program the FLASH
mbed_official 610:813dcc80987e 42 memory of all STM32L4xx devices.
mbed_official 610:813dcc80987e 43
mbed_official 610:813dcc80987e 44 (#) Flash Memory IO Programming functions:
mbed_official 610:813dcc80987e 45 (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
mbed_official 610:813dcc80987e 46 HAL_FLASH_Lock() functions
mbed_official 610:813dcc80987e 47 (++) Program functions: double word and fast program (full row programming)
mbed_official 610:813dcc80987e 48 (++) There Two modes of programming :
mbed_official 610:813dcc80987e 49 (+++) Polling mode using HAL_FLASH_Program() function
mbed_official 610:813dcc80987e 50 (+++) Interrupt mode using HAL_FLASH_Program_IT() function
mbed_official 610:813dcc80987e 51
mbed_official 610:813dcc80987e 52 (#) Interrupts and flags management functions :
mbed_official 610:813dcc80987e 53 (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
mbed_official 610:813dcc80987e 54 (++) Callback functions are called when the flash operations are finished :
mbed_official 610:813dcc80987e 55 HAL_FLASH_EndOfOperationCallback() when everything is ok, otherwise
mbed_official 610:813dcc80987e 56 HAL_FLASH_OperationErrorCallback()
mbed_official 610:813dcc80987e 57 (++) Get error flag status by calling HAL_GetError()
mbed_official 610:813dcc80987e 58
mbed_official 610:813dcc80987e 59 (#) Option bytes management functions :
mbed_official 610:813dcc80987e 60 (++) Lock and Unlock the option bytes using HAL_FLASH_OB_Unlock() and
mbed_official 610:813dcc80987e 61 HAL_FLASH_OB_Lock() functions
mbed_official 610:813dcc80987e 62 (++) Launch the reload of the option bytes using HAL_FLASH_Launch() function.
mbed_official 610:813dcc80987e 63 In this case, a reset is generated
mbed_official 610:813dcc80987e 64
mbed_official 610:813dcc80987e 65 [..]
mbed_official 610:813dcc80987e 66 In addition to these functions, this driver includes a set of macros allowing
mbed_official 610:813dcc80987e 67 to handle the following operations:
mbed_official 610:813dcc80987e 68 (+) Set the latency
mbed_official 610:813dcc80987e 69 (+) Enable/Disable the prefetch buffer
mbed_official 610:813dcc80987e 70 (+) Enable/Disable the Instruction cache and the Data cache
mbed_official 610:813dcc80987e 71 (+) Reset the Instruction cache and the Data cache
mbed_official 610:813dcc80987e 72 (+) Enable/Disable the Flash power-down during low-power run and sleep modes
mbed_official 610:813dcc80987e 73 (+) Enable/Disable the Flash interrupts
mbed_official 610:813dcc80987e 74 (+) Monitor the Flash flags status
mbed_official 610:813dcc80987e 75
mbed_official 610:813dcc80987e 76 @endverbatim
mbed_official 610:813dcc80987e 77 ******************************************************************************
mbed_official 610:813dcc80987e 78 * @attention
mbed_official 610:813dcc80987e 79 *
mbed_official 610:813dcc80987e 80 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 610:813dcc80987e 81 *
mbed_official 610:813dcc80987e 82 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 610:813dcc80987e 83 * are permitted provided that the following conditions are met:
mbed_official 610:813dcc80987e 84 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 610:813dcc80987e 85 * this list of conditions and the following disclaimer.
mbed_official 610:813dcc80987e 86 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 610:813dcc80987e 87 * this list of conditions and the following disclaimer in the documentation
mbed_official 610:813dcc80987e 88 * and/or other materials provided with the distribution.
mbed_official 610:813dcc80987e 89 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 610:813dcc80987e 90 * may be used to endorse or promote products derived from this software
mbed_official 610:813dcc80987e 91 * without specific prior written permission.
mbed_official 610:813dcc80987e 92 *
mbed_official 610:813dcc80987e 93 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 610:813dcc80987e 94 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 610:813dcc80987e 95 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 610:813dcc80987e 96 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 610:813dcc80987e 97 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 610:813dcc80987e 98 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 610:813dcc80987e 99 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 610:813dcc80987e 100 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 610:813dcc80987e 101 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 610:813dcc80987e 102 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 610:813dcc80987e 103 *
mbed_official 610:813dcc80987e 104 ******************************************************************************
mbed_official 610:813dcc80987e 105 */
mbed_official 610:813dcc80987e 106
mbed_official 610:813dcc80987e 107 /* Includes ------------------------------------------------------------------*/
mbed_official 610:813dcc80987e 108 #include "stm32l4xx_hal.h"
mbed_official 610:813dcc80987e 109
mbed_official 610:813dcc80987e 110 /** @addtogroup STM32L4xx_HAL_Driver
mbed_official 610:813dcc80987e 111 * @{
mbed_official 610:813dcc80987e 112 */
mbed_official 610:813dcc80987e 113
mbed_official 610:813dcc80987e 114 /** @defgroup FLASH FLASH
mbed_official 610:813dcc80987e 115 * @brief FLASH HAL module driver
mbed_official 610:813dcc80987e 116 * @{
mbed_official 610:813dcc80987e 117 */
mbed_official 610:813dcc80987e 118
mbed_official 610:813dcc80987e 119 #ifdef HAL_FLASH_MODULE_ENABLED
mbed_official 610:813dcc80987e 120
mbed_official 610:813dcc80987e 121 /* Private typedef -----------------------------------------------------------*/
mbed_official 610:813dcc80987e 122 /* Private defines -----------------------------------------------------------*/
mbed_official 610:813dcc80987e 123 /* Private macros ------------------------------------------------------------*/
mbed_official 610:813dcc80987e 124 /* Private variables ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 125 /** @defgroup FLASH_Private_Variables FLASH Private Variables
mbed_official 610:813dcc80987e 126 * @{
mbed_official 610:813dcc80987e 127 */
mbed_official 610:813dcc80987e 128 /**
mbed_official 610:813dcc80987e 129 * @brief Variable used for Program/Erase sectors under interruption
mbed_official 610:813dcc80987e 130 */
mbed_official 610:813dcc80987e 131 FLASH_ProcessTypeDef pFlash;
mbed_official 610:813dcc80987e 132 /**
mbed_official 610:813dcc80987e 133 * @}
mbed_official 610:813dcc80987e 134 */
mbed_official 610:813dcc80987e 135
mbed_official 610:813dcc80987e 136 /* Private function prototypes -----------------------------------------------*/
mbed_official 610:813dcc80987e 137 /** @defgroup FLASH_Private_Functions FLASH Private Functions
mbed_official 610:813dcc80987e 138 * @{
mbed_official 610:813dcc80987e 139 */
mbed_official 610:813dcc80987e 140 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
mbed_official 610:813dcc80987e 141 extern void FLASH_PageErase(uint32_t Page, uint32_t Banks);
mbed_official 610:813dcc80987e 142 extern void FLASH_FlushCaches(void);
mbed_official 610:813dcc80987e 143 static void FLASH_SetErrorCode(void);
mbed_official 610:813dcc80987e 144 static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data);
mbed_official 610:813dcc80987e 145 static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress);
mbed_official 610:813dcc80987e 146 /**
mbed_official 610:813dcc80987e 147 * @}
mbed_official 610:813dcc80987e 148 */
mbed_official 610:813dcc80987e 149
mbed_official 610:813dcc80987e 150 /* Exported functions --------------------------------------------------------*/
mbed_official 610:813dcc80987e 151 /** @defgroup FLASH_Exported_Functions FLASH Exported Functions
mbed_official 610:813dcc80987e 152 * @{
mbed_official 610:813dcc80987e 153 */
mbed_official 610:813dcc80987e 154
mbed_official 610:813dcc80987e 155 /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
mbed_official 610:813dcc80987e 156 * @brief Programming operation functions
mbed_official 610:813dcc80987e 157 *
mbed_official 610:813dcc80987e 158 @verbatim
mbed_official 610:813dcc80987e 159 ===============================================================================
mbed_official 610:813dcc80987e 160 ##### Programming operation functions #####
mbed_official 610:813dcc80987e 161 ===============================================================================
mbed_official 610:813dcc80987e 162 [..]
mbed_official 610:813dcc80987e 163 This subsection provides a set of functions allowing to manage the FLASH
mbed_official 610:813dcc80987e 164 program operations.
mbed_official 610:813dcc80987e 165
mbed_official 610:813dcc80987e 166 @endverbatim
mbed_official 610:813dcc80987e 167 * @{
mbed_official 610:813dcc80987e 168 */
mbed_official 610:813dcc80987e 169
mbed_official 610:813dcc80987e 170 /**
mbed_official 610:813dcc80987e 171 * @brief Program double word or fast program of a row at a specified address.
mbed_official 610:813dcc80987e 172 * @param TypeProgram: Indicate the way to program at a specified address.
mbed_official 610:813dcc80987e 173 * This parameter can be a value of @ref FLASH_Type_Program
mbed_official 610:813dcc80987e 174 * @param Address: specifies the address to be programmed.
mbed_official 610:813dcc80987e 175 * @param Data: specifies the data to be programmed
mbed_official 610:813dcc80987e 176 * This parameter is the data for the double word program and the address where
mbed_official 610:813dcc80987e 177 * are stored the data for the row fast program
mbed_official 610:813dcc80987e 178 *
mbed_official 610:813dcc80987e 179 * @retval HAL_StatusTypeDef HAL Status
mbed_official 610:813dcc80987e 180 */
mbed_official 610:813dcc80987e 181 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
mbed_official 610:813dcc80987e 182 {
mbed_official 610:813dcc80987e 183 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 610:813dcc80987e 184 uint32_t prog_bit = 0;
mbed_official 610:813dcc80987e 185
mbed_official 610:813dcc80987e 186 /* Process Locked */
mbed_official 610:813dcc80987e 187 __HAL_LOCK(&pFlash);
mbed_official 610:813dcc80987e 188
mbed_official 610:813dcc80987e 189 /* Check the parameters */
mbed_official 610:813dcc80987e 190 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
mbed_official 610:813dcc80987e 191
mbed_official 610:813dcc80987e 192 /* Wait for last operation to be completed */
mbed_official 610:813dcc80987e 193 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
mbed_official 610:813dcc80987e 194
mbed_official 610:813dcc80987e 195 if(status == HAL_OK)
mbed_official 610:813dcc80987e 196 {
mbed_official 610:813dcc80987e 197 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
mbed_official 610:813dcc80987e 198
mbed_official 610:813dcc80987e 199 if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
mbed_official 610:813dcc80987e 200 {
mbed_official 610:813dcc80987e 201 /* Program double-word (64-bit) at a specified address */
mbed_official 610:813dcc80987e 202 FLASH_Program_DoubleWord(Address, Data);
mbed_official 610:813dcc80987e 203 prog_bit = FLASH_CR_PG;
mbed_official 610:813dcc80987e 204 }
mbed_official 610:813dcc80987e 205 else if((TypeProgram == FLASH_TYPEPROGRAM_FAST) || (TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST))
mbed_official 610:813dcc80987e 206 {
mbed_official 610:813dcc80987e 207 /* Fast program a 32 row double-word (64-bit) at a specified address */
mbed_official 610:813dcc80987e 208 FLASH_Program_Fast(Address, (uint32_t)Data);
mbed_official 610:813dcc80987e 209
mbed_official 610:813dcc80987e 210 /* If it is the last row, the bit will be cleared at the end of the operation */
mbed_official 610:813dcc80987e 211 if(TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST)
mbed_official 610:813dcc80987e 212 {
mbed_official 610:813dcc80987e 213 prog_bit = FLASH_CR_FSTPG;
mbed_official 610:813dcc80987e 214 }
mbed_official 610:813dcc80987e 215 }
mbed_official 610:813dcc80987e 216
mbed_official 610:813dcc80987e 217 /* Wait for last operation to be completed */
mbed_official 610:813dcc80987e 218 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
mbed_official 610:813dcc80987e 219
mbed_official 610:813dcc80987e 220 /* If the program operation is completed, disable the PG or FSTPG Bit */
mbed_official 610:813dcc80987e 221 if (prog_bit != 0)
mbed_official 610:813dcc80987e 222 {
mbed_official 610:813dcc80987e 223 CLEAR_BIT(FLASH->CR, prog_bit);
mbed_official 610:813dcc80987e 224 }
mbed_official 610:813dcc80987e 225 }
mbed_official 610:813dcc80987e 226
mbed_official 610:813dcc80987e 227 /* Process Unlocked */
mbed_official 610:813dcc80987e 228 __HAL_UNLOCK(&pFlash);
mbed_official 610:813dcc80987e 229
mbed_official 610:813dcc80987e 230 return status;
mbed_official 610:813dcc80987e 231 }
mbed_official 610:813dcc80987e 232
mbed_official 610:813dcc80987e 233 /**
mbed_official 610:813dcc80987e 234 * @brief Program double word or fast program of a row at a specified address with interrupt enabled.
mbed_official 610:813dcc80987e 235 * @param TypeProgram: Indicate the way to program at a specified address.
mbed_official 610:813dcc80987e 236 * This parameter can be a value of @ref FLASH_Type_Program
mbed_official 610:813dcc80987e 237 * @param Address: specifies the address to be programmed.
mbed_official 610:813dcc80987e 238 * @param Data: specifies the data to be programmed
mbed_official 610:813dcc80987e 239 * This parameter is the data for the double word program and the address where
mbed_official 610:813dcc80987e 240 * are stored the data for the row fast program
mbed_official 610:813dcc80987e 241 *
mbed_official 610:813dcc80987e 242 * @retval HAL Status
mbed_official 610:813dcc80987e 243 */
mbed_official 610:813dcc80987e 244 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
mbed_official 610:813dcc80987e 245 {
mbed_official 610:813dcc80987e 246 HAL_StatusTypeDef status = HAL_OK;
mbed_official 610:813dcc80987e 247
mbed_official 610:813dcc80987e 248 /* Check the parameters */
mbed_official 610:813dcc80987e 249 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
mbed_official 610:813dcc80987e 250
mbed_official 610:813dcc80987e 251 /* Process Locked */
mbed_official 610:813dcc80987e 252 __HAL_LOCK(&pFlash);
mbed_official 610:813dcc80987e 253
mbed_official 610:813dcc80987e 254 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
mbed_official 610:813dcc80987e 255
mbed_official 610:813dcc80987e 256 /* Set internal variables used by the IRQ handler */
mbed_official 610:813dcc80987e 257 if(TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST)
mbed_official 610:813dcc80987e 258 {
mbed_official 610:813dcc80987e 259 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM_LAST;
mbed_official 610:813dcc80987e 260 }
mbed_official 610:813dcc80987e 261 else
mbed_official 610:813dcc80987e 262 {
mbed_official 610:813dcc80987e 263 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM;
mbed_official 610:813dcc80987e 264 }
mbed_official 610:813dcc80987e 265 pFlash.Address = Address;
mbed_official 610:813dcc80987e 266
mbed_official 610:813dcc80987e 267 /* Enable End of Operation and Error interrupts */
mbed_official 610:813dcc80987e 268 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
mbed_official 610:813dcc80987e 269
mbed_official 610:813dcc80987e 270 if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
mbed_official 610:813dcc80987e 271 {
mbed_official 610:813dcc80987e 272 /* Program double-word (64-bit) at a specified address */
mbed_official 610:813dcc80987e 273 FLASH_Program_DoubleWord(Address, Data);
mbed_official 610:813dcc80987e 274 }
mbed_official 610:813dcc80987e 275 else if((TypeProgram == FLASH_TYPEPROGRAM_FAST) || (TypeProgram == FLASH_TYPEPROGRAM_FAST_AND_LAST))
mbed_official 610:813dcc80987e 276 {
mbed_official 610:813dcc80987e 277 /* Fast program a 32 row double-word (64-bit) at a specified address */
mbed_official 610:813dcc80987e 278 FLASH_Program_Fast(Address, (uint32_t)Data);
mbed_official 610:813dcc80987e 279 }
mbed_official 610:813dcc80987e 280
mbed_official 610:813dcc80987e 281 return status;
mbed_official 610:813dcc80987e 282 }
mbed_official 610:813dcc80987e 283
mbed_official 610:813dcc80987e 284 /**
mbed_official 610:813dcc80987e 285 * @brief Handle FLASH interrupt request.
mbed_official 610:813dcc80987e 286 * @retval None
mbed_official 610:813dcc80987e 287 */
mbed_official 610:813dcc80987e 288 void HAL_FLASH_IRQHandler(void)
mbed_official 610:813dcc80987e 289 {
mbed_official 610:813dcc80987e 290 uint32_t tmp_page;
mbed_official 610:813dcc80987e 291
mbed_official 610:813dcc80987e 292 /* If the operation is completed, disable the PG, PNB, MER1, MER2 and PER Bit */
mbed_official 610:813dcc80987e 293 CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_MER1 | FLASH_CR_MER2 | FLASH_CR_PER | FLASH_CR_PNB));
mbed_official 610:813dcc80987e 294
mbed_official 610:813dcc80987e 295 /* Disable the FSTPG Bit only if it is the last row programmed */
mbed_official 610:813dcc80987e 296 if(pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM_LAST)
mbed_official 610:813dcc80987e 297 {
mbed_official 610:813dcc80987e 298 CLEAR_BIT(FLASH->CR, FLASH_CR_FSTPG);
mbed_official 610:813dcc80987e 299 }
mbed_official 610:813dcc80987e 300
mbed_official 610:813dcc80987e 301 /* Check FLASH operation error flags */
mbed_official 610:813dcc80987e 302 if((__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PROGERR)) ||
mbed_official 610:813dcc80987e 303 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR)) ||
mbed_official 610:813dcc80987e 304 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR)) ||
mbed_official 610:813dcc80987e 305 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_MISERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_FASTERR)) ||
mbed_official 610:813dcc80987e 306 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) ||
mbed_official 610:813dcc80987e 307 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_ECCD)))
mbed_official 610:813dcc80987e 308 {
mbed_official 610:813dcc80987e 309 /*Save the error code*/
mbed_official 610:813dcc80987e 310 FLASH_SetErrorCode();
mbed_official 610:813dcc80987e 311
mbed_official 610:813dcc80987e 312 /* FLASH error interrupt user callback */
mbed_official 610:813dcc80987e 313 if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGE_ERASE)
mbed_official 610:813dcc80987e 314 {
mbed_official 610:813dcc80987e 315 HAL_FLASH_EndOfOperationCallback(pFlash.Page);
mbed_official 610:813dcc80987e 316 }
mbed_official 610:813dcc80987e 317 else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASS_ERASE)
mbed_official 610:813dcc80987e 318 {
mbed_official 610:813dcc80987e 319 HAL_FLASH_EndOfOperationCallback(pFlash.Bank);
mbed_official 610:813dcc80987e 320 }
mbed_official 610:813dcc80987e 321 else if((pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM) ||
mbed_official 610:813dcc80987e 322 (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM_LAST))
mbed_official 610:813dcc80987e 323 {
mbed_official 610:813dcc80987e 324 HAL_FLASH_OperationErrorCallback(pFlash.Address);
mbed_official 610:813dcc80987e 325 }
mbed_official 610:813dcc80987e 326
mbed_official 610:813dcc80987e 327 HAL_FLASH_OperationErrorCallback(pFlash.Address);
mbed_official 610:813dcc80987e 328
mbed_official 610:813dcc80987e 329 /*Stop the procedure ongoing*/
mbed_official 610:813dcc80987e 330 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
mbed_official 610:813dcc80987e 331 }
mbed_official 610:813dcc80987e 332
mbed_official 610:813dcc80987e 333 /* Check FLASH End of Operation flag */
mbed_official 610:813dcc80987e 334 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
mbed_official 610:813dcc80987e 335 {
mbed_official 610:813dcc80987e 336 /* Clear FLASH End of Operation pending bit */
mbed_official 610:813dcc80987e 337 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
mbed_official 610:813dcc80987e 338
mbed_official 610:813dcc80987e 339 if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGE_ERASE)
mbed_official 610:813dcc80987e 340 {
mbed_official 610:813dcc80987e 341 /* Nb of pages to erased can be decreased */
mbed_official 610:813dcc80987e 342 pFlash.NbPagesToErase--;
mbed_official 610:813dcc80987e 343
mbed_official 610:813dcc80987e 344 /* Check if there are still pages to erase*/
mbed_official 610:813dcc80987e 345 if(pFlash.NbPagesToErase != 0)
mbed_official 610:813dcc80987e 346 {
mbed_official 610:813dcc80987e 347 /* Indicate user which page has been erased*/
mbed_official 610:813dcc80987e 348 HAL_FLASH_EndOfOperationCallback(pFlash.Page);
mbed_official 610:813dcc80987e 349
mbed_official 610:813dcc80987e 350 /* Increment page number */
mbed_official 610:813dcc80987e 351 pFlash.Page++;
mbed_official 610:813dcc80987e 352 tmp_page = pFlash.Page;
mbed_official 610:813dcc80987e 353 FLASH_PageErase(tmp_page, pFlash.Bank);
mbed_official 610:813dcc80987e 354 }
mbed_official 610:813dcc80987e 355 else
mbed_official 610:813dcc80987e 356 {
mbed_official 610:813dcc80987e 357 /* No more pages to Erase */
mbed_official 610:813dcc80987e 358 /* Reset Address and stop Erase pages procedure */
mbed_official 610:813dcc80987e 359 pFlash.Page = 0xFFFFFFFF;
mbed_official 610:813dcc80987e 360 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
mbed_official 610:813dcc80987e 361
mbed_official 610:813dcc80987e 362 /* Flush the caches to be sure of the data consistency */
mbed_official 610:813dcc80987e 363 FLASH_FlushCaches() ;
mbed_official 610:813dcc80987e 364
mbed_official 610:813dcc80987e 365 /* FLASH EOP interrupt user callback */
mbed_official 610:813dcc80987e 366 HAL_FLASH_EndOfOperationCallback(pFlash.Page);
mbed_official 610:813dcc80987e 367 }
mbed_official 610:813dcc80987e 368 }
mbed_official 610:813dcc80987e 369 else
mbed_official 610:813dcc80987e 370 {
mbed_official 610:813dcc80987e 371 if(pFlash.ProcedureOnGoing == FLASH_PROC_MASS_ERASE)
mbed_official 610:813dcc80987e 372 {
mbed_official 610:813dcc80987e 373 /* MassErase ended. Return the selected bank */
mbed_official 610:813dcc80987e 374 /* Flush the caches to be sure of the data consistency */
mbed_official 610:813dcc80987e 375 FLASH_FlushCaches() ;
mbed_official 610:813dcc80987e 376
mbed_official 610:813dcc80987e 377 /* FLASH EOP interrupt user callback */
mbed_official 610:813dcc80987e 378 HAL_FLASH_EndOfOperationCallback(pFlash.Bank);
mbed_official 610:813dcc80987e 379 }
mbed_official 610:813dcc80987e 380 else if((pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM) ||
mbed_official 610:813dcc80987e 381 (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM_LAST))
mbed_official 610:813dcc80987e 382 {
mbed_official 610:813dcc80987e 383 /* Program ended. Return the selected address */
mbed_official 610:813dcc80987e 384 /* FLASH EOP interrupt user callback */
mbed_official 610:813dcc80987e 385 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
mbed_official 610:813dcc80987e 386 }
mbed_official 610:813dcc80987e 387
mbed_official 610:813dcc80987e 388 /*Clear the procedure ongoing*/
mbed_official 610:813dcc80987e 389 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
mbed_official 610:813dcc80987e 390 }
mbed_official 610:813dcc80987e 391 }
mbed_official 610:813dcc80987e 392
mbed_official 610:813dcc80987e 393 if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
mbed_official 610:813dcc80987e 394 {
mbed_official 610:813dcc80987e 395 /* Disable End of Operation and Error interrupts */
mbed_official 610:813dcc80987e 396 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
mbed_official 610:813dcc80987e 397
mbed_official 610:813dcc80987e 398 /* Process Unlocked */
mbed_official 610:813dcc80987e 399 __HAL_UNLOCK(&pFlash);
mbed_official 610:813dcc80987e 400 }
mbed_official 610:813dcc80987e 401 }
mbed_official 610:813dcc80987e 402
mbed_official 610:813dcc80987e 403 /**
mbed_official 610:813dcc80987e 404 * @brief FLASH end of operation interrupt callback.
mbed_official 610:813dcc80987e 405 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
mbed_official 610:813dcc80987e 406 * Mass Erase: Bank number which has been requested to erase
mbed_official 610:813dcc80987e 407 * Page Erase: Page which has been erased
mbed_official 610:813dcc80987e 408 * (if 0xFFFFFFFF, it means that all the selected pages have been erased)
mbed_official 610:813dcc80987e 409 * Program: Address which was selected for data program
mbed_official 610:813dcc80987e 410 * @retval None
mbed_official 610:813dcc80987e 411 */
mbed_official 610:813dcc80987e 412 __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
mbed_official 610:813dcc80987e 413 {
mbed_official 610:813dcc80987e 414 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 415 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
mbed_official 610:813dcc80987e 416 */
mbed_official 610:813dcc80987e 417 }
mbed_official 610:813dcc80987e 418
mbed_official 610:813dcc80987e 419 /**
mbed_official 610:813dcc80987e 420 * @brief FLASH operation error interrupt callback.
mbed_official 610:813dcc80987e 421 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
mbed_official 610:813dcc80987e 422 * Mass Erase: Bank number which has been requested to erase
mbed_official 610:813dcc80987e 423 * Page Erase: Page number which returned an error
mbed_official 610:813dcc80987e 424 * Program: Address which was selected for data program
mbed_official 610:813dcc80987e 425 * @retval None
mbed_official 610:813dcc80987e 426 */
mbed_official 610:813dcc80987e 427 __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
mbed_official 610:813dcc80987e 428 {
mbed_official 610:813dcc80987e 429 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 430 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
mbed_official 610:813dcc80987e 431 */
mbed_official 610:813dcc80987e 432 }
mbed_official 610:813dcc80987e 433
mbed_official 610:813dcc80987e 434 /**
mbed_official 610:813dcc80987e 435 * @}
mbed_official 610:813dcc80987e 436 */
mbed_official 610:813dcc80987e 437
mbed_official 610:813dcc80987e 438 /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
mbed_official 610:813dcc80987e 439 * @brief Management functions
mbed_official 610:813dcc80987e 440 *
mbed_official 610:813dcc80987e 441 @verbatim
mbed_official 610:813dcc80987e 442 ===============================================================================
mbed_official 610:813dcc80987e 443 ##### Peripheral Control functions #####
mbed_official 610:813dcc80987e 444 ===============================================================================
mbed_official 610:813dcc80987e 445 [..]
mbed_official 610:813dcc80987e 446 This subsection provides a set of functions allowing to control the FLASH
mbed_official 610:813dcc80987e 447 memory operations.
mbed_official 610:813dcc80987e 448
mbed_official 610:813dcc80987e 449 @endverbatim
mbed_official 610:813dcc80987e 450 * @{
mbed_official 610:813dcc80987e 451 */
mbed_official 610:813dcc80987e 452
mbed_official 610:813dcc80987e 453 /**
mbed_official 610:813dcc80987e 454 * @brief Unlock the FLASH control register access.
mbed_official 610:813dcc80987e 455 * @retval HAL Status
mbed_official 610:813dcc80987e 456 */
mbed_official 610:813dcc80987e 457 HAL_StatusTypeDef HAL_FLASH_Unlock(void)
mbed_official 610:813dcc80987e 458 {
mbed_official 610:813dcc80987e 459 if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
mbed_official 610:813dcc80987e 460 {
mbed_official 610:813dcc80987e 461 /* Authorize the FLASH Registers access */
mbed_official 610:813dcc80987e 462 WRITE_REG(FLASH->KEYR, FLASH_KEY1);
mbed_official 610:813dcc80987e 463 WRITE_REG(FLASH->KEYR, FLASH_KEY2);
mbed_official 610:813dcc80987e 464 }
mbed_official 610:813dcc80987e 465 else
mbed_official 610:813dcc80987e 466 {
mbed_official 610:813dcc80987e 467 return HAL_ERROR;
mbed_official 610:813dcc80987e 468 }
mbed_official 610:813dcc80987e 469
mbed_official 610:813dcc80987e 470 return HAL_OK;
mbed_official 610:813dcc80987e 471 }
mbed_official 610:813dcc80987e 472
mbed_official 610:813dcc80987e 473 /**
mbed_official 610:813dcc80987e 474 * @brief Lock the FLASH control register access.
mbed_official 610:813dcc80987e 475 * @retval HAL Status
mbed_official 610:813dcc80987e 476 */
mbed_official 610:813dcc80987e 477 HAL_StatusTypeDef HAL_FLASH_Lock(void)
mbed_official 610:813dcc80987e 478 {
mbed_official 610:813dcc80987e 479 /* Set the LOCK Bit to lock the FLASH Registers access */
mbed_official 610:813dcc80987e 480 SET_BIT(FLASH->CR, FLASH_CR_LOCK);
mbed_official 610:813dcc80987e 481
mbed_official 610:813dcc80987e 482 return HAL_OK;
mbed_official 610:813dcc80987e 483 }
mbed_official 610:813dcc80987e 484
mbed_official 610:813dcc80987e 485 /**
mbed_official 610:813dcc80987e 486 * @brief Unlock the FLASH Option Bytes Registers access.
mbed_official 610:813dcc80987e 487 * @retval HAL Status
mbed_official 610:813dcc80987e 488 */
mbed_official 610:813dcc80987e 489 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
mbed_official 610:813dcc80987e 490 {
mbed_official 610:813dcc80987e 491 if(READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != RESET)
mbed_official 610:813dcc80987e 492 {
mbed_official 610:813dcc80987e 493 /* Authorizes the Option Byte register programming */
mbed_official 610:813dcc80987e 494 WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
mbed_official 610:813dcc80987e 495 WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
mbed_official 610:813dcc80987e 496 }
mbed_official 610:813dcc80987e 497 else
mbed_official 610:813dcc80987e 498 {
mbed_official 610:813dcc80987e 499 return HAL_ERROR;
mbed_official 610:813dcc80987e 500 }
mbed_official 610:813dcc80987e 501
mbed_official 610:813dcc80987e 502 return HAL_OK;
mbed_official 610:813dcc80987e 503 }
mbed_official 610:813dcc80987e 504
mbed_official 610:813dcc80987e 505 /**
mbed_official 610:813dcc80987e 506 * @brief Lock the FLASH Option Bytes Registers access.
mbed_official 610:813dcc80987e 507 * @retval HAL Status
mbed_official 610:813dcc80987e 508 */
mbed_official 610:813dcc80987e 509 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
mbed_official 610:813dcc80987e 510 {
mbed_official 610:813dcc80987e 511 /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
mbed_official 610:813dcc80987e 512 SET_BIT(FLASH->CR, FLASH_CR_OPTLOCK);
mbed_official 610:813dcc80987e 513
mbed_official 610:813dcc80987e 514 return HAL_OK;
mbed_official 610:813dcc80987e 515 }
mbed_official 610:813dcc80987e 516
mbed_official 610:813dcc80987e 517 /**
mbed_official 610:813dcc80987e 518 * @brief Launch the option byte loading.
mbed_official 610:813dcc80987e 519 * @retval HAL Status
mbed_official 610:813dcc80987e 520 */
mbed_official 610:813dcc80987e 521 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
mbed_official 610:813dcc80987e 522 {
mbed_official 610:813dcc80987e 523 /* Set the bit to force the option byte reloading */
mbed_official 610:813dcc80987e 524 SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
mbed_official 610:813dcc80987e 525
mbed_official 610:813dcc80987e 526 /* Wait for last operation to be completed */
mbed_official 610:813dcc80987e 527 return(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE));
mbed_official 610:813dcc80987e 528 }
mbed_official 610:813dcc80987e 529
mbed_official 610:813dcc80987e 530 /**
mbed_official 610:813dcc80987e 531 * @}
mbed_official 610:813dcc80987e 532 */
mbed_official 610:813dcc80987e 533
mbed_official 610:813dcc80987e 534 /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
mbed_official 610:813dcc80987e 535 * @brief Peripheral Errors functions
mbed_official 610:813dcc80987e 536 *
mbed_official 610:813dcc80987e 537 @verbatim
mbed_official 610:813dcc80987e 538 ===============================================================================
mbed_official 610:813dcc80987e 539 ##### Peripheral Errors functions #####
mbed_official 610:813dcc80987e 540 ===============================================================================
mbed_official 610:813dcc80987e 541 [..]
mbed_official 610:813dcc80987e 542 This subsection permits to get in run-time Errors of the FLASH peripheral.
mbed_official 610:813dcc80987e 543
mbed_official 610:813dcc80987e 544 @endverbatim
mbed_official 610:813dcc80987e 545 * @{
mbed_official 610:813dcc80987e 546 */
mbed_official 610:813dcc80987e 547
mbed_official 610:813dcc80987e 548 /**
mbed_official 610:813dcc80987e 549 * @brief Get the specific FLASH error flag.
mbed_official 610:813dcc80987e 550 * @retval FLASH_ErrorCode: The returned value can be:
mbed_official 610:813dcc80987e 551 * @arg HAL_FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP)
mbed_official 610:813dcc80987e 552 * @arg HAL_FLASH_ERROR_PGS: FLASH Programming Sequence error flag
mbed_official 610:813dcc80987e 553 * @arg HAL_FLASH_ERROR_PGP: FLASH Programming Parallelism error flag
mbed_official 610:813dcc80987e 554 * @arg HAL_FLASH_ERROR_PGA: FLASH Programming Alignment error flag
mbed_official 610:813dcc80987e 555 * @arg HAL_FLASH_ERROR_WRP: FLASH Write protected error flag
mbed_official 610:813dcc80987e 556 * @arg HAL_FLASH_ERROR_OPERATION: FLASH operation Error flag
mbed_official 610:813dcc80987e 557 * @arg HAL_FLASH_ERROR_NONE: No error set
mbed_official 610:813dcc80987e 558 * @arg HAL_FLASH_ERROR_OP: FLASH Operation error
mbed_official 610:813dcc80987e 559 * @arg HAL_FLASH_ERROR_PROG: FLASH Programming error
mbed_official 610:813dcc80987e 560 * @arg HAL_FLASH_ERROR_WRP: FLASH Write protection error
mbed_official 610:813dcc80987e 561 * @arg HAL_FLASH_ERROR_PGA: FLASH Programming alignment error
mbed_official 610:813dcc80987e 562 * @arg HAL_FLASH_ERROR_SIZ: FLASH Size error
mbed_official 610:813dcc80987e 563 * @arg HAL_FLASH_ERROR_PGS: FLASH Programming sequence error
mbed_official 610:813dcc80987e 564 * @arg HAL_FLASH_ERROR_MIS: FLASH Fast programming data miss error
mbed_official 610:813dcc80987e 565 * @arg HAL_FLASH_ERROR_FAST: FLASH Fast programming error
mbed_official 610:813dcc80987e 566 * @arg HAL_FLASH_ERROR_RD: FLASH PCROP read error
mbed_official 610:813dcc80987e 567 * @arg HAL_FLASH_ERROR_OPTV: FLASH Option validity error
mbed_official 610:813dcc80987e 568 * @arg HAL_FLASH_ERROR_ECCD: FLASH two ECC errors have been detected
mbed_official 610:813dcc80987e 569 */
mbed_official 610:813dcc80987e 570 uint32_t HAL_FLASH_GetError(void)
mbed_official 610:813dcc80987e 571 {
mbed_official 610:813dcc80987e 572 return pFlash.ErrorCode;
mbed_official 610:813dcc80987e 573 }
mbed_official 610:813dcc80987e 574
mbed_official 610:813dcc80987e 575 /**
mbed_official 610:813dcc80987e 576 * @}
mbed_official 610:813dcc80987e 577 */
mbed_official 610:813dcc80987e 578
mbed_official 610:813dcc80987e 579 /**
mbed_official 610:813dcc80987e 580 * @}
mbed_official 610:813dcc80987e 581 */
mbed_official 610:813dcc80987e 582
mbed_official 610:813dcc80987e 583 /* Private functions ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 584
mbed_official 610:813dcc80987e 585 /** @addtogroup FLASH_Private_Functions
mbed_official 610:813dcc80987e 586 * @{
mbed_official 610:813dcc80987e 587 */
mbed_official 610:813dcc80987e 588
mbed_official 610:813dcc80987e 589 /**
mbed_official 610:813dcc80987e 590 * @brief Wait for a FLASH operation to complete.
mbed_official 610:813dcc80987e 591 * @param Timeout: maximum flash operation timeout
mbed_official 610:813dcc80987e 592 * @retval HAL_StatusTypeDef HAL Status
mbed_official 610:813dcc80987e 593 */
mbed_official 610:813dcc80987e 594 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
mbed_official 610:813dcc80987e 595 {
mbed_official 610:813dcc80987e 596 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
mbed_official 610:813dcc80987e 597 Even if the FLASH operation fails, the BUSY flag will be reset and an error
mbed_official 610:813dcc80987e 598 flag will be set */
mbed_official 610:813dcc80987e 599
mbed_official 610:813dcc80987e 600 uint32_t timeout = HAL_GetTick() + Timeout;
mbed_official 610:813dcc80987e 601
mbed_official 610:813dcc80987e 602 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
mbed_official 610:813dcc80987e 603 {
mbed_official 610:813dcc80987e 604 if(Timeout != HAL_MAX_DELAY)
mbed_official 610:813dcc80987e 605 {
mbed_official 610:813dcc80987e 606 if(HAL_GetTick() >= timeout)
mbed_official 610:813dcc80987e 607 {
mbed_official 610:813dcc80987e 608 return HAL_TIMEOUT;
mbed_official 610:813dcc80987e 609 }
mbed_official 610:813dcc80987e 610 }
mbed_official 610:813dcc80987e 611 }
mbed_official 610:813dcc80987e 612
mbed_official 610:813dcc80987e 613 if((__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PROGERR)) ||
mbed_official 610:813dcc80987e 614 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR)) ||
mbed_official 610:813dcc80987e 615 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR)) ||
mbed_official 610:813dcc80987e 616 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_MISERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_FASTERR)) ||
mbed_official 610:813dcc80987e 617 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) ||
mbed_official 610:813dcc80987e 618 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_ECCD)))
mbed_official 610:813dcc80987e 619 {
mbed_official 610:813dcc80987e 620 /*Save the error code*/
mbed_official 610:813dcc80987e 621 FLASH_SetErrorCode();
mbed_official 610:813dcc80987e 622
mbed_official 610:813dcc80987e 623 return HAL_ERROR;
mbed_official 610:813dcc80987e 624 }
mbed_official 610:813dcc80987e 625
mbed_official 610:813dcc80987e 626 /* Check FLASH End of Operation flag */
mbed_official 610:813dcc80987e 627 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
mbed_official 610:813dcc80987e 628 {
mbed_official 610:813dcc80987e 629 /* Clear FLASH End of Operation pending bit */
mbed_official 610:813dcc80987e 630 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
mbed_official 610:813dcc80987e 631 }
mbed_official 610:813dcc80987e 632
mbed_official 610:813dcc80987e 633 /* If there is an error flag set */
mbed_official 610:813dcc80987e 634 return HAL_OK;
mbed_official 610:813dcc80987e 635 }
mbed_official 610:813dcc80987e 636
mbed_official 610:813dcc80987e 637 /**
mbed_official 610:813dcc80987e 638 * @brief Set the specific FLASH error flag.
mbed_official 610:813dcc80987e 639 * @retval None
mbed_official 610:813dcc80987e 640 */
mbed_official 610:813dcc80987e 641 static void FLASH_SetErrorCode(void)
mbed_official 610:813dcc80987e 642 {
mbed_official 610:813dcc80987e 643 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR))
mbed_official 610:813dcc80987e 644 {
mbed_official 610:813dcc80987e 645 pFlash.ErrorCode |= HAL_FLASH_ERROR_OP;
mbed_official 610:813dcc80987e 646 }
mbed_official 610:813dcc80987e 647
mbed_official 610:813dcc80987e 648 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PROGERR))
mbed_official 610:813dcc80987e 649 {
mbed_official 610:813dcc80987e 650 pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
mbed_official 610:813dcc80987e 651 }
mbed_official 610:813dcc80987e 652
mbed_official 610:813dcc80987e 653 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
mbed_official 610:813dcc80987e 654 {
mbed_official 610:813dcc80987e 655 pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
mbed_official 610:813dcc80987e 656 }
mbed_official 610:813dcc80987e 657
mbed_official 610:813dcc80987e 658 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR))
mbed_official 610:813dcc80987e 659 {
mbed_official 610:813dcc80987e 660 pFlash.ErrorCode |= HAL_FLASH_ERROR_PGA;
mbed_official 610:813dcc80987e 661 }
mbed_official 610:813dcc80987e 662
mbed_official 610:813dcc80987e 663 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR))
mbed_official 610:813dcc80987e 664 {
mbed_official 610:813dcc80987e 665 pFlash.ErrorCode |= HAL_FLASH_ERROR_SIZ;
mbed_official 610:813dcc80987e 666 }
mbed_official 610:813dcc80987e 667
mbed_official 610:813dcc80987e 668 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR))
mbed_official 610:813dcc80987e 669 {
mbed_official 610:813dcc80987e 670 pFlash.ErrorCode |= HAL_FLASH_ERROR_PGS;
mbed_official 610:813dcc80987e 671 }
mbed_official 610:813dcc80987e 672
mbed_official 610:813dcc80987e 673 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_MISERR))
mbed_official 610:813dcc80987e 674 {
mbed_official 610:813dcc80987e 675 pFlash.ErrorCode |= HAL_FLASH_ERROR_MIS;
mbed_official 610:813dcc80987e 676 }
mbed_official 610:813dcc80987e 677
mbed_official 610:813dcc80987e 678 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_FASTERR))
mbed_official 610:813dcc80987e 679 {
mbed_official 610:813dcc80987e 680 pFlash.ErrorCode |= HAL_FLASH_ERROR_FAST;
mbed_official 610:813dcc80987e 681 }
mbed_official 610:813dcc80987e 682
mbed_official 610:813dcc80987e 683 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR))
mbed_official 610:813dcc80987e 684 {
mbed_official 610:813dcc80987e 685 pFlash.ErrorCode |= HAL_FLASH_ERROR_RD;
mbed_official 610:813dcc80987e 686 }
mbed_official 610:813dcc80987e 687
mbed_official 610:813dcc80987e 688 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
mbed_official 610:813dcc80987e 689 {
mbed_official 610:813dcc80987e 690 pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
mbed_official 610:813dcc80987e 691 }
mbed_official 610:813dcc80987e 692
mbed_official 610:813dcc80987e 693 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ECCD))
mbed_official 610:813dcc80987e 694 {
mbed_official 610:813dcc80987e 695 pFlash.ErrorCode |= HAL_FLASH_ERROR_ECCD;
mbed_official 610:813dcc80987e 696 }
mbed_official 610:813dcc80987e 697
mbed_official 610:813dcc80987e 698 /* Clear error programming flags */
mbed_official 610:813dcc80987e 699 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
mbed_official 610:813dcc80987e 700 }
mbed_official 610:813dcc80987e 701
mbed_official 610:813dcc80987e 702 /**
mbed_official 610:813dcc80987e 703 * @brief Program double-word (64-bit) at a specified address.
mbed_official 610:813dcc80987e 704 * @param Address: specifies the address to be programmed.
mbed_official 610:813dcc80987e 705 * @param Data: specifies the data to be programmed.
mbed_official 610:813dcc80987e 706 * @retval None
mbed_official 610:813dcc80987e 707 */
mbed_official 610:813dcc80987e 708 static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
mbed_official 610:813dcc80987e 709 {
mbed_official 610:813dcc80987e 710 /* Check the parameters */
mbed_official 610:813dcc80987e 711 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 610:813dcc80987e 712
mbed_official 610:813dcc80987e 713 /* Set PG bit */
mbed_official 610:813dcc80987e 714 SET_BIT(FLASH->CR, FLASH_CR_PG);
mbed_official 610:813dcc80987e 715
mbed_official 610:813dcc80987e 716 /* Program the double word */
mbed_official 610:813dcc80987e 717 *(__IO uint32_t*)Address = (uint32_t)Data;
mbed_official 610:813dcc80987e 718 *(__IO uint32_t*)(Address+4) = (uint32_t)(Data >> 32);
mbed_official 610:813dcc80987e 719 }
mbed_official 610:813dcc80987e 720
mbed_official 610:813dcc80987e 721 /**
mbed_official 610:813dcc80987e 722 * @brief Fast program a 32 row double-word (64-bit) at a specified address.
mbed_official 610:813dcc80987e 723 * @param Address: specifies the address to be programmed.
mbed_official 610:813dcc80987e 724 * @param DataAddress: specifies the address where the data are stored.
mbed_official 610:813dcc80987e 725 * @retval None
mbed_official 610:813dcc80987e 726 */
mbed_official 610:813dcc80987e 727 static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress)
mbed_official 610:813dcc80987e 728 {
mbed_official 610:813dcc80987e 729 uint8_t row_index = 32;
mbed_official 610:813dcc80987e 730 __IO uint64_t *dest_addr = (__IO uint64_t*)Address;
mbed_official 610:813dcc80987e 731 __IO uint64_t *src_addr = (__IO uint64_t*)DataAddress;
mbed_official 610:813dcc80987e 732
mbed_official 610:813dcc80987e 733 /* Check the parameters */
mbed_official 610:813dcc80987e 734 assert_param(IS_FLASH_MAIN_MEM_ADDRESS(Address));
mbed_official 610:813dcc80987e 735
mbed_official 610:813dcc80987e 736 /* Set FSTPG bit */
mbed_official 610:813dcc80987e 737 SET_BIT(FLASH->CR, FLASH_CR_FSTPG);
mbed_official 610:813dcc80987e 738
mbed_official 610:813dcc80987e 739 /* Disable interrupts to avoid any interruption during the loop */
mbed_official 610:813dcc80987e 740 __disable_irq();
mbed_official 610:813dcc80987e 741
mbed_official 610:813dcc80987e 742 /* Program the 32 double word */
mbed_official 610:813dcc80987e 743 do
mbed_official 610:813dcc80987e 744 {
mbed_official 610:813dcc80987e 745 *dest_addr++ = *src_addr++;
mbed_official 610:813dcc80987e 746 } while (--row_index != 0);
mbed_official 610:813dcc80987e 747
mbed_official 610:813dcc80987e 748 /* Re-enable the interrupts */
mbed_official 610:813dcc80987e 749 __enable_irq();
mbed_official 610:813dcc80987e 750 }
mbed_official 610:813dcc80987e 751
mbed_official 610:813dcc80987e 752 /**
mbed_official 610:813dcc80987e 753 * @}
mbed_official 610:813dcc80987e 754 */
mbed_official 610:813dcc80987e 755
mbed_official 610:813dcc80987e 756 #endif /* HAL_FLASH_MODULE_ENABLED */
mbed_official 610:813dcc80987e 757
mbed_official 610:813dcc80987e 758 /**
mbed_official 610:813dcc80987e 759 * @}
mbed_official 610:813dcc80987e 760 */
mbed_official 610:813dcc80987e 761
mbed_official 610:813dcc80987e 762 /**
mbed_official 610:813dcc80987e 763 * @}
mbed_official 610:813dcc80987e 764 */
mbed_official 610:813dcc80987e 765
mbed_official 610:813dcc80987e 766 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/