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