mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_flash.c@613:bc40b8d2aec4, 2015-08-20 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Aug 20 10:45:13 2015 +0100
- Revision:
- 613:bc40b8d2aec4
- Parent:
- 532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade
Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/
Nordic: update application start address in GCC linker script
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 | 613:bc40b8d2aec4 | 5 | * @version V1.3.2 |
mbed_official | 613:bc40b8d2aec4 | 6 | * @date 26-June-2015 |
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 | 532:fe11edbda85c | 68 | * <h2><center>© COPYRIGHT(c) 2015 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 | 532:fe11edbda85c | 102 | /** @defgroup FLASH 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 | 532:fe11edbda85c | 111 | /** @addtogroup FLASH_Private_Constants |
mbed_official | 532:fe11edbda85c | 112 | * @{ |
mbed_official | 532:fe11edbda85c | 113 | */ |
mbed_official | 235:685d5f11838f | 114 | #define SECTOR_MASK ((uint32_t)0xFFFFFF07) |
mbed_official | 532:fe11edbda85c | 115 | #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ |
mbed_official | 532:fe11edbda85c | 116 | /** |
mbed_official | 532:fe11edbda85c | 117 | * @} |
mbed_official | 532:fe11edbda85c | 118 | */ |
mbed_official | 235:685d5f11838f | 119 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 120 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 532:fe11edbda85c | 121 | /** @addtogroup FLASH_Private_Variables |
mbed_official | 532:fe11edbda85c | 122 | * @{ |
mbed_official | 532:fe11edbda85c | 123 | */ |
mbed_official | 235:685d5f11838f | 124 | /* Variable used for Erase sectors under interruption */ |
mbed_official | 235:685d5f11838f | 125 | FLASH_ProcessTypeDef pFlash; |
mbed_official | 532:fe11edbda85c | 126 | /** |
mbed_official | 532:fe11edbda85c | 127 | * @} |
mbed_official | 532:fe11edbda85c | 128 | */ |
mbed_official | 235:685d5f11838f | 129 | |
mbed_official | 235:685d5f11838f | 130 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 532:fe11edbda85c | 131 | /** @addtogroup FLASH_Private_Functions |
mbed_official | 532:fe11edbda85c | 132 | * @{ |
mbed_official | 532:fe11edbda85c | 133 | */ |
mbed_official | 235:685d5f11838f | 134 | /* Program operations */ |
mbed_official | 235:685d5f11838f | 135 | static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data); |
mbed_official | 235:685d5f11838f | 136 | static void FLASH_Program_Word(uint32_t Address, uint32_t Data); |
mbed_official | 235:685d5f11838f | 137 | static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 235:685d5f11838f | 138 | static void FLASH_Program_Byte(uint32_t Address, uint8_t Data); |
mbed_official | 235:685d5f11838f | 139 | static void FLASH_SetErrorCode(void); |
mbed_official | 235:685d5f11838f | 140 | |
mbed_official | 235:685d5f11838f | 141 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
mbed_official | 532:fe11edbda85c | 142 | /** |
mbed_official | 532:fe11edbda85c | 143 | * @} |
mbed_official | 532:fe11edbda85c | 144 | */ |
mbed_official | 235:685d5f11838f | 145 | |
mbed_official | 532:fe11edbda85c | 146 | /* Exported functions --------------------------------------------------------*/ |
mbed_official | 532:fe11edbda85c | 147 | /** @defgroup FLASH_Exported_Functions FLASH Exported Functions |
mbed_official | 235:685d5f11838f | 148 | * @{ |
mbed_official | 235:685d5f11838f | 149 | */ |
mbed_official | 235:685d5f11838f | 150 | |
mbed_official | 532:fe11edbda85c | 151 | /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions |
mbed_official | 235:685d5f11838f | 152 | * @brief Programming operation functions |
mbed_official | 235:685d5f11838f | 153 | * |
mbed_official | 235:685d5f11838f | 154 | @verbatim |
mbed_official | 235:685d5f11838f | 155 | =============================================================================== |
mbed_official | 235:685d5f11838f | 156 | ##### Programming operation functions ##### |
mbed_official | 235:685d5f11838f | 157 | =============================================================================== |
mbed_official | 235:685d5f11838f | 158 | [..] |
mbed_official | 235:685d5f11838f | 159 | This subsection provides a set of functions allowing to manage the FLASH |
mbed_official | 235:685d5f11838f | 160 | program operations. |
mbed_official | 235:685d5f11838f | 161 | |
mbed_official | 235:685d5f11838f | 162 | @endverbatim |
mbed_official | 235:685d5f11838f | 163 | * @{ |
mbed_official | 235:685d5f11838f | 164 | */ |
mbed_official | 235:685d5f11838f | 165 | |
mbed_official | 235:685d5f11838f | 166 | /** |
mbed_official | 235:685d5f11838f | 167 | * @brief Program byte, halfword, word or double word at a specified address |
mbed_official | 235:685d5f11838f | 168 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 235:685d5f11838f | 169 | * This parameter can be a value of @ref FLASH_Type_Program |
mbed_official | 235:685d5f11838f | 170 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 171 | * @param Data: specifies the data to be programmed |
mbed_official | 235:685d5f11838f | 172 | * |
mbed_official | 235:685d5f11838f | 173 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 235:685d5f11838f | 174 | */ |
mbed_official | 235:685d5f11838f | 175 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
mbed_official | 235:685d5f11838f | 176 | { |
mbed_official | 235:685d5f11838f | 177 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 235:685d5f11838f | 178 | |
mbed_official | 235:685d5f11838f | 179 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 180 | __HAL_LOCK(&pFlash); |
mbed_official | 235:685d5f11838f | 181 | |
mbed_official | 235:685d5f11838f | 182 | /* Check the parameters */ |
mbed_official | 532:fe11edbda85c | 183 | assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); |
mbed_official | 235:685d5f11838f | 184 | |
mbed_official | 235:685d5f11838f | 185 | /* Wait for last operation to be completed */ |
mbed_official | 532:fe11edbda85c | 186 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 235:685d5f11838f | 187 | |
mbed_official | 235:685d5f11838f | 188 | if(status == HAL_OK) |
mbed_official | 235:685d5f11838f | 189 | { |
mbed_official | 532:fe11edbda85c | 190 | if(TypeProgram == FLASH_TYPEPROGRAM_BYTE) |
mbed_official | 235:685d5f11838f | 191 | { |
mbed_official | 235:685d5f11838f | 192 | /*Program byte (8-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 193 | FLASH_Program_Byte(Address, (uint8_t) Data); |
mbed_official | 235:685d5f11838f | 194 | } |
mbed_official | 532:fe11edbda85c | 195 | else if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) |
mbed_official | 235:685d5f11838f | 196 | { |
mbed_official | 235:685d5f11838f | 197 | /*Program halfword (16-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 198 | FLASH_Program_HalfWord(Address, (uint16_t) Data); |
mbed_official | 235:685d5f11838f | 199 | } |
mbed_official | 532:fe11edbda85c | 200 | else if(TypeProgram == FLASH_TYPEPROGRAM_WORD) |
mbed_official | 235:685d5f11838f | 201 | { |
mbed_official | 235:685d5f11838f | 202 | /*Program word (32-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 203 | FLASH_Program_Word(Address, (uint32_t) Data); |
mbed_official | 235:685d5f11838f | 204 | } |
mbed_official | 235:685d5f11838f | 205 | else |
mbed_official | 235:685d5f11838f | 206 | { |
mbed_official | 235:685d5f11838f | 207 | /*Program double word (64-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 208 | FLASH_Program_DoubleWord(Address, Data); |
mbed_official | 235:685d5f11838f | 209 | } |
mbed_official | 235:685d5f11838f | 210 | |
mbed_official | 235:685d5f11838f | 211 | /* Wait for last operation to be completed */ |
mbed_official | 532:fe11edbda85c | 212 | status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
mbed_official | 235:685d5f11838f | 213 | |
mbed_official | 235:685d5f11838f | 214 | /* If the program operation is completed, disable the PG Bit */ |
mbed_official | 235:685d5f11838f | 215 | FLASH->CR &= (~FLASH_CR_PG); |
mbed_official | 235:685d5f11838f | 216 | } |
mbed_official | 235:685d5f11838f | 217 | |
mbed_official | 235:685d5f11838f | 218 | /* Process Unlocked */ |
mbed_official | 235:685d5f11838f | 219 | __HAL_UNLOCK(&pFlash); |
mbed_official | 235:685d5f11838f | 220 | |
mbed_official | 235:685d5f11838f | 221 | return status; |
mbed_official | 235:685d5f11838f | 222 | } |
mbed_official | 235:685d5f11838f | 223 | |
mbed_official | 235:685d5f11838f | 224 | /** |
mbed_official | 235:685d5f11838f | 225 | * @brief Program byte, halfword, word or double word at a specified address with interrupt enabled. |
mbed_official | 235:685d5f11838f | 226 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 235:685d5f11838f | 227 | * This parameter can be a value of @ref FLASH_Type_Program |
mbed_official | 235:685d5f11838f | 228 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 229 | * @param Data: specifies the data to be programmed |
mbed_official | 235:685d5f11838f | 230 | * |
mbed_official | 235:685d5f11838f | 231 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 232 | */ |
mbed_official | 235:685d5f11838f | 233 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) |
mbed_official | 235:685d5f11838f | 234 | { |
mbed_official | 235:685d5f11838f | 235 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 235:685d5f11838f | 236 | |
mbed_official | 235:685d5f11838f | 237 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 238 | __HAL_LOCK(&pFlash); |
mbed_official | 235:685d5f11838f | 239 | |
mbed_official | 235:685d5f11838f | 240 | /* Check the parameters */ |
mbed_official | 532:fe11edbda85c | 241 | assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); |
mbed_official | 235:685d5f11838f | 242 | |
mbed_official | 235:685d5f11838f | 243 | /* Enable End of FLASH Operation interrupt */ |
mbed_official | 235:685d5f11838f | 244 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); |
mbed_official | 235:685d5f11838f | 245 | |
mbed_official | 235:685d5f11838f | 246 | /* Enable Error source interrupt */ |
mbed_official | 235:685d5f11838f | 247 | __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); |
mbed_official | 235:685d5f11838f | 248 | |
mbed_official | 235:685d5f11838f | 249 | /* Clear pending flags (if any) */ |
mbed_official | 235:685d5f11838f | 250 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ |
mbed_official | 235:685d5f11838f | 251 | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR); |
mbed_official | 235:685d5f11838f | 252 | |
mbed_official | 235:685d5f11838f | 253 | pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM; |
mbed_official | 235:685d5f11838f | 254 | pFlash.Address = Address; |
mbed_official | 235:685d5f11838f | 255 | |
mbed_official | 532:fe11edbda85c | 256 | if(TypeProgram == FLASH_TYPEPROGRAM_BYTE) |
mbed_official | 235:685d5f11838f | 257 | { |
mbed_official | 235:685d5f11838f | 258 | /*Program byte (8-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 259 | FLASH_Program_Byte(Address, (uint8_t) Data); |
mbed_official | 235:685d5f11838f | 260 | } |
mbed_official | 532:fe11edbda85c | 261 | else if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) |
mbed_official | 235:685d5f11838f | 262 | { |
mbed_official | 235:685d5f11838f | 263 | /*Program halfword (16-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 264 | FLASH_Program_HalfWord(Address, (uint16_t) Data); |
mbed_official | 235:685d5f11838f | 265 | } |
mbed_official | 532:fe11edbda85c | 266 | else if(TypeProgram == FLASH_TYPEPROGRAM_WORD) |
mbed_official | 235:685d5f11838f | 267 | { |
mbed_official | 235:685d5f11838f | 268 | /*Program word (32-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 269 | FLASH_Program_Word(Address, (uint32_t) Data); |
mbed_official | 235:685d5f11838f | 270 | } |
mbed_official | 235:685d5f11838f | 271 | else |
mbed_official | 235:685d5f11838f | 272 | { |
mbed_official | 235:685d5f11838f | 273 | /*Program double word (64-bit) at a specified address.*/ |
mbed_official | 235:685d5f11838f | 274 | FLASH_Program_DoubleWord(Address, Data); |
mbed_official | 235:685d5f11838f | 275 | } |
mbed_official | 235:685d5f11838f | 276 | |
mbed_official | 235:685d5f11838f | 277 | return status; |
mbed_official | 235:685d5f11838f | 278 | } |
mbed_official | 235:685d5f11838f | 279 | |
mbed_official | 235:685d5f11838f | 280 | /** |
mbed_official | 235:685d5f11838f | 281 | * @brief This function handles FLASH interrupt request. |
mbed_official | 235:685d5f11838f | 282 | * @retval None |
mbed_official | 235:685d5f11838f | 283 | */ |
mbed_official | 235:685d5f11838f | 284 | void HAL_FLASH_IRQHandler(void) |
mbed_official | 235:685d5f11838f | 285 | { |
mbed_official | 235:685d5f11838f | 286 | uint32_t temp; |
mbed_official | 235:685d5f11838f | 287 | |
mbed_official | 235:685d5f11838f | 288 | /* If the program operation is completed, disable the PG Bit */ |
mbed_official | 235:685d5f11838f | 289 | FLASH->CR &= (~FLASH_CR_PG); |
mbed_official | 235:685d5f11838f | 290 | |
mbed_official | 235:685d5f11838f | 291 | /* If the erase operation is completed, disable the SER Bit */ |
mbed_official | 235:685d5f11838f | 292 | FLASH->CR &= (~FLASH_CR_SER); |
mbed_official | 235:685d5f11838f | 293 | FLASH->CR &= SECTOR_MASK; |
mbed_official | 235:685d5f11838f | 294 | |
mbed_official | 235:685d5f11838f | 295 | /* if the erase operation is completed, disable the MER Bit */ |
mbed_official | 235:685d5f11838f | 296 | FLASH->CR &= (~FLASH_MER_BIT); |
mbed_official | 235:685d5f11838f | 297 | |
mbed_official | 235:685d5f11838f | 298 | /* Check FLASH End of Operation flag */ |
mbed_official | 235:685d5f11838f | 299 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != RESET) |
mbed_official | 235:685d5f11838f | 300 | { |
mbed_official | 235:685d5f11838f | 301 | if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE) |
mbed_official | 235:685d5f11838f | 302 | { |
mbed_official | 235:685d5f11838f | 303 | /*Nb of sector to erased can be decreased*/ |
mbed_official | 235:685d5f11838f | 304 | pFlash.NbSectorsToErase--; |
mbed_official | 235:685d5f11838f | 305 | |
mbed_official | 235:685d5f11838f | 306 | /* Check if there are still sectors to erase*/ |
mbed_official | 235:685d5f11838f | 307 | if(pFlash.NbSectorsToErase != 0) |
mbed_official | 235:685d5f11838f | 308 | { |
mbed_official | 235:685d5f11838f | 309 | temp = pFlash.Sector; |
mbed_official | 235:685d5f11838f | 310 | /*Indicate user which sector has been erased*/ |
mbed_official | 235:685d5f11838f | 311 | HAL_FLASH_EndOfOperationCallback(temp); |
mbed_official | 235:685d5f11838f | 312 | |
mbed_official | 235:685d5f11838f | 313 | /* Clear pending flags (if any) */ |
mbed_official | 235:685d5f11838f | 314 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ |
mbed_official | 235:685d5f11838f | 315 | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR); |
mbed_official | 235:685d5f11838f | 316 | |
mbed_official | 235:685d5f11838f | 317 | /*Increment sector number*/ |
mbed_official | 532:fe11edbda85c | 318 | pFlash.Sector++; |
mbed_official | 532:fe11edbda85c | 319 | temp = pFlash.Sector; |
mbed_official | 235:685d5f11838f | 320 | FLASH_Erase_Sector(temp, pFlash.VoltageForErase); |
mbed_official | 235:685d5f11838f | 321 | } |
mbed_official | 235:685d5f11838f | 322 | else |
mbed_official | 235:685d5f11838f | 323 | { |
mbed_official | 235:685d5f11838f | 324 | /*No more sectors to Erase, user callback can be called.*/ |
mbed_official | 235:685d5f11838f | 325 | /*Reset Sector and stop Erase sectors procedure*/ |
mbed_official | 235:685d5f11838f | 326 | pFlash.Sector = temp = 0xFFFFFFFF; |
mbed_official | 235:685d5f11838f | 327 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 235:685d5f11838f | 328 | /* FLASH EOP interrupt user callback */ |
mbed_official | 235:685d5f11838f | 329 | HAL_FLASH_EndOfOperationCallback(temp); |
mbed_official | 235:685d5f11838f | 330 | /* Clear FLASH End of Operation pending bit */ |
mbed_official | 235:685d5f11838f | 331 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); |
mbed_official | 235:685d5f11838f | 332 | } |
mbed_official | 235:685d5f11838f | 333 | } |
mbed_official | 235:685d5f11838f | 334 | else |
mbed_official | 235:685d5f11838f | 335 | { |
mbed_official | 532:fe11edbda85c | 336 | if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) |
mbed_official | 235:685d5f11838f | 337 | { |
mbed_official | 235:685d5f11838f | 338 | /*MassErase ended. Return the selected bank*/ |
mbed_official | 235:685d5f11838f | 339 | /* FLASH EOP interrupt user callback */ |
mbed_official | 235:685d5f11838f | 340 | HAL_FLASH_EndOfOperationCallback(pFlash.Bank); |
mbed_official | 235:685d5f11838f | 341 | } |
mbed_official | 235:685d5f11838f | 342 | else |
mbed_official | 235:685d5f11838f | 343 | { |
mbed_official | 235:685d5f11838f | 344 | /*Program ended. Return the selected address*/ |
mbed_official | 235:685d5f11838f | 345 | /* FLASH EOP interrupt user callback */ |
mbed_official | 235:685d5f11838f | 346 | HAL_FLASH_EndOfOperationCallback(pFlash.Address); |
mbed_official | 235:685d5f11838f | 347 | } |
mbed_official | 235:685d5f11838f | 348 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 235:685d5f11838f | 349 | /* Clear FLASH End of Operation pending bit */ |
mbed_official | 235:685d5f11838f | 350 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); |
mbed_official | 235:685d5f11838f | 351 | } |
mbed_official | 235:685d5f11838f | 352 | |
mbed_official | 235:685d5f11838f | 353 | } |
mbed_official | 235:685d5f11838f | 354 | |
mbed_official | 235:685d5f11838f | 355 | /* Check FLASH operation error flags */ |
mbed_official | 235:685d5f11838f | 356 | if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \ |
mbed_official | 235:685d5f11838f | 357 | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR | FLASH_FLAG_RDERR)) != RESET) |
mbed_official | 235:685d5f11838f | 358 | { |
mbed_official | 235:685d5f11838f | 359 | if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE) |
mbed_official | 235:685d5f11838f | 360 | { |
mbed_official | 235:685d5f11838f | 361 | /*return the faulty sector*/ |
mbed_official | 235:685d5f11838f | 362 | temp = pFlash.Sector; |
mbed_official | 235:685d5f11838f | 363 | pFlash.Sector = 0xFFFFFFFF; |
mbed_official | 235:685d5f11838f | 364 | } |
mbed_official | 532:fe11edbda85c | 365 | else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) |
mbed_official | 235:685d5f11838f | 366 | { |
mbed_official | 235:685d5f11838f | 367 | /*return the faulty bank*/ |
mbed_official | 235:685d5f11838f | 368 | temp = pFlash.Bank; |
mbed_official | 235:685d5f11838f | 369 | } |
mbed_official | 235:685d5f11838f | 370 | else |
mbed_official | 235:685d5f11838f | 371 | { |
mbed_official | 532:fe11edbda85c | 372 | /*return the faulty address*/ |
mbed_official | 235:685d5f11838f | 373 | temp = pFlash.Address; |
mbed_official | 235:685d5f11838f | 374 | } |
mbed_official | 235:685d5f11838f | 375 | |
mbed_official | 235:685d5f11838f | 376 | /*Save the Error code*/ |
mbed_official | 235:685d5f11838f | 377 | FLASH_SetErrorCode(); |
mbed_official | 235:685d5f11838f | 378 | |
mbed_official | 235:685d5f11838f | 379 | /* FLASH error interrupt user callback */ |
mbed_official | 235:685d5f11838f | 380 | HAL_FLASH_OperationErrorCallback(temp); |
mbed_official | 235:685d5f11838f | 381 | /* Clear FLASH error pending bits */ |
mbed_official | 235:685d5f11838f | 382 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |\ |
mbed_official | 235:685d5f11838f | 383 | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR | FLASH_FLAG_RDERR); |
mbed_official | 235:685d5f11838f | 384 | |
mbed_official | 235:685d5f11838f | 385 | /*Stop the procedure ongoing*/ |
mbed_official | 235:685d5f11838f | 386 | pFlash.ProcedureOnGoing = FLASH_PROC_NONE; |
mbed_official | 235:685d5f11838f | 387 | } |
mbed_official | 235:685d5f11838f | 388 | |
mbed_official | 235:685d5f11838f | 389 | if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE) |
mbed_official | 235:685d5f11838f | 390 | { |
mbed_official | 235:685d5f11838f | 391 | /* Disable End of FLASH Operation interrupt */ |
mbed_official | 235:685d5f11838f | 392 | __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP); |
mbed_official | 235:685d5f11838f | 393 | |
mbed_official | 235:685d5f11838f | 394 | /* Disable Error source interrupt */ |
mbed_official | 235:685d5f11838f | 395 | __HAL_FLASH_DISABLE_IT(FLASH_IT_ERR); |
mbed_official | 235:685d5f11838f | 396 | |
mbed_official | 235:685d5f11838f | 397 | /* Process Unlocked */ |
mbed_official | 235:685d5f11838f | 398 | __HAL_UNLOCK(&pFlash); |
mbed_official | 235:685d5f11838f | 399 | } |
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 end of operation 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 which has been erased |
mbed_official | 235:685d5f11838f | 408 | * (if 0xFFFFFFFF, it means that all the selected sectors have been erased) |
mbed_official | 235:685d5f11838f | 409 | * Program: Address which was selected for data program |
mbed_official | 235:685d5f11838f | 410 | * @retval None |
mbed_official | 235:685d5f11838f | 411 | */ |
mbed_official | 235:685d5f11838f | 412 | __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue) |
mbed_official | 235:685d5f11838f | 413 | { |
mbed_official | 235:685d5f11838f | 414 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 415 | the HAL_FLASH_EndOfOperationCallback could be implemented in the user file |
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 | * @brief FLASH operation error interrupt callback |
mbed_official | 235:685d5f11838f | 421 | * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure |
mbed_official | 235:685d5f11838f | 422 | * Mass Erase: Bank number which has been requested to erase |
mbed_official | 235:685d5f11838f | 423 | * Sectors Erase: Sector number which returned an error |
mbed_official | 235:685d5f11838f | 424 | * Program: Address which was selected for data program |
mbed_official | 235:685d5f11838f | 425 | * @retval None |
mbed_official | 235:685d5f11838f | 426 | */ |
mbed_official | 235:685d5f11838f | 427 | __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue) |
mbed_official | 235:685d5f11838f | 428 | { |
mbed_official | 235:685d5f11838f | 429 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 430 | the HAL_FLASH_OperationErrorCallback could be implemented in the user file |
mbed_official | 235:685d5f11838f | 431 | */ |
mbed_official | 235:685d5f11838f | 432 | } |
mbed_official | 235:685d5f11838f | 433 | |
mbed_official | 235:685d5f11838f | 434 | /** |
mbed_official | 235:685d5f11838f | 435 | * @} |
mbed_official | 235:685d5f11838f | 436 | */ |
mbed_official | 235:685d5f11838f | 437 | |
mbed_official | 532:fe11edbda85c | 438 | /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions |
mbed_official | 235:685d5f11838f | 439 | * @brief management functions |
mbed_official | 235:685d5f11838f | 440 | * |
mbed_official | 235:685d5f11838f | 441 | @verbatim |
mbed_official | 235:685d5f11838f | 442 | =============================================================================== |
mbed_official | 235:685d5f11838f | 443 | ##### Peripheral Control functions ##### |
mbed_official | 235:685d5f11838f | 444 | =============================================================================== |
mbed_official | 235:685d5f11838f | 445 | [..] |
mbed_official | 235:685d5f11838f | 446 | This subsection provides a set of functions allowing to control the FLASH |
mbed_official | 235:685d5f11838f | 447 | memory operations. |
mbed_official | 235:685d5f11838f | 448 | |
mbed_official | 235:685d5f11838f | 449 | @endverbatim |
mbed_official | 235:685d5f11838f | 450 | * @{ |
mbed_official | 235:685d5f11838f | 451 | */ |
mbed_official | 235:685d5f11838f | 452 | |
mbed_official | 235:685d5f11838f | 453 | /** |
mbed_official | 235:685d5f11838f | 454 | * @brief Unlock the FLASH control register access |
mbed_official | 235:685d5f11838f | 455 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 456 | */ |
mbed_official | 235:685d5f11838f | 457 | HAL_StatusTypeDef HAL_FLASH_Unlock(void) |
mbed_official | 235:685d5f11838f | 458 | { |
mbed_official | 235:685d5f11838f | 459 | if((FLASH->CR & FLASH_CR_LOCK) != RESET) |
mbed_official | 235:685d5f11838f | 460 | { |
mbed_official | 235:685d5f11838f | 461 | /* Authorize the FLASH Registers access */ |
mbed_official | 235:685d5f11838f | 462 | FLASH->KEYR = FLASH_KEY1; |
mbed_official | 235:685d5f11838f | 463 | FLASH->KEYR = FLASH_KEY2; |
mbed_official | 235:685d5f11838f | 464 | } |
mbed_official | 235:685d5f11838f | 465 | else |
mbed_official | 235:685d5f11838f | 466 | { |
mbed_official | 235:685d5f11838f | 467 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 468 | } |
mbed_official | 235:685d5f11838f | 469 | |
mbed_official | 235:685d5f11838f | 470 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 471 | } |
mbed_official | 235:685d5f11838f | 472 | |
mbed_official | 235:685d5f11838f | 473 | /** |
mbed_official | 235:685d5f11838f | 474 | * @brief Locks the FLASH control register access |
mbed_official | 235:685d5f11838f | 475 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 476 | */ |
mbed_official | 235:685d5f11838f | 477 | HAL_StatusTypeDef HAL_FLASH_Lock(void) |
mbed_official | 235:685d5f11838f | 478 | { |
mbed_official | 235:685d5f11838f | 479 | /* Set the LOCK Bit to lock the FLASH Registers access */ |
mbed_official | 235:685d5f11838f | 480 | FLASH->CR |= FLASH_CR_LOCK; |
mbed_official | 235:685d5f11838f | 481 | |
mbed_official | 235:685d5f11838f | 482 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 483 | } |
mbed_official | 235:685d5f11838f | 484 | |
mbed_official | 235:685d5f11838f | 485 | /** |
mbed_official | 235:685d5f11838f | 486 | * @brief Unlock the FLASH Option Control Registers access. |
mbed_official | 235:685d5f11838f | 487 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 488 | */ |
mbed_official | 235:685d5f11838f | 489 | HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void) |
mbed_official | 235:685d5f11838f | 490 | { |
mbed_official | 235:685d5f11838f | 491 | if((FLASH->OPTCR & FLASH_OPTCR_OPTLOCK) != RESET) |
mbed_official | 235:685d5f11838f | 492 | { |
mbed_official | 235:685d5f11838f | 493 | /* Authorizes the Option Byte register programming */ |
mbed_official | 235:685d5f11838f | 494 | FLASH->OPTKEYR = FLASH_OPT_KEY1; |
mbed_official | 235:685d5f11838f | 495 | FLASH->OPTKEYR = FLASH_OPT_KEY2; |
mbed_official | 235:685d5f11838f | 496 | } |
mbed_official | 235:685d5f11838f | 497 | else |
mbed_official | 235:685d5f11838f | 498 | { |
mbed_official | 235:685d5f11838f | 499 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 500 | } |
mbed_official | 235:685d5f11838f | 501 | |
mbed_official | 235:685d5f11838f | 502 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 503 | } |
mbed_official | 235:685d5f11838f | 504 | |
mbed_official | 235:685d5f11838f | 505 | /** |
mbed_official | 235:685d5f11838f | 506 | * @brief Lock the FLASH Option Control Registers access. |
mbed_official | 235:685d5f11838f | 507 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 508 | */ |
mbed_official | 235:685d5f11838f | 509 | HAL_StatusTypeDef HAL_FLASH_OB_Lock(void) |
mbed_official | 235:685d5f11838f | 510 | { |
mbed_official | 235:685d5f11838f | 511 | /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */ |
mbed_official | 235:685d5f11838f | 512 | FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK; |
mbed_official | 235:685d5f11838f | 513 | |
mbed_official | 235:685d5f11838f | 514 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 515 | } |
mbed_official | 235:685d5f11838f | 516 | |
mbed_official | 235:685d5f11838f | 517 | /** |
mbed_official | 235:685d5f11838f | 518 | * @brief Launch the option byte loading. |
mbed_official | 235:685d5f11838f | 519 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 520 | */ |
mbed_official | 235:685d5f11838f | 521 | HAL_StatusTypeDef HAL_FLASH_OB_Launch(void) |
mbed_official | 235:685d5f11838f | 522 | { |
mbed_official | 235:685d5f11838f | 523 | /* Set the OPTSTRT bit in OPTCR register */ |
mbed_official | 235:685d5f11838f | 524 | *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= FLASH_OPTCR_OPTSTRT; |
mbed_official | 235:685d5f11838f | 525 | |
mbed_official | 235:685d5f11838f | 526 | /* Wait for last operation to be completed */ |
mbed_official | 532:fe11edbda85c | 527 | return(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE)); |
mbed_official | 235:685d5f11838f | 528 | } |
mbed_official | 235:685d5f11838f | 529 | |
mbed_official | 235:685d5f11838f | 530 | /** |
mbed_official | 235:685d5f11838f | 531 | * @} |
mbed_official | 235:685d5f11838f | 532 | */ |
mbed_official | 235:685d5f11838f | 533 | |
mbed_official | 532:fe11edbda85c | 534 | /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions |
mbed_official | 235:685d5f11838f | 535 | * @brief Peripheral Errors functions |
mbed_official | 235:685d5f11838f | 536 | * |
mbed_official | 235:685d5f11838f | 537 | @verbatim |
mbed_official | 235:685d5f11838f | 538 | =============================================================================== |
mbed_official | 235:685d5f11838f | 539 | ##### Peripheral Errors functions ##### |
mbed_official | 235:685d5f11838f | 540 | =============================================================================== |
mbed_official | 235:685d5f11838f | 541 | [..] |
mbed_official | 235:685d5f11838f | 542 | This subsection permits to get in run-time Errors of the FLASH peripheral. |
mbed_official | 235:685d5f11838f | 543 | |
mbed_official | 235:685d5f11838f | 544 | @endverbatim |
mbed_official | 235:685d5f11838f | 545 | * @{ |
mbed_official | 235:685d5f11838f | 546 | */ |
mbed_official | 235:685d5f11838f | 547 | |
mbed_official | 235:685d5f11838f | 548 | /** |
mbed_official | 235:685d5f11838f | 549 | * @brief Get the specific FLASH error flag. |
mbed_official | 532:fe11edbda85c | 550 | * @retval FLASH_ErrorCode: The returned value can be a combination of: |
mbed_official | 532:fe11edbda85c | 551 | * @arg HAL_FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP) |
mbed_official | 532:fe11edbda85c | 552 | * @arg HAL_FLASH_ERROR_PGS: FLASH Programming Sequence error flag |
mbed_official | 532:fe11edbda85c | 553 | * @arg HAL_FLASH_ERROR_PGP: FLASH Programming Parallelism error flag |
mbed_official | 532:fe11edbda85c | 554 | * @arg HAL_FLASH_ERROR_PGA: FLASH Programming Alignment error flag |
mbed_official | 532:fe11edbda85c | 555 | * @arg HAL_FLASH_ERROR_WRP: FLASH Write protected error flag |
mbed_official | 532:fe11edbda85c | 556 | * @arg HAL_FLASH_ERROR_OPERATION: FLASH operation Error flag |
mbed_official | 235:685d5f11838f | 557 | */ |
mbed_official | 532:fe11edbda85c | 558 | uint32_t HAL_FLASH_GetError(void) |
mbed_official | 235:685d5f11838f | 559 | { |
mbed_official | 235:685d5f11838f | 560 | return pFlash.ErrorCode; |
mbed_official | 235:685d5f11838f | 561 | } |
mbed_official | 235:685d5f11838f | 562 | |
mbed_official | 235:685d5f11838f | 563 | /** |
mbed_official | 235:685d5f11838f | 564 | * @} |
mbed_official | 235:685d5f11838f | 565 | */ |
mbed_official | 235:685d5f11838f | 566 | |
mbed_official | 235:685d5f11838f | 567 | /** |
mbed_official | 235:685d5f11838f | 568 | * @brief Wait for a FLASH operation to complete. |
mbed_official | 235:685d5f11838f | 569 | * @param Timeout: maximum flash operationtimeout |
mbed_official | 235:685d5f11838f | 570 | * @retval HAL Status |
mbed_official | 235:685d5f11838f | 571 | */ |
mbed_official | 235:685d5f11838f | 572 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout) |
mbed_official | 235:685d5f11838f | 573 | { |
mbed_official | 235:685d5f11838f | 574 | uint32_t tickstart = 0; |
mbed_official | 532:fe11edbda85c | 575 | |
mbed_official | 532:fe11edbda85c | 576 | /* Clear Error Code */ |
mbed_official | 532:fe11edbda85c | 577 | pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
mbed_official | 532:fe11edbda85c | 578 | |
mbed_official | 235:685d5f11838f | 579 | /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset. |
mbed_official | 235:685d5f11838f | 580 | Even if the FLASH operation fails, the BUSY flag will be reset and an error |
mbed_official | 235:685d5f11838f | 581 | flag will be set */ |
mbed_official | 235:685d5f11838f | 582 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 583 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 584 | |
mbed_official | 235:685d5f11838f | 585 | while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET) |
mbed_official | 235:685d5f11838f | 586 | { |
mbed_official | 235:685d5f11838f | 587 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 235:685d5f11838f | 588 | { |
mbed_official | 235:685d5f11838f | 589 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 235:685d5f11838f | 590 | { |
mbed_official | 235:685d5f11838f | 591 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 592 | } |
mbed_official | 235:685d5f11838f | 593 | } |
mbed_official | 235:685d5f11838f | 594 | } |
mbed_official | 235:685d5f11838f | 595 | |
mbed_official | 235:685d5f11838f | 596 | if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \ |
mbed_official | 235:685d5f11838f | 597 | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR | FLASH_FLAG_RDERR)) != RESET) |
mbed_official | 235:685d5f11838f | 598 | { |
mbed_official | 235:685d5f11838f | 599 | /*Save the error code*/ |
mbed_official | 235:685d5f11838f | 600 | FLASH_SetErrorCode(); |
mbed_official | 235:685d5f11838f | 601 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 602 | } |
mbed_official | 235:685d5f11838f | 603 | |
mbed_official | 235:685d5f11838f | 604 | /* If there is an error flag set */ |
mbed_official | 235:685d5f11838f | 605 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 606 | |
mbed_official | 235:685d5f11838f | 607 | } |
mbed_official | 235:685d5f11838f | 608 | |
mbed_official | 235:685d5f11838f | 609 | /** |
mbed_official | 235:685d5f11838f | 610 | * @brief Program a double word (64-bit) at a specified address. |
mbed_official | 235:685d5f11838f | 611 | * @note This function must be used when the device voltage range is from |
mbed_official | 235:685d5f11838f | 612 | * 2.7V to 3.6V and an External Vpp is present. |
mbed_official | 235:685d5f11838f | 613 | * |
mbed_official | 235:685d5f11838f | 614 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 235:685d5f11838f | 615 | * the erase operation is performed before the program one. |
mbed_official | 235:685d5f11838f | 616 | * |
mbed_official | 235:685d5f11838f | 617 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 618 | * @param Data: specifies the data to be programmed. |
mbed_official | 235:685d5f11838f | 619 | * @retval None |
mbed_official | 235:685d5f11838f | 620 | */ |
mbed_official | 235:685d5f11838f | 621 | static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data) |
mbed_official | 235:685d5f11838f | 622 | { |
mbed_official | 235:685d5f11838f | 623 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 624 | assert_param(IS_FLASH_ADDRESS(Address)); |
mbed_official | 235:685d5f11838f | 625 | |
mbed_official | 235:685d5f11838f | 626 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 235:685d5f11838f | 627 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 235:685d5f11838f | 628 | FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD; |
mbed_official | 235:685d5f11838f | 629 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 235:685d5f11838f | 630 | |
mbed_official | 235:685d5f11838f | 631 | *(__IO uint64_t*)Address = Data; |
mbed_official | 235:685d5f11838f | 632 | } |
mbed_official | 235:685d5f11838f | 633 | |
mbed_official | 235:685d5f11838f | 634 | |
mbed_official | 235:685d5f11838f | 635 | /** |
mbed_official | 235:685d5f11838f | 636 | * @brief Program word (32-bit) at a specified address. |
mbed_official | 235:685d5f11838f | 637 | * @note This function must be used when the device voltage range is from |
mbed_official | 235:685d5f11838f | 638 | * 2.7V to 3.6V. |
mbed_official | 235:685d5f11838f | 639 | * |
mbed_official | 235:685d5f11838f | 640 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 235:685d5f11838f | 641 | * the erase operation is performed before the program one. |
mbed_official | 235:685d5f11838f | 642 | * |
mbed_official | 235:685d5f11838f | 643 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 644 | * @param Data: specifies the data to be programmed. |
mbed_official | 235:685d5f11838f | 645 | * @retval None |
mbed_official | 235:685d5f11838f | 646 | */ |
mbed_official | 235:685d5f11838f | 647 | static void FLASH_Program_Word(uint32_t Address, uint32_t Data) |
mbed_official | 235:685d5f11838f | 648 | { |
mbed_official | 235:685d5f11838f | 649 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 650 | assert_param(IS_FLASH_ADDRESS(Address)); |
mbed_official | 235:685d5f11838f | 651 | |
mbed_official | 235:685d5f11838f | 652 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 235:685d5f11838f | 653 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 235:685d5f11838f | 654 | FLASH->CR |= FLASH_PSIZE_WORD; |
mbed_official | 235:685d5f11838f | 655 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 235:685d5f11838f | 656 | |
mbed_official | 235:685d5f11838f | 657 | *(__IO uint32_t*)Address = Data; |
mbed_official | 235:685d5f11838f | 658 | } |
mbed_official | 235:685d5f11838f | 659 | |
mbed_official | 235:685d5f11838f | 660 | /** |
mbed_official | 235:685d5f11838f | 661 | * @brief Program a half-word (16-bit) at a specified address. |
mbed_official | 235:685d5f11838f | 662 | * @note This function must be used when the device voltage range is from |
mbed_official | 235:685d5f11838f | 663 | * 2.7V to 3.6V. |
mbed_official | 235:685d5f11838f | 664 | * |
mbed_official | 235:685d5f11838f | 665 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 235:685d5f11838f | 666 | * the erase operation is performed before the program one. |
mbed_official | 235:685d5f11838f | 667 | * |
mbed_official | 235:685d5f11838f | 668 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 669 | * @param Data: specifies the data to be programmed. |
mbed_official | 235:685d5f11838f | 670 | * @retval None |
mbed_official | 235:685d5f11838f | 671 | */ |
mbed_official | 235:685d5f11838f | 672 | static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 235:685d5f11838f | 673 | { |
mbed_official | 235:685d5f11838f | 674 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 675 | assert_param(IS_FLASH_ADDRESS(Address)); |
mbed_official | 235:685d5f11838f | 676 | |
mbed_official | 235:685d5f11838f | 677 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 235:685d5f11838f | 678 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 235:685d5f11838f | 679 | FLASH->CR |= FLASH_PSIZE_HALF_WORD; |
mbed_official | 235:685d5f11838f | 680 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 235:685d5f11838f | 681 | |
mbed_official | 235:685d5f11838f | 682 | *(__IO uint16_t*)Address = Data; |
mbed_official | 235:685d5f11838f | 683 | } |
mbed_official | 235:685d5f11838f | 684 | |
mbed_official | 235:685d5f11838f | 685 | /** |
mbed_official | 235:685d5f11838f | 686 | * @brief Program byte (8-bit) at a specified address. |
mbed_official | 235:685d5f11838f | 687 | * @note This function must be used when the device voltage range is from |
mbed_official | 235:685d5f11838f | 688 | * 2.7V to 3.6V. |
mbed_official | 235:685d5f11838f | 689 | * |
mbed_official | 235:685d5f11838f | 690 | * @note If an erase and a program operations are requested simultaneously, |
mbed_official | 235:685d5f11838f | 691 | * the erase operation is performed before the program one. |
mbed_official | 235:685d5f11838f | 692 | * |
mbed_official | 235:685d5f11838f | 693 | * @param Address: specifies the address to be programmed. |
mbed_official | 235:685d5f11838f | 694 | * @param Data: specifies the data to be programmed. |
mbed_official | 235:685d5f11838f | 695 | * @retval None |
mbed_official | 235:685d5f11838f | 696 | */ |
mbed_official | 235:685d5f11838f | 697 | static void FLASH_Program_Byte(uint32_t Address, uint8_t Data) |
mbed_official | 235:685d5f11838f | 698 | { |
mbed_official | 235:685d5f11838f | 699 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 700 | assert_param(IS_FLASH_ADDRESS(Address)); |
mbed_official | 235:685d5f11838f | 701 | |
mbed_official | 235:685d5f11838f | 702 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 235:685d5f11838f | 703 | FLASH->CR &= CR_PSIZE_MASK; |
mbed_official | 235:685d5f11838f | 704 | FLASH->CR |= FLASH_PSIZE_BYTE; |
mbed_official | 235:685d5f11838f | 705 | FLASH->CR |= FLASH_CR_PG; |
mbed_official | 235:685d5f11838f | 706 | |
mbed_official | 235:685d5f11838f | 707 | *(__IO uint8_t*)Address = Data; |
mbed_official | 235:685d5f11838f | 708 | } |
mbed_official | 235:685d5f11838f | 709 | |
mbed_official | 235:685d5f11838f | 710 | /** |
mbed_official | 235:685d5f11838f | 711 | * @brief Set the specific FLASH error flag. |
mbed_official | 235:685d5f11838f | 712 | * @retval None |
mbed_official | 235:685d5f11838f | 713 | */ |
mbed_official | 235:685d5f11838f | 714 | static void FLASH_SetErrorCode(void) |
mbed_official | 235:685d5f11838f | 715 | { |
mbed_official | 235:685d5f11838f | 716 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) != RESET) |
mbed_official | 235:685d5f11838f | 717 | { |
mbed_official | 532:fe11edbda85c | 718 | pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP; |
mbed_official | 235:685d5f11838f | 719 | } |
mbed_official | 235:685d5f11838f | 720 | |
mbed_official | 235:685d5f11838f | 721 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR) != RESET) |
mbed_official | 235:685d5f11838f | 722 | { |
mbed_official | 532:fe11edbda85c | 723 | pFlash.ErrorCode |= HAL_FLASH_ERROR_PGA; |
mbed_official | 235:685d5f11838f | 724 | } |
mbed_official | 235:685d5f11838f | 725 | |
mbed_official | 235:685d5f11838f | 726 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGPERR) != RESET) |
mbed_official | 235:685d5f11838f | 727 | { |
mbed_official | 532:fe11edbda85c | 728 | pFlash.ErrorCode |= HAL_FLASH_ERROR_PGP; |
mbed_official | 235:685d5f11838f | 729 | } |
mbed_official | 235:685d5f11838f | 730 | |
mbed_official | 235:685d5f11838f | 731 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR) != RESET) |
mbed_official | 235:685d5f11838f | 732 | { |
mbed_official | 532:fe11edbda85c | 733 | pFlash.ErrorCode |= HAL_FLASH_ERROR_PGS; |
mbed_official | 235:685d5f11838f | 734 | } |
mbed_official | 235:685d5f11838f | 735 | |
mbed_official | 235:685d5f11838f | 736 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR) != RESET) |
mbed_official | 235:685d5f11838f | 737 | { |
mbed_official | 532:fe11edbda85c | 738 | pFlash.ErrorCode |= HAL_FLASH_ERROR_RD; |
mbed_official | 235:685d5f11838f | 739 | } |
mbed_official | 235:685d5f11838f | 740 | |
mbed_official | 235:685d5f11838f | 741 | if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR) != RESET) |
mbed_official | 235:685d5f11838f | 742 | { |
mbed_official | 532:fe11edbda85c | 743 | pFlash.ErrorCode |= HAL_FLASH_ERROR_OPERATION; |
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 | */ |
mbed_official | 235:685d5f11838f | 750 | |
mbed_official | 235:685d5f11838f | 751 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 235:685d5f11838f | 752 | |
mbed_official | 235:685d5f11838f | 753 | /** |
mbed_official | 235:685d5f11838f | 754 | * @} |
mbed_official | 235:685d5f11838f | 755 | */ |
mbed_official | 235:685d5f11838f | 756 | |
mbed_official | 235:685d5f11838f | 757 | /** |
mbed_official | 235:685d5f11838f | 758 | * @} |
mbed_official | 235:685d5f11838f | 759 | */ |
mbed_official | 235:685d5f11838f | 760 | |
mbed_official | 235:685d5f11838f | 761 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |