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:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
394:83f921546702
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 354:e67efb2aab0e 1 /**
mbed_official 354:e67efb2aab0e 2 ******************************************************************************
mbed_official 354:e67efb2aab0e 3 * @file stm32l1xx_hal_flash.c
mbed_official 354:e67efb2aab0e 4 * @author MCD Application Team
mbed_official 354:e67efb2aab0e 5 * @version V1.0.0
mbed_official 354:e67efb2aab0e 6 * @date 5-September-2014
mbed_official 354:e67efb2aab0e 7 * @brief FLASH HAL module driver.
mbed_official 354:e67efb2aab0e 8 * This file provides firmware functions to manage the following
mbed_official 354:e67efb2aab0e 9 * functionalities of the internal FLASH memory:
mbed_official 354:e67efb2aab0e 10 * + FLASH Interface configuration
mbed_official 354:e67efb2aab0e 11 * + FLASH Memory Programming
mbed_official 354:e67efb2aab0e 12 * + Interrupts and flags management
mbed_official 354:e67efb2aab0e 13 *
mbed_official 354:e67efb2aab0e 14 * @verbatim
mbed_official 354:e67efb2aab0e 15
mbed_official 354:e67efb2aab0e 16 ==============================================================================
mbed_official 354:e67efb2aab0e 17 ##### FLASH peripheral features #####
mbed_official 354:e67efb2aab0e 18 ==============================================================================
mbed_official 354:e67efb2aab0e 19
mbed_official 354:e67efb2aab0e 20 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
mbed_official 354:e67efb2aab0e 21 to the Flash memory. It implements the erase and program Flash memory operations
mbed_official 354:e67efb2aab0e 22 and the read and write protection mechanisms.
mbed_official 354:e67efb2aab0e 23
mbed_official 354:e67efb2aab0e 24 [..] The Flash memory interface accelerates code execution with a system of instruction prefetch.
mbed_official 354:e67efb2aab0e 25
mbed_official 354:e67efb2aab0e 26 [..] The FLASH main features are:
mbed_official 354:e67efb2aab0e 27 (+) Flash memory read operations
mbed_official 354:e67efb2aab0e 28 (+) Flash memory program/erase operations
mbed_official 354:e67efb2aab0e 29 (+) Read / write protections
mbed_official 354:e67efb2aab0e 30 (+) Prefetch on I-Code
mbed_official 354:e67efb2aab0e 31 (+) Option Bytes programming
mbed_official 354:e67efb2aab0e 32
mbed_official 354:e67efb2aab0e 33 ##### How to use this driver #####
mbed_official 354:e67efb2aab0e 34 ==============================================================================
mbed_official 354:e67efb2aab0e 35 [..] This driver provides functions to configure and program the Flash
mbed_official 354:e67efb2aab0e 36 memory of all STM32L1xx devices.
mbed_official 354:e67efb2aab0e 37
mbed_official 354:e67efb2aab0e 38 (#) FLASH Memory Programming functions: this group includes all
mbed_official 354:e67efb2aab0e 39 needed functions to erase and program the main memory:
mbed_official 354:e67efb2aab0e 40 (++) Lock and Unlock the Flash interface.
mbed_official 354:e67efb2aab0e 41 (++) Erase function: Erase Page.
mbed_official 354:e67efb2aab0e 42 (++) Program functions: Fast Word and Half Page(should be
mbed_official 354:e67efb2aab0e 43 executed from internal SRAM).
mbed_official 354:e67efb2aab0e 44
mbed_official 354:e67efb2aab0e 45 (#) DATA EEPROM Programming functions: this group includes all
mbed_official 354:e67efb2aab0e 46 needed functions to erase and program the DATA EEPROM memory:
mbed_official 354:e67efb2aab0e 47 (++) Lock and Unlock the DATA EEPROM interface.
mbed_official 354:e67efb2aab0e 48 (++) Erase function: Erase Byte, erase HalfWord, erase Word, erase
mbed_official 354:e67efb2aab0e 49 Double Word (should be executed from internal SRAM).
mbed_official 354:e67efb2aab0e 50 (++) Program functions: Fast Program Byte, Fast Program Half-Word,
mbed_official 354:e67efb2aab0e 51 FastProgramWord, Program Byte, Program Half-Word,
mbed_official 354:e67efb2aab0e 52 Program Word and Program Double-Word (should be executed
mbed_official 354:e67efb2aab0e 53 from internal SRAM).
mbed_official 354:e67efb2aab0e 54
mbed_official 354:e67efb2aab0e 55 (#) FLASH Option Bytes Programming functions: this group includes
mbed_official 354:e67efb2aab0e 56 all needed functions to:
mbed_official 354:e67efb2aab0e 57 (++) Lock and Unlock the Flash Option bytes.
mbed_official 354:e67efb2aab0e 58 (++) Set/Reset the write protection.
mbed_official 354:e67efb2aab0e 59 (++) Set the Read protection Level.
mbed_official 354:e67efb2aab0e 60 (++) Set the BOR level.
mbed_official 354:e67efb2aab0e 61 (++) Program the user option Bytes.
mbed_official 354:e67efb2aab0e 62 (++) Launch the Option Bytes loader.
mbed_official 354:e67efb2aab0e 63 (++) Get the Write protection.
mbed_official 354:e67efb2aab0e 64 (++) Get the read protection status.
mbed_official 354:e67efb2aab0e 65 (++) Get the BOR level.
mbed_official 354:e67efb2aab0e 66 (++) Get the user option bytes.
mbed_official 354:e67efb2aab0e 67
mbed_official 354:e67efb2aab0e 68 (#) Interrupts and flags management functions :
mbed_official 354:e67efb2aab0e 69 (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
mbed_official 354:e67efb2aab0e 70 (++) Wait for last FLASH operation according to its status
mbed_official 354:e67efb2aab0e 71 (++) Get error flag status by calling HAL_GetErrorCode()
mbed_official 354:e67efb2aab0e 72
mbed_official 354:e67efb2aab0e 73 (#) FLASH Interface configuration functions: this group includes
mbed_official 354:e67efb2aab0e 74 the management of following features:
mbed_official 354:e67efb2aab0e 75 (++) Enable/Disable the RUN PowerDown mode.
mbed_official 354:e67efb2aab0e 76 (++) Enable/Disable the SLEEP PowerDown mode.
mbed_official 354:e67efb2aab0e 77
mbed_official 354:e67efb2aab0e 78 (#) FLASH Peripheral State methods: this group includes
mbed_official 354:e67efb2aab0e 79 the management of following features:
mbed_official 354:e67efb2aab0e 80 (++) Wait for the FLASH operation
mbed_official 354:e67efb2aab0e 81 (++) Get the specific FLASH error flag
mbed_official 354:e67efb2aab0e 82
mbed_official 354:e67efb2aab0e 83 [..] In addition to these function, this driver includes a set of macros allowing
mbed_official 354:e67efb2aab0e 84 to handle the following operations:
mbed_official 354:e67efb2aab0e 85
mbed_official 354:e67efb2aab0e 86 (+) Set/Get the latency
mbed_official 354:e67efb2aab0e 87 (+) Enable/Disable the prefetch buffer
mbed_official 354:e67efb2aab0e 88 (+) Enable/Disable the 64 bit Read Access.
mbed_official 354:e67efb2aab0e 89 (+) Enable/Disable the Flash power-down
mbed_official 354:e67efb2aab0e 90 (+) Enable/Disable the FLASH interrupts
mbed_official 354:e67efb2aab0e 91 (+) Monitor the FLASH flags status
mbed_official 354:e67efb2aab0e 92
mbed_official 354:e67efb2aab0e 93 ===============================================================================
mbed_official 354:e67efb2aab0e 94 ##### Programming operation functions #####
mbed_official 354:e67efb2aab0e 95 ===============================================================================
mbed_official 354:e67efb2aab0e 96 [..]
mbed_official 354:e67efb2aab0e 97 This subsection provides a set of functions allowing to manage the FLASH
mbed_official 354:e67efb2aab0e 98 program operations.
mbed_official 354:e67efb2aab0e 99
mbed_official 354:e67efb2aab0e 100 [..] The FLASH Memory Programming functions, includes the following functions:
mbed_official 354:e67efb2aab0e 101 (+) HAL_FLASH_Unlock(void);
mbed_official 354:e67efb2aab0e 102 (+) HAL_FLASH_Lock(void);
mbed_official 354:e67efb2aab0e 103 (+) HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
mbed_official 354:e67efb2aab0e 104 (+) HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
mbed_official 354:e67efb2aab0e 105
mbed_official 354:e67efb2aab0e 106 [..] Any operation of erase or program should follow these steps:
mbed_official 354:e67efb2aab0e 107 (#) Call the HAL_FLASH_Unlock() function to enable the flash control register and
mbed_official 354:e67efb2aab0e 108 program memory access.
mbed_official 354:e67efb2aab0e 109 (#) Call the desired function to erase page or program data.
mbed_official 354:e67efb2aab0e 110 (#) Call the HAL_FLASH_Lock() to disable the flash program memory access
mbed_official 354:e67efb2aab0e 111 (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 354:e67efb2aab0e 112
mbed_official 354:e67efb2aab0e 113 ==============================================================================
mbed_official 354:e67efb2aab0e 114 ##### Option Bytes Programming functions #####
mbed_official 354:e67efb2aab0e 115 ==============================================================================
mbed_official 354:e67efb2aab0e 116
mbed_official 354:e67efb2aab0e 117 [..] The FLASH_Option Bytes Programming_functions, includes the following functions:
mbed_official 354:e67efb2aab0e 118 (+) HAL_FLASH_OB_Unlock(void);
mbed_official 354:e67efb2aab0e 119 (+) HAL_FLASH_OB_Lock(void);
mbed_official 354:e67efb2aab0e 120 (+) HAL_FLASH_OB_Launch(void);
mbed_official 354:e67efb2aab0e 121 (+) HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
mbed_official 354:e67efb2aab0e 122 (+) HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
mbed_official 354:e67efb2aab0e 123
mbed_official 354:e67efb2aab0e 124 [..] Any operation of erase or program should follow these steps:
mbed_official 354:e67efb2aab0e 125 (#) Call the HAL_FLASH_OB_Unlock() function to enable the Flash option control
mbed_official 354:e67efb2aab0e 126 register access.
mbed_official 354:e67efb2aab0e 127 (#) Call the following functions to program the desired option bytes.
mbed_official 354:e67efb2aab0e 128 (++) HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
mbed_official 354:e67efb2aab0e 129 (#) Once all needed option bytes to be programmed are correctly written, call the
mbed_official 354:e67efb2aab0e 130 HAL_FLASH_OB_Launch(void) function to launch the Option Bytes programming process.
mbed_official 354:e67efb2aab0e 131 (#) Call the HAL_FLASH_OB_Lock() to disable the Flash option control register access (recommended
mbed_official 354:e67efb2aab0e 132 to protect the option Bytes against possible unwanted operations).
mbed_official 354:e67efb2aab0e 133
mbed_official 354:e67efb2aab0e 134 * @endverbatim
mbed_official 354:e67efb2aab0e 135 *
mbed_official 354:e67efb2aab0e 136 ******************************************************************************
mbed_official 354:e67efb2aab0e 137 * @attention
mbed_official 354:e67efb2aab0e 138 *
mbed_official 354:e67efb2aab0e 139 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 354:e67efb2aab0e 140 *
mbed_official 354:e67efb2aab0e 141 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 354:e67efb2aab0e 142 * are permitted provided that the following conditions are met:
mbed_official 354:e67efb2aab0e 143 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 354:e67efb2aab0e 144 * this list of conditions and the following disclaimer.
mbed_official 354:e67efb2aab0e 145 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 354:e67efb2aab0e 146 * this list of conditions and the following disclaimer in the documentation
mbed_official 354:e67efb2aab0e 147 * and/or other materials provided with the distribution.
mbed_official 354:e67efb2aab0e 148 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 354:e67efb2aab0e 149 * may be used to endorse or promote products derived from this software
mbed_official 354:e67efb2aab0e 150 * without specific prior written permission.
mbed_official 354:e67efb2aab0e 151 *
mbed_official 354:e67efb2aab0e 152 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 354:e67efb2aab0e 153 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 354:e67efb2aab0e 154 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 354:e67efb2aab0e 155 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 354:e67efb2aab0e 156 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 354:e67efb2aab0e 157 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 354:e67efb2aab0e 158 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 354:e67efb2aab0e 159 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 354:e67efb2aab0e 160 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 354:e67efb2aab0e 161 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 354:e67efb2aab0e 162 *
mbed_official 354:e67efb2aab0e 163 ******************************************************************************
mbed_official 354:e67efb2aab0e 164 */
mbed_official 354:e67efb2aab0e 165
mbed_official 354:e67efb2aab0e 166 /* Includes ------------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 167 #include "stm32l1xx_hal.h"
mbed_official 354:e67efb2aab0e 168
mbed_official 354:e67efb2aab0e 169 /** @addtogroup STM32L1xx_HAL_Driver
mbed_official 354:e67efb2aab0e 170 * @{
mbed_official 354:e67efb2aab0e 171 */
mbed_official 354:e67efb2aab0e 172
mbed_official 354:e67efb2aab0e 173 #ifdef HAL_FLASH_MODULE_ENABLED
mbed_official 354:e67efb2aab0e 174
mbed_official 354:e67efb2aab0e 175 /** @defgroup FLASH FLASH
mbed_official 354:e67efb2aab0e 176 * @brief FLASH driver modules
mbed_official 354:e67efb2aab0e 177 * @{
mbed_official 354:e67efb2aab0e 178 */
mbed_official 354:e67efb2aab0e 179
mbed_official 354:e67efb2aab0e 180 /* Private typedef -----------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 181 /* Private define ------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 182 /* Private macro -------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 183 /* Private variables ---------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 184 /** @defgroup FLASH_Internal_Variables FLASH Internal Variables
mbed_official 354:e67efb2aab0e 185 * @{
mbed_official 354:e67efb2aab0e 186 */
mbed_official 354:e67efb2aab0e 187
mbed_official 354:e67efb2aab0e 188 /**
mbed_official 354:e67efb2aab0e 189 * @brief Variable used for Program/Erase sectors under interruption
mbed_official 354:e67efb2aab0e 190 */
mbed_official 354:e67efb2aab0e 191 FLASH_ProcessTypeDef ProcFlash;
mbed_official 354:e67efb2aab0e 192
mbed_official 354:e67efb2aab0e 193
mbed_official 354:e67efb2aab0e 194 /**
mbed_official 354:e67efb2aab0e 195 * @}
mbed_official 354:e67efb2aab0e 196 */
mbed_official 354:e67efb2aab0e 197 /* Private function prototypes -----------------------------------------------*/
mbed_official 354:e67efb2aab0e 198 /* Private functions ---------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 199
mbed_official 354:e67efb2aab0e 200 /** @defgroup FLASH_Exported_Functions FLASH Exported functions
mbed_official 354:e67efb2aab0e 201 * @{
mbed_official 354:e67efb2aab0e 202 */
mbed_official 354:e67efb2aab0e 203
mbed_official 354:e67efb2aab0e 204 /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
mbed_official 354:e67efb2aab0e 205 * @brief Programming operation functions
mbed_official 354:e67efb2aab0e 206 *
mbed_official 354:e67efb2aab0e 207 @verbatim
mbed_official 354:e67efb2aab0e 208 @endverbatim
mbed_official 354:e67efb2aab0e 209 * @{
mbed_official 354:e67efb2aab0e 210 */
mbed_official 354:e67efb2aab0e 211 /**
mbed_official 354:e67efb2aab0e 212 * @brief Program word at a specified address
mbed_official 354:e67efb2aab0e 213 * @note To correctly run this function, the HAL_FLASH_Unlock() function
mbed_official 354:e67efb2aab0e 214 * must be called before.
mbed_official 354:e67efb2aab0e 215 * Call the HAL_FLASH_Lock() to disable the flash memory access
mbed_official 354:e67efb2aab0e 216 * (recommended to protect the FLASH memory against possible unwanted operation).
mbed_official 354:e67efb2aab0e 217 * @param TypeProgram: Indicate the way to program at a specified address.
mbed_official 354:e67efb2aab0e 218 * This parameter can be a value of @ref FLASH_Type_Program
mbed_official 354:e67efb2aab0e 219 * @param Address: specifies the address to be programmed.
mbed_official 354:e67efb2aab0e 220 * @param Data: specifies the data to be programmed
mbed_official 354:e67efb2aab0e 221 *
mbed_official 354:e67efb2aab0e 222 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 223 */
mbed_official 354:e67efb2aab0e 224 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
mbed_official 354:e67efb2aab0e 225 {
mbed_official 354:e67efb2aab0e 226 HAL_StatusTypeDef status = HAL_ERROR;
mbed_official 354:e67efb2aab0e 227
mbed_official 354:e67efb2aab0e 228 /* Process Locked */
mbed_official 354:e67efb2aab0e 229 __HAL_LOCK(&ProcFlash);
mbed_official 354:e67efb2aab0e 230
mbed_official 354:e67efb2aab0e 231 /* Check the parameters */
mbed_official 354:e67efb2aab0e 232 assert_param(IS_TYPEPROGRAMFLASH(TypeProgram));
mbed_official 354:e67efb2aab0e 233 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 354:e67efb2aab0e 234
mbed_official 354:e67efb2aab0e 235 /* Wait for last operation to be completed */
mbed_official 354:e67efb2aab0e 236 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 354:e67efb2aab0e 237
mbed_official 354:e67efb2aab0e 238 if(status == HAL_OK)
mbed_official 354:e67efb2aab0e 239 {
mbed_official 354:e67efb2aab0e 240 /*Program word (32-bit) at a specified address.*/
mbed_official 354:e67efb2aab0e 241 *(__IO uint32_t *)Address = Data;
mbed_official 354:e67efb2aab0e 242
mbed_official 354:e67efb2aab0e 243 /* Wait for last operation to be completed */
mbed_official 354:e67efb2aab0e 244 status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE);
mbed_official 354:e67efb2aab0e 245 }
mbed_official 354:e67efb2aab0e 246
mbed_official 354:e67efb2aab0e 247 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 248 __HAL_UNLOCK(&ProcFlash);
mbed_official 354:e67efb2aab0e 249
mbed_official 354:e67efb2aab0e 250 return status;
mbed_official 354:e67efb2aab0e 251 }
mbed_official 354:e67efb2aab0e 252
mbed_official 354:e67efb2aab0e 253 /**
mbed_official 354:e67efb2aab0e 254 * @brief Program word at a specified address with interrupt enabled.
mbed_official 354:e67efb2aab0e 255 * @param TypeProgram: Indicate the way to program at a specified address.
mbed_official 354:e67efb2aab0e 256 * This parameter can be a value of @ref FLASH_Type_Program
mbed_official 354:e67efb2aab0e 257 * @param Address: specifies the address to be programmed.
mbed_official 354:e67efb2aab0e 258 * @param Data: specifies the data to be programmed
mbed_official 354:e67efb2aab0e 259 *
mbed_official 354:e67efb2aab0e 260 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 261 */
mbed_official 354:e67efb2aab0e 262 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
mbed_official 354:e67efb2aab0e 263 {
mbed_official 354:e67efb2aab0e 264 HAL_StatusTypeDef status = HAL_OK;
mbed_official 354:e67efb2aab0e 265
mbed_official 354:e67efb2aab0e 266 /* Process Locked */
mbed_official 354:e67efb2aab0e 267 __HAL_LOCK(&ProcFlash);
mbed_official 354:e67efb2aab0e 268
mbed_official 354:e67efb2aab0e 269 /* Check the parameters */
mbed_official 354:e67efb2aab0e 270 assert_param(IS_TYPEPROGRAMFLASH(TypeProgram));
mbed_official 354:e67efb2aab0e 271 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
mbed_official 354:e67efb2aab0e 272
mbed_official 354:e67efb2aab0e 273 /* Enable End of FLASH Operation interrupt */
mbed_official 354:e67efb2aab0e 274 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
mbed_official 354:e67efb2aab0e 275
mbed_official 354:e67efb2aab0e 276 /* Enable Error source interrupt */
mbed_official 354:e67efb2aab0e 277 __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR);
mbed_official 354:e67efb2aab0e 278
mbed_official 354:e67efb2aab0e 279 /* Clear pending flags (if any) */
mbed_official 354:e67efb2aab0e 280 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_MASK);
mbed_official 354:e67efb2aab0e 281
mbed_official 354:e67efb2aab0e 282 ProcFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM;
mbed_official 354:e67efb2aab0e 283 ProcFlash.Address = Address;
mbed_official 354:e67efb2aab0e 284
mbed_official 354:e67efb2aab0e 285 if(TypeProgram == TYPEPROGRAM_WORD)
mbed_official 354:e67efb2aab0e 286 {
mbed_official 354:e67efb2aab0e 287 /*Program word (32-bit) at a specified address.*/
mbed_official 354:e67efb2aab0e 288 *(__IO uint32_t *)Address = Data;
mbed_official 354:e67efb2aab0e 289 }
mbed_official 354:e67efb2aab0e 290
mbed_official 354:e67efb2aab0e 291 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 292 __HAL_UNLOCK(&ProcFlash);
mbed_official 354:e67efb2aab0e 293
mbed_official 354:e67efb2aab0e 294 return status;
mbed_official 354:e67efb2aab0e 295 }
mbed_official 354:e67efb2aab0e 296
mbed_official 354:e67efb2aab0e 297 /**
mbed_official 354:e67efb2aab0e 298 * @brief FLASH end of operation interrupt callback
mbed_official 354:e67efb2aab0e 299 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
mbed_official 354:e67efb2aab0e 300 * - Pages Erase: Sector which has been erased
mbed_official 354:e67efb2aab0e 301 * (if 0xFFFFFFFF, it means that all the selected sectors have been erased)
mbed_official 354:e67efb2aab0e 302 * - Program: Address which was selected for data program
mbed_official 354:e67efb2aab0e 303 * @retval none
mbed_official 354:e67efb2aab0e 304 */
mbed_official 354:e67efb2aab0e 305 __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
mbed_official 354:e67efb2aab0e 306 {
mbed_official 354:e67efb2aab0e 307 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 354:e67efb2aab0e 308 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
mbed_official 354:e67efb2aab0e 309 */
mbed_official 354:e67efb2aab0e 310 }
mbed_official 354:e67efb2aab0e 311
mbed_official 354:e67efb2aab0e 312 /**
mbed_official 354:e67efb2aab0e 313 * @brief FLASH operation error interrupt callback
mbed_official 354:e67efb2aab0e 314 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
mbed_official 354:e67efb2aab0e 315 * - Pagess Erase: Sector number which returned an error
mbed_official 354:e67efb2aab0e 316 * - Program: Address which was selected for data program
mbed_official 354:e67efb2aab0e 317 * @retval none
mbed_official 354:e67efb2aab0e 318 */
mbed_official 354:e67efb2aab0e 319 __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
mbed_official 354:e67efb2aab0e 320 {
mbed_official 354:e67efb2aab0e 321 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 354:e67efb2aab0e 322 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
mbed_official 354:e67efb2aab0e 323 */
mbed_official 354:e67efb2aab0e 324 }
mbed_official 354:e67efb2aab0e 325
mbed_official 354:e67efb2aab0e 326 /**
mbed_official 354:e67efb2aab0e 327 * @}
mbed_official 354:e67efb2aab0e 328 */
mbed_official 354:e67efb2aab0e 329
mbed_official 354:e67efb2aab0e 330 /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
mbed_official 354:e67efb2aab0e 331 * @brief management functions
mbed_official 354:e67efb2aab0e 332 *
mbed_official 354:e67efb2aab0e 333 @verbatim
mbed_official 354:e67efb2aab0e 334 ===============================================================================
mbed_official 354:e67efb2aab0e 335 ##### Peripheral Control functions #####
mbed_official 354:e67efb2aab0e 336 ===============================================================================
mbed_official 354:e67efb2aab0e 337 [..]
mbed_official 354:e67efb2aab0e 338 This subsection provides a set of functions allowing to control the FLASH
mbed_official 354:e67efb2aab0e 339 memory operations.
mbed_official 354:e67efb2aab0e 340
mbed_official 354:e67efb2aab0e 341 @endverbatim
mbed_official 354:e67efb2aab0e 342 * @{
mbed_official 354:e67efb2aab0e 343 */
mbed_official 354:e67efb2aab0e 344
mbed_official 354:e67efb2aab0e 345 /**
mbed_official 354:e67efb2aab0e 346 * @brief Unlock the FLASH control register access
mbed_official 354:e67efb2aab0e 347 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 348 */
mbed_official 354:e67efb2aab0e 349 HAL_StatusTypeDef HAL_FLASH_Unlock(void)
mbed_official 354:e67efb2aab0e 350 {
mbed_official 354:e67efb2aab0e 351 if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET)
mbed_official 354:e67efb2aab0e 352 {
mbed_official 354:e67efb2aab0e 353 /* Unlocking FLASH_PECR register access*/
mbed_official 354:e67efb2aab0e 354 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
mbed_official 354:e67efb2aab0e 355 {
mbed_official 354:e67efb2aab0e 356 FLASH->PEKEYR = FLASH_PEKEY1;
mbed_official 354:e67efb2aab0e 357 FLASH->PEKEYR = FLASH_PEKEY2;
mbed_official 354:e67efb2aab0e 358 }
mbed_official 354:e67efb2aab0e 359
mbed_official 354:e67efb2aab0e 360 /* Unlocking the program memory access */
mbed_official 354:e67efb2aab0e 361 FLASH->PRGKEYR = FLASH_PRGKEY1;
mbed_official 354:e67efb2aab0e 362 FLASH->PRGKEYR = FLASH_PRGKEY2;
mbed_official 354:e67efb2aab0e 363 }
mbed_official 354:e67efb2aab0e 364 else
mbed_official 354:e67efb2aab0e 365 {
mbed_official 354:e67efb2aab0e 366 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 367 }
mbed_official 354:e67efb2aab0e 368
mbed_official 354:e67efb2aab0e 369 return HAL_OK;
mbed_official 354:e67efb2aab0e 370 }
mbed_official 354:e67efb2aab0e 371
mbed_official 354:e67efb2aab0e 372 /**
mbed_official 354:e67efb2aab0e 373 * @brief Locks the FLASH control register access
mbed_official 354:e67efb2aab0e 374 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 375 */
mbed_official 354:e67efb2aab0e 376 HAL_StatusTypeDef HAL_FLASH_Lock(void)
mbed_official 354:e67efb2aab0e 377 {
mbed_official 354:e67efb2aab0e 378 /* Set the PRGLOCK Bit to lock the program memory access */
mbed_official 354:e67efb2aab0e 379 SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
mbed_official 354:e67efb2aab0e 380
mbed_official 354:e67efb2aab0e 381 return HAL_OK;
mbed_official 354:e67efb2aab0e 382 }
mbed_official 354:e67efb2aab0e 383
mbed_official 354:e67efb2aab0e 384 /**
mbed_official 354:e67efb2aab0e 385 * @brief Unlock the FLASH Option Control Registers access.
mbed_official 354:e67efb2aab0e 386 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 387 */
mbed_official 354:e67efb2aab0e 388 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
mbed_official 354:e67efb2aab0e 389 {
mbed_official 354:e67efb2aab0e 390 if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET)
mbed_official 354:e67efb2aab0e 391 {
mbed_official 354:e67efb2aab0e 392 /* Unlocking FLASH_PECR register access*/
mbed_official 354:e67efb2aab0e 393 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
mbed_official 354:e67efb2aab0e 394 {
mbed_official 354:e67efb2aab0e 395 /* Unlocking FLASH_PECR register access*/
mbed_official 354:e67efb2aab0e 396 FLASH->PEKEYR = FLASH_PEKEY1;
mbed_official 354:e67efb2aab0e 397 FLASH->PEKEYR = FLASH_PEKEY2;
mbed_official 354:e67efb2aab0e 398 }
mbed_official 354:e67efb2aab0e 399
mbed_official 354:e67efb2aab0e 400 /* Unlocking the option bytes block access */
mbed_official 354:e67efb2aab0e 401 FLASH->OPTKEYR = FLASH_OPTKEY1;
mbed_official 354:e67efb2aab0e 402 FLASH->OPTKEYR = FLASH_OPTKEY2;
mbed_official 354:e67efb2aab0e 403 }
mbed_official 354:e67efb2aab0e 404 else
mbed_official 354:e67efb2aab0e 405 {
mbed_official 354:e67efb2aab0e 406 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 407 }
mbed_official 354:e67efb2aab0e 408
mbed_official 354:e67efb2aab0e 409 return HAL_OK;
mbed_official 354:e67efb2aab0e 410 }
mbed_official 354:e67efb2aab0e 411
mbed_official 354:e67efb2aab0e 412 /**
mbed_official 354:e67efb2aab0e 413 * @brief Lock the FLASH Option Control Registers access.
mbed_official 354:e67efb2aab0e 414 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 415 */
mbed_official 354:e67efb2aab0e 416 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
mbed_official 354:e67efb2aab0e 417 {
mbed_official 354:e67efb2aab0e 418 /* Set the OPTLOCK Bit to lock the option bytes block access */
mbed_official 354:e67efb2aab0e 419 SET_BIT(FLASH->PECR, FLASH_PECR_OPTLOCK);
mbed_official 354:e67efb2aab0e 420
mbed_official 354:e67efb2aab0e 421 return HAL_OK;
mbed_official 354:e67efb2aab0e 422 }
mbed_official 354:e67efb2aab0e 423
mbed_official 354:e67efb2aab0e 424 /**
mbed_official 354:e67efb2aab0e 425 * @brief Launch the option byte loading.
mbed_official 354:e67efb2aab0e 426 * @retval HAL_StatusTypeDef HAL Status
mbed_official 354:e67efb2aab0e 427 */
mbed_official 354:e67efb2aab0e 428 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
mbed_official 354:e67efb2aab0e 429 {
mbed_official 354:e67efb2aab0e 430 /* Set the OBL_Launch bit to lauch the option byte loading */
mbed_official 354:e67efb2aab0e 431 SET_BIT(FLASH->PECR, FLASH_PECR_OBL_LAUNCH);
mbed_official 354:e67efb2aab0e 432
mbed_official 354:e67efb2aab0e 433 /* Wait for last operation to be completed */
mbed_official 354:e67efb2aab0e 434 return(FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE));
mbed_official 354:e67efb2aab0e 435 }
mbed_official 354:e67efb2aab0e 436
mbed_official 354:e67efb2aab0e 437 /**
mbed_official 354:e67efb2aab0e 438 * @}
mbed_official 354:e67efb2aab0e 439 */
mbed_official 354:e67efb2aab0e 440
mbed_official 354:e67efb2aab0e 441 /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
mbed_official 354:e67efb2aab0e 442 * @brief Peripheral Errors functions
mbed_official 354:e67efb2aab0e 443 *
mbed_official 354:e67efb2aab0e 444 @verbatim
mbed_official 354:e67efb2aab0e 445 ===============================================================================
mbed_official 354:e67efb2aab0e 446 ##### Peripheral Errors functions #####
mbed_official 354:e67efb2aab0e 447 ===============================================================================
mbed_official 354:e67efb2aab0e 448 [..]
mbed_official 354:e67efb2aab0e 449 This subsection permit to get in run-time Errors of the FLASH peripheral.
mbed_official 354:e67efb2aab0e 450
mbed_official 354:e67efb2aab0e 451 @endverbatim
mbed_official 354:e67efb2aab0e 452 * @{
mbed_official 354:e67efb2aab0e 453 */
mbed_official 354:e67efb2aab0e 454
mbed_official 354:e67efb2aab0e 455 /**
mbed_official 354:e67efb2aab0e 456 * @brief Get the specific FLASH error flag.
mbed_official 354:e67efb2aab0e 457 * @retval FLASH_ErrorCode: The returned value can be:
mbed_official 354:e67efb2aab0e 458 * @arg FLASH_ERROR_WRP: FLASH Write protected error flag
mbed_official 354:e67efb2aab0e 459 * @arg FLASH_ERROR_PGA: FLASH Programming Alignment error flag
mbed_official 354:e67efb2aab0e 460 * @arg FLASH_ERROR_SIZE: FLASH Size error flag
mbed_official 354:e67efb2aab0e 461 * @arg FLASH_ERROR_OPTV: Option validity error flag
mbed_official 354:e67efb2aab0e 462 * @arg FLASH_ERROR_OPTVUSR: Option UserValidity Error flag (available only Cat.3, Cat.4 and Cat.5 devices)
mbed_official 354:e67efb2aab0e 463 * @arg FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP) (available only Cat.2 and Cat.3 devices)
mbed_official 354:e67efb2aab0e 464 */
mbed_official 354:e67efb2aab0e 465 FLASH_ErrorTypeDef HAL_FLASH_GetError(void)
mbed_official 354:e67efb2aab0e 466 {
mbed_official 354:e67efb2aab0e 467 return ProcFlash.ErrorCode;
mbed_official 354:e67efb2aab0e 468 }
mbed_official 354:e67efb2aab0e 469
mbed_official 354:e67efb2aab0e 470 /**
mbed_official 354:e67efb2aab0e 471 * @}
mbed_official 354:e67efb2aab0e 472 */
mbed_official 354:e67efb2aab0e 473
mbed_official 354:e67efb2aab0e 474 /**
mbed_official 354:e67efb2aab0e 475 * @}
mbed_official 354:e67efb2aab0e 476 */
mbed_official 354:e67efb2aab0e 477
mbed_official 354:e67efb2aab0e 478 #endif /* HAL_FLASH_MODULE_ENABLED */
mbed_official 354:e67efb2aab0e 479
mbed_official 354:e67efb2aab0e 480 /**
mbed_official 354:e67efb2aab0e 481 * @}
mbed_official 354:e67efb2aab0e 482 */
mbed_official 354:e67efb2aab0e 483
mbed_official 354:e67efb2aab0e 484 /**
mbed_official 354:e67efb2aab0e 485 * @}
mbed_official 354:e67efb2aab0e 486 */
mbed_official 354:e67efb2aab0e 487
mbed_official 354:e67efb2aab0e 488
mbed_official 354:e67efb2aab0e 489
mbed_official 354:e67efb2aab0e 490 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/