mbed library sources modified for open wear

Dependents:   openwear-lifelogger-example

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 21 15:00:08 2014 +0100
Revision:
297:ec1b66a3d094
Parent:
targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal_flash.c@242:7074e42da0b2
Synchronized with git revision bbc120c4786e99dfa586e7a13f8638064f1e5938

Full URL: https://github.com/mbedmicro/mbed/commit/bbc120c4786e99dfa586e7a13f8638064f1e5938/

DISCO_F407VG - add USBDevice support and a variant - ARCH_MAX

Who changed what in which revision?

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