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