Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f1xx_hal_flash.h |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @version V1.0.1 |
||
| 6 | * @date 31-July-2015 |
||
| 7 | * @brief Header file of Flash HAL module. |
||
| 8 | ****************************************************************************** |
||
| 9 | * @attention |
||
| 10 | * |
||
| 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
||
| 12 | * |
||
| 13 | * Redistribution and use in source and binary forms, with or without modification, |
||
| 14 | * are permitted provided that the following conditions are met: |
||
| 15 | * 1. Redistributions of source code must retain the above copyright notice, |
||
| 16 | * this list of conditions and the following disclaimer. |
||
| 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
| 18 | * this list of conditions and the following disclaimer in the documentation |
||
| 19 | * and/or other materials provided with the distribution. |
||
| 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
||
| 21 | * may be used to endorse or promote products derived from this software |
||
| 22 | * without specific prior written permission. |
||
| 23 | * |
||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
| 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
| 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
| 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
| 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 34 | * |
||
| 35 | ****************************************************************************** |
||
| 36 | */ |
||
| 37 | |||
| 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
| 39 | #ifndef __STM32F1xx_HAL_FLASH_H |
||
| 40 | #define __STM32F1xx_HAL_FLASH_H |
||
| 41 | |||
| 42 | #ifdef __cplusplus |
||
| 43 | extern "C" { |
||
| 44 | #endif |
||
| 45 | |||
| 46 | /* Includes ------------------------------------------------------------------*/ |
||
| 47 | #include "stm32f1xx_hal_def.h" |
||
| 48 | |||
| 49 | /** @addtogroup STM32F1xx_HAL_Driver |
||
| 50 | * @{ |
||
| 51 | */ |
||
| 52 | |||
| 53 | /** @addtogroup FLASH |
||
| 54 | * @{ |
||
| 55 | */ |
||
| 56 | |||
| 57 | /** @addtogroup FLASH_Private_Constants |
||
| 58 | * @{ |
||
| 59 | */ |
||
| 60 | #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ |
||
| 61 | /** |
||
| 62 | * @} |
||
| 63 | */ |
||
| 64 | |||
| 65 | /** @addtogroup FLASH_Private_Macros |
||
| 66 | * @{ |
||
| 67 | */ |
||
| 68 | |||
| 69 | #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ |
||
| 70 | ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ |
||
| 71 | ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) |
||
| 72 | |||
| 73 | #if defined(FLASH_ACR_LATENCY) |
||
| 74 | #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ |
||
| 75 | ((__LATENCY__) == FLASH_LATENCY_1) || \ |
||
| 76 | ((__LATENCY__) == FLASH_LATENCY_2)) |
||
| 77 | |||
| 78 | #else |
||
| 79 | #define IS_FLASH_LATENCY(__LATENCY__) ((__LATENCY__) == FLASH_LATENCY_0) |
||
| 80 | #endif /* FLASH_ACR_LATENCY */ |
||
| 81 | /** |
||
| 82 | * @} |
||
| 83 | */ |
||
| 84 | |||
| 85 | /* Exported types ------------------------------------------------------------*/ |
||
| 86 | /** @defgroup FLASH_Exported_Types FLASH Exported Types |
||
| 87 | * @{ |
||
| 88 | */ |
||
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * @brief FLASH Procedure structure definition |
||
| 93 | */ |
||
| 94 | typedef enum |
||
| 95 | { |
||
| 96 | FLASH_PROC_NONE = 0, |
||
| 97 | FLASH_PROC_PAGEERASE = 1, |
||
| 98 | FLASH_PROC_MASSERASE = 2, |
||
| 99 | FLASH_PROC_PROGRAMHALFWORD = 3, |
||
| 100 | FLASH_PROC_PROGRAMWORD = 4, |
||
| 101 | FLASH_PROC_PROGRAMDOUBLEWORD = 5 |
||
| 102 | } FLASH_ProcedureTypeDef; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @brief FLASH handle Structure definition |
||
| 106 | */ |
||
| 107 | typedef struct |
||
| 108 | { |
||
| 109 | __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */ |
||
| 110 | |||
| 111 | __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */ |
||
| 112 | |||
| 113 | __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */ |
||
| 114 | |||
| 115 | __IO uint64_t Data; /*!< Internal variable to save data to be programmed */ |
||
| 116 | |||
| 117 | HAL_LockTypeDef Lock; /*!< FLASH locking object */ |
||
| 118 | |||
| 119 | __IO uint32_t ErrorCode; /*!< FLASH error code |
||
| 120 | This parameter can be a value of @ref FLASH_Error_Codes */ |
||
| 121 | } FLASH_ProcessTypeDef; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @} |
||
| 125 | */ |
||
| 126 | |||
| 127 | /* Exported constants --------------------------------------------------------*/ |
||
| 128 | /** @defgroup FLASH_Exported_Constants FLASH Exported Constants |
||
| 129 | * @{ |
||
| 130 | */ |
||
| 131 | |||
| 132 | /** @defgroup FLASH_Error_Codes FLASH Error Codes |
||
| 133 | * @{ |
||
| 134 | */ |
||
| 135 | |||
| 136 | #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00) /*!< No error */ |
||
| 137 | #define HAL_FLASH_ERROR_PROG ((uint32_t)0x01) /*!< Programming error */ |
||
| 138 | #define HAL_FLASH_ERROR_WRP ((uint32_t)0x02) /*!< Write protection error */ |
||
| 139 | #define HAL_FLASH_ERROR_OPTV ((uint32_t)0x04) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @} |
||
| 143 | */ |
||
| 144 | |||
| 145 | /** @defgroup FLASH_Type_Program FLASH Type Program |
||
| 146 | * @{ |
||
| 147 | */ |
||
| 148 | #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!<Program a half-word (16-bit) at a specified address.*/ |
||
| 149 | #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02) /*!<Program a word (32-bit) at a specified address.*/ |
||
| 150 | #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!<Program a double word (64-bit) at a specified address*/ |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @} |
||
| 154 | */ |
||
| 155 | |||
| 156 | #if defined(FLASH_ACR_LATENCY) |
||
| 157 | /** @defgroup FLASH_Latency FLASH Latency |
||
| 158 | * @{ |
||
| 159 | */ |
||
| 160 | #define FLASH_LATENCY_0 ((uint32_t)0x00000000) /*!< FLASH Zero Latency cycle */ |
||
| 161 | #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */ |
||
| 162 | #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */ |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @} |
||
| 166 | */ |
||
| 167 | |||
| 168 | #else |
||
| 169 | /** @defgroup FLASH_Latency FLASH Latency |
||
| 170 | * @{ |
||
| 171 | */ |
||
| 172 | #define FLASH_LATENCY_0 ((uint32_t)0x00000000) /*!< FLASH Zero Latency cycle */ |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @} |
||
| 176 | */ |
||
| 177 | |||
| 178 | #endif /* FLASH_ACR_LATENCY */ |
||
| 179 | /** |
||
| 180 | * @} |
||
| 181 | */ |
||
| 182 | |||
| 183 | /* Exported macro ------------------------------------------------------------*/ |
||
| 184 | |||
| 185 | /** @defgroup FLASH_Exported_Macros FLASH Exported Macros |
||
| 186 | * @brief macros to control FLASH features |
||
| 187 | * @{ |
||
| 188 | */ |
||
| 189 | |||
| 190 | /** @defgroup FLASH_Half_Cycle FLASH Half Cycle |
||
| 191 | * @brief macros to handle FLASH half cycle |
||
| 192 | * @{ |
||
| 193 | */ |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @brief Enable the FLASH half cycle access. |
||
| 197 | * @note half cycle access can only be used with a low-frequency clock of less than |
||
| 198 | 8 MHz that can be obtained with the use of HSI or HSE but not of PLL. |
||
| 199 | * @retval None |
||
| 200 | */ |
||
| 201 | #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @brief Disable the FLASH half cycle access. |
||
| 205 | * @note half cycle access can only be used with a low-frequency clock of less than |
||
| 206 | 8 MHz that can be obtained with the use of HSI or HSE but not of PLL. |
||
| 207 | * @retval None |
||
| 208 | */ |
||
| 209 | #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA)) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @} |
||
| 213 | */ |
||
| 214 | |||
| 215 | #if defined(FLASH_ACR_LATENCY) |
||
| 216 | /** @defgroup FLASH_EM_Latency FLASH Latency |
||
| 217 | * @brief macros to handle FLASH Latency |
||
| 218 | * @{ |
||
| 219 | */ |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @brief Set the FLASH Latency. |
||
| 223 | * @param __LATENCY__: FLASH Latency |
||
| 224 | * The value of this parameter depend on device used within the same series |
||
| 225 | * @retval None |
||
| 226 | */ |
||
| 227 | #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__)) |
||
| 228 | |||
| 229 | |||
| 230 | /** |
||
| 231 | * @brief Get the FLASH Latency. |
||
| 232 | * @retval FLASH Latency |
||
| 233 | * The value of this parameter depend on device used within the same series |
||
| 234 | */ |
||
| 235 | #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @} |
||
| 239 | */ |
||
| 240 | |||
| 241 | #endif /* FLASH_ACR_LATENCY */ |
||
| 242 | /** @defgroup FLASH_Prefetch FLASH Prefetch |
||
| 243 | * @brief macros to handle FLASH Prefetch buffer |
||
| 244 | * @{ |
||
| 245 | */ |
||
| 246 | /** |
||
| 247 | * @brief Enable the FLASH prefetch buffer. |
||
| 248 | * @retval None |
||
| 249 | */ |
||
| 250 | #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @brief Disable the FLASH prefetch buffer. |
||
| 254 | * @retval None |
||
| 255 | */ |
||
| 256 | #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE)) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @} |
||
| 260 | */ |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @} |
||
| 264 | */ |
||
| 265 | |||
| 266 | /* Include FLASH HAL Extended module */ |
||
| 267 | #include "stm32f1xx_hal_flash_ex.h" |
||
| 268 | |||
| 269 | /* Exported functions --------------------------------------------------------*/ |
||
| 270 | /** @addtogroup FLASH_Exported_Functions |
||
| 271 | * @{ |
||
| 272 | */ |
||
| 273 | |||
| 274 | /** @addtogroup FLASH_Exported_Functions_Group1 |
||
| 275 | * @{ |
||
| 276 | */ |
||
| 277 | /* IO operation functions *****************************************************/ |
||
| 278 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); |
||
| 279 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); |
||
| 280 | |||
| 281 | /* FLASH IRQ handler method */ |
||
| 282 | void HAL_FLASH_IRQHandler(void); |
||
| 283 | /* Callbacks in non blocking modes */ |
||
| 284 | void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); |
||
| 285 | void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @} |
||
| 289 | */ |
||
| 290 | |||
| 291 | /** @addtogroup FLASH_Exported_Functions_Group2 |
||
| 292 | * @{ |
||
| 293 | */ |
||
| 294 | /* Peripheral Control functions ***********************************************/ |
||
| 295 | HAL_StatusTypeDef HAL_FLASH_Unlock(void); |
||
| 296 | HAL_StatusTypeDef HAL_FLASH_Lock(void); |
||
| 297 | HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); |
||
| 298 | HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); |
||
| 299 | HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @} |
||
| 303 | */ |
||
| 304 | |||
| 305 | /** @addtogroup FLASH_Exported_Functions_Group3 |
||
| 306 | * @{ |
||
| 307 | */ |
||
| 308 | /* Peripheral State and Error functions ***************************************/ |
||
| 309 | uint32_t HAL_FLASH_GetError(void); |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @} |
||
| 313 | */ |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @} |
||
| 317 | */ |
||
| 318 | |||
| 319 | /* Private function -------------------------------------------------*/ |
||
| 320 | /** @addtogroup FLASH_Private_Functions |
||
| 321 | * @{ |
||
| 322 | */ |
||
| 323 | void FLASH_PageErase(uint32_t PageAddress); |
||
| 324 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); |
||
| 325 | #if defined(FLASH_BANK2_END) |
||
| 326 | HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout); |
||
| 327 | #endif /* FLASH_BANK2_END */ |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @} |
||
| 331 | */ |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @} |
||
| 335 | */ |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @} |
||
| 339 | */ |
||
| 340 | |||
| 341 | #ifdef __cplusplus |
||
| 342 | } |
||
| 343 | #endif |
||
| 344 | |||
| 345 | #endif /* __STM32F1xx_HAL_FLASH_H */ |
||
| 346 | |||
| 347 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
||
| 348 |