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