1 /** 2 ****************************************************************************** 3 * @file stm32f3xx_hal_flash.h 4 * @author MCD Application Team 5 * @brief Header file of Flash HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2016 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file in 13 * the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 ****************************************************************************** 16 */ 17 18 /* Define to prevent recursive inclusion -------------------------------------*/ 19 #ifndef __STM32F3xx_HAL_FLASH_H 20 #define __STM32F3xx_HAL_FLASH_H 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /* Includes ------------------------------------------------------------------*/ 27 #include "stm32f3xx_hal_def.h" 28 29 /** @addtogroup STM32F3xx_HAL_Driver 30 * @{ 31 */ 32 33 /** @addtogroup FLASH 34 * @{ 35 */ 36 37 /** @addtogroup FLASH_Private_Constants 38 * @{ 39 */ 40 #define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */ 41 /** 42 * @} 43 */ 44 45 /** @addtogroup FLASH_Private_Macros 46 * @{ 47 */ 48 49 #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ 50 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ 51 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) 52 53 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ 54 ((__LATENCY__) == FLASH_LATENCY_1) || \ 55 ((__LATENCY__) == FLASH_LATENCY_2)) 56 57 /** 58 * @} 59 */ 60 61 /* Exported types ------------------------------------------------------------*/ 62 /** @defgroup FLASH_Exported_Types FLASH Exported Types 63 * @{ 64 */ 65 66 /** 67 * @brief FLASH Procedure structure definition 68 */ 69 typedef enum 70 { 71 FLASH_PROC_NONE = 0U, 72 FLASH_PROC_PAGEERASE = 1U, 73 FLASH_PROC_MASSERASE = 2U, 74 FLASH_PROC_PROGRAMHALFWORD = 3U, 75 FLASH_PROC_PROGRAMWORD = 4U, 76 FLASH_PROC_PROGRAMDOUBLEWORD = 5U 77 } FLASH_ProcedureTypeDef; 78 79 /** 80 * @brief FLASH handle Structure definition 81 */ 82 typedef struct 83 { 84 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */ 85 86 __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */ 87 88 __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */ 89 90 __IO uint64_t Data; /*!< Internal variable to save data to be programmed */ 91 92 HAL_LockTypeDef Lock; /*!< FLASH locking object */ 93 94 __IO uint32_t ErrorCode; /*!< FLASH error code 95 This parameter can be a value of @ref FLASH_Error_Codes */ 96 } FLASH_ProcessTypeDef; 97 98 /** 99 * @} 100 */ 101 102 /* Exported constants --------------------------------------------------------*/ 103 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants 104 * @{ 105 */ 106 107 /** @defgroup FLASH_Error_Codes FLASH Error Codes 108 * @{ 109 */ 110 111 #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */ 112 #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */ 113 #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */ 114 115 /** 116 * @} 117 */ 118 119 /** @defgroup FLASH_Type_Program FLASH Type Program 120 * @{ 121 */ 122 #define FLASH_TYPEPROGRAM_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/ 123 #define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/ 124 #define FLASH_TYPEPROGRAM_DOUBLEWORD (0x03U) /*!<Program a double word (64-bit) at a specified address*/ 125 126 /** 127 * @} 128 */ 129 130 /** @defgroup FLASH_Latency FLASH Latency 131 * @{ 132 */ 133 #define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */ 134 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */ 135 #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */ 136 137 /** 138 * @} 139 */ 140 141 142 /** @defgroup FLASH_Flag_definition FLASH Flag definition 143 * @{ 144 */ 145 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ 146 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */ 147 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ 148 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */ 149 /** 150 * @} 151 */ 152 153 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition 154 * @{ 155 */ 156 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */ 157 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */ 158 /** 159 * @} 160 */ 161 162 /** 163 * @} 164 */ 165 166 /* Exported macro ------------------------------------------------------------*/ 167 168 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros 169 * @brief macros to control FLASH features 170 * @{ 171 */ 172 173 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle 174 * @brief macros to handle FLASH half cycle 175 * @{ 176 */ 177 178 /** 179 * @brief Enable the FLASH half cycle access. 180 * @retval None 181 */ 182 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA) 183 184 /** 185 * @brief Disable the FLASH half cycle access. 186 * @retval None 187 */ 188 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA)) 189 190 /** 191 * @} 192 */ 193 194 /** @defgroup FLASH_EM_Latency FLASH Latency 195 * @brief macros to handle FLASH Latency 196 * @{ 197 */ 198 199 /** 200 * @brief Set the FLASH Latency. 201 * @param __LATENCY__ FLASH Latency 202 * This parameter can be one of the following values: 203 * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle 204 * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle 205 * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles 206 * @retval None 207 */ 208 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__)) 209 210 211 /** 212 * @brief Get the FLASH Latency. 213 * @retval FLASH Latency 214 * This parameter can be one of the following values: 215 * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle 216 * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle 217 * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles 218 */ 219 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) 220 221 /** 222 * @} 223 */ 224 225 /** @defgroup FLASH_Prefetch FLASH Prefetch 226 * @brief macros to handle FLASH Prefetch buffer 227 * @{ 228 */ 229 /** 230 * @brief Enable the FLASH prefetch buffer. 231 * @retval None 232 */ 233 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE) 234 235 /** 236 * @brief Disable the FLASH prefetch buffer. 237 * @retval None 238 */ 239 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE)) 240 241 /** 242 * @} 243 */ 244 245 /** @defgroup FLASH_Interrupt FLASH Interrupts 246 * @brief macros to handle FLASH interrupts 247 * @{ 248 */ 249 250 /** 251 * @brief Enable the specified FLASH interrupt. 252 * @param __INTERRUPT__ FLASH interrupt 253 * This parameter can be any combination of the following values: 254 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 255 * @arg @ref FLASH_IT_ERR Error Interrupt 256 * @retval none 257 */ 258 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__)) 259 260 /** 261 * @brief Disable the specified FLASH interrupt. 262 * @param __INTERRUPT__ FLASH interrupt 263 * This parameter can be any combination of the following values: 264 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 265 * @arg @ref FLASH_IT_ERR Error Interrupt 266 * @retval none 267 */ 268 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__)) 269 270 /** 271 * @brief Get the specified FLASH flag status. 272 * @param __FLAG__ specifies the FLASH flag to check. 273 * This parameter can be one of the following values: 274 * @arg @ref FLASH_FLAG_BSY FLASH Busy flag 275 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 276 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 277 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 278 * @retval The new state of __FLAG__ (SET or RESET). 279 */ 280 #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__)) 281 282 /** 283 * @brief Clear the specified FLASH flag. 284 * @param __FLAG__ specifies the FLASH flags to clear. 285 * This parameter can be any combination of the following values: 286 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 287 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 288 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 289 * @retval none 290 */ 291 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__)) 292 293 /** 294 * @} 295 */ 296 297 /** 298 * @} 299 */ 300 301 /* Include FLASH HAL Extended module */ 302 #include "stm32f3xx_hal_flash_ex.h" 303 304 /* Exported functions --------------------------------------------------------*/ 305 /** @addtogroup FLASH_Exported_Functions 306 * @{ 307 */ 308 309 /** @addtogroup FLASH_Exported_Functions_Group1 310 * @{ 311 */ 312 /* IO operation functions *****************************************************/ 313 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 314 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 315 316 /* FLASH IRQ handler function */ 317 void HAL_FLASH_IRQHandler(void); 318 /* Callbacks in non blocking modes */ 319 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 320 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 321 322 /** 323 * @} 324 */ 325 326 /** @addtogroup FLASH_Exported_Functions_Group2 327 * @{ 328 */ 329 /* Peripheral Control functions ***********************************************/ 330 HAL_StatusTypeDef HAL_FLASH_Unlock(void); 331 HAL_StatusTypeDef HAL_FLASH_Lock(void); 332 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 333 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 334 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); 335 336 /** 337 * @} 338 */ 339 340 /** @addtogroup FLASH_Exported_Functions_Group3 341 * @{ 342 */ 343 /* Peripheral State and Error functions ***************************************/ 344 uint32_t HAL_FLASH_GetError(void); 345 346 /** 347 * @} 348 */ 349 350 /** 351 * @} 352 */ 353 354 /* Private function -------------------------------------------------*/ 355 /** @addtogroup FLASH_Private_Functions 356 * @{ 357 */ 358 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 359 360 /** 361 * @} 362 */ 363 364 /** 365 * @} 366 */ 367 368 /** 369 * @} 370 */ 371 372 #ifdef __cplusplus 373 } 374 #endif 375 376 #endif /* __STM32F3xx_HAL_FLASH_H */ 377 378 379