STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_flash.h 00004 * @author MCD Application Team 00005 * @brief Header file of FLASH HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F4xx_HAL_FLASH_H 00022 #define __STM32F4xx_HAL_FLASH_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f4xx_hal_def.h" 00030 00031 /** @addtogroup STM32F4xx_HAL_Driver 00032 * @{ 00033 */ 00034 00035 /** @addtogroup FLASH 00036 * @{ 00037 */ 00038 00039 /* Exported types ------------------------------------------------------------*/ 00040 /** @defgroup FLASH_Exported_Types FLASH Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief FLASH Procedure structure definition 00046 */ 00047 typedef enum 00048 { 00049 FLASH_PROC_NONE = 0U, 00050 FLASH_PROC_SECTERASE, 00051 FLASH_PROC_MASSERASE, 00052 FLASH_PROC_PROGRAM 00053 } FLASH_ProcedureTypeDef; 00054 00055 /** 00056 * @brief FLASH handle Structure definition 00057 */ 00058 typedef struct 00059 { 00060 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/ 00061 00062 __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/ 00063 00064 __IO uint8_t VoltageForErase; /*Internal variable to provide voltage range selected by user in IT context*/ 00065 00066 __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/ 00067 00068 __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/ 00069 00070 __IO uint32_t Address; /*Internal variable to save address selected for program*/ 00071 00072 HAL_LockTypeDef Lock; /* FLASH locking object */ 00073 00074 __IO uint32_t ErrorCode; /* FLASH error code */ 00075 00076 }FLASH_ProcessTypeDef; 00077 00078 /** 00079 * @} 00080 */ 00081 00082 /* Exported constants --------------------------------------------------------*/ 00083 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants 00084 * @{ 00085 */ 00086 /** @defgroup FLASH_Error_Code FLASH Error Code 00087 * @brief FLASH Error Code 00088 * @{ 00089 */ 00090 #define HAL_FLASH_ERROR_NONE 0x00000000U /*!< No error */ 00091 #define HAL_FLASH_ERROR_RD 0x00000001U /*!< Read Protection error */ 00092 #define HAL_FLASH_ERROR_PGS 0x00000002U /*!< Programming Sequence error */ 00093 #define HAL_FLASH_ERROR_PGP 0x00000004U /*!< Programming Parallelism error */ 00094 #define HAL_FLASH_ERROR_PGA 0x00000008U /*!< Programming Alignment error */ 00095 #define HAL_FLASH_ERROR_WRP 0x00000010U /*!< Write protection error */ 00096 #define HAL_FLASH_ERROR_OPERATION 0x00000020U /*!< Operation Error */ 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup FLASH_Type_Program FLASH Type Program 00102 * @{ 00103 */ 00104 #define FLASH_TYPEPROGRAM_BYTE 0x00000000U /*!< Program byte (8-bit) at a specified address */ 00105 #define FLASH_TYPEPROGRAM_HALFWORD 0x00000001U /*!< Program a half-word (16-bit) at a specified address */ 00106 #define FLASH_TYPEPROGRAM_WORD 0x00000002U /*!< Program a word (32-bit) at a specified address */ 00107 #define FLASH_TYPEPROGRAM_DOUBLEWORD 0x00000003U /*!< Program a double word (64-bit) at a specified address */ 00108 /** 00109 * @} 00110 */ 00111 00112 /** @defgroup FLASH_Flag_definition FLASH Flag definition 00113 * @brief Flag definition 00114 * @{ 00115 */ 00116 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */ 00117 #define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */ 00118 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ 00119 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */ 00120 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */ 00121 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */ 00122 #if defined(FLASH_SR_RDERR) 00123 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< Read Protection error flag (PCROP) */ 00124 #endif /* FLASH_SR_RDERR */ 00125 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ 00126 /** 00127 * @} 00128 */ 00129 00130 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition 00131 * @brief FLASH Interrupt definition 00132 * @{ 00133 */ 00134 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */ 00135 #define FLASH_IT_ERR 0x02000000U /*!< Error Interrupt source */ 00136 /** 00137 * @} 00138 */ 00139 00140 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism 00141 * @{ 00142 */ 00143 #define FLASH_PSIZE_BYTE 0x00000000U 00144 #define FLASH_PSIZE_HALF_WORD 0x00000100U 00145 #define FLASH_PSIZE_WORD 0x00000200U 00146 #define FLASH_PSIZE_DOUBLE_WORD 0x00000300U 00147 #define CR_PSIZE_MASK 0xFFFFFCFFU 00148 /** 00149 * @} 00150 */ 00151 00152 /** @defgroup FLASH_Keys FLASH Keys 00153 * @{ 00154 */ 00155 #define RDP_KEY ((uint16_t)0x00A5) 00156 #define FLASH_KEY1 0x45670123U 00157 #define FLASH_KEY2 0xCDEF89ABU 00158 #define FLASH_OPT_KEY1 0x08192A3BU 00159 #define FLASH_OPT_KEY2 0x4C5D6E7FU 00160 /** 00161 * @} 00162 */ 00163 00164 /** 00165 * @} 00166 */ 00167 00168 /* Exported macro ------------------------------------------------------------*/ 00169 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros 00170 * @{ 00171 */ 00172 /** 00173 * @brief Set the FLASH Latency. 00174 * @param __LATENCY__ FLASH Latency 00175 * The value of this parameter depend on device used within the same series 00176 * @retval none 00177 */ 00178 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__)) 00179 00180 /** 00181 * @brief Get the FLASH Latency. 00182 * @retval FLASH Latency 00183 * The value of this parameter depend on device used within the same series 00184 */ 00185 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) 00186 00187 /** 00188 * @brief Enable the FLASH prefetch buffer. 00189 * @retval none 00190 */ 00191 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN) 00192 00193 /** 00194 * @brief Disable the FLASH prefetch buffer. 00195 * @retval none 00196 */ 00197 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN)) 00198 00199 /** 00200 * @brief Enable the FLASH instruction cache. 00201 * @retval none 00202 */ 00203 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN) 00204 00205 /** 00206 * @brief Disable the FLASH instruction cache. 00207 * @retval none 00208 */ 00209 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN)) 00210 00211 /** 00212 * @brief Enable the FLASH data cache. 00213 * @retval none 00214 */ 00215 #define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN) 00216 00217 /** 00218 * @brief Disable the FLASH data cache. 00219 * @retval none 00220 */ 00221 #define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN)) 00222 00223 /** 00224 * @brief Resets the FLASH instruction Cache. 00225 * @note This function must be used only when the Instruction Cache is disabled. 00226 * @retval None 00227 */ 00228 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_ICRST; \ 00229 FLASH->ACR &= ~FLASH_ACR_ICRST; \ 00230 }while(0U) 00231 00232 /** 00233 * @brief Resets the FLASH data Cache. 00234 * @note This function must be used only when the data Cache is disabled. 00235 * @retval None 00236 */ 00237 #define __HAL_FLASH_DATA_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_DCRST; \ 00238 FLASH->ACR &= ~FLASH_ACR_DCRST; \ 00239 }while(0U) 00240 /** 00241 * @brief Enable the specified FLASH interrupt. 00242 * @param __INTERRUPT__ FLASH interrupt 00243 * This parameter can be any combination of the following values: 00244 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt 00245 * @arg FLASH_IT_ERR: Error Interrupt 00246 * @retval none 00247 */ 00248 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__)) 00249 00250 /** 00251 * @brief Disable the specified FLASH interrupt. 00252 * @param __INTERRUPT__ FLASH interrupt 00253 * This parameter can be any combination of the following values: 00254 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt 00255 * @arg FLASH_IT_ERR: Error Interrupt 00256 * @retval none 00257 */ 00258 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__)) 00259 00260 /** 00261 * @brief Get the specified FLASH flag status. 00262 * @param __FLAG__ specifies the FLASH flags to check. 00263 * This parameter can be any combination of the following values: 00264 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag 00265 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag 00266 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag 00267 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag 00268 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag 00269 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag 00270 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*) 00271 * @arg FLASH_FLAG_BSY : FLASH Busy flag 00272 * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices 00273 * @retval The new state of __FLAG__ (SET or RESET). 00274 */ 00275 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__))) 00276 00277 /** 00278 * @brief Clear the specified FLASH flags. 00279 * @param __FLAG__ specifies the FLASH flags to clear. 00280 * This parameter can be any combination of the following values: 00281 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag 00282 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag 00283 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag 00284 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag 00285 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag 00286 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag 00287 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*) 00288 * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices 00289 * @retval none 00290 */ 00291 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__)) 00292 /** 00293 * @} 00294 */ 00295 00296 /* Include FLASH HAL Extension module */ 00297 #include "stm32f4xx_hal_flash_ex.h" 00298 #include "stm32f4xx_hal_flash_ramfunc.h" 00299 00300 /* Exported functions --------------------------------------------------------*/ 00301 /** @addtogroup FLASH_Exported_Functions 00302 * @{ 00303 */ 00304 /** @addtogroup FLASH_Exported_Functions_Group1 00305 * @{ 00306 */ 00307 /* Program operation functions ***********************************************/ 00308 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 00309 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 00310 /* FLASH IRQ handler method */ 00311 void HAL_FLASH_IRQHandler(void); 00312 /* Callbacks in non blocking modes */ 00313 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 00314 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 00315 /** 00316 * @} 00317 */ 00318 00319 /** @addtogroup FLASH_Exported_Functions_Group2 00320 * @{ 00321 */ 00322 /* Peripheral Control functions **********************************************/ 00323 HAL_StatusTypeDef HAL_FLASH_Unlock(void); 00324 HAL_StatusTypeDef HAL_FLASH_Lock(void); 00325 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 00326 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 00327 /* Option bytes control */ 00328 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); 00329 /** 00330 * @} 00331 */ 00332 00333 /** @addtogroup FLASH_Exported_Functions_Group3 00334 * @{ 00335 */ 00336 /* Peripheral State functions ************************************************/ 00337 uint32_t HAL_FLASH_GetError(void); 00338 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 00339 /** 00340 * @} 00341 */ 00342 00343 /** 00344 * @} 00345 */ 00346 /* Private types -------------------------------------------------------------*/ 00347 /* Private variables ---------------------------------------------------------*/ 00348 /** @defgroup FLASH_Private_Variables FLASH Private Variables 00349 * @{ 00350 */ 00351 00352 /** 00353 * @} 00354 */ 00355 /* Private constants ---------------------------------------------------------*/ 00356 /** @defgroup FLASH_Private_Constants FLASH Private Constants 00357 * @{ 00358 */ 00359 00360 /** 00361 * @brief ACR register byte 0 (Bits[7:0]) base address 00362 */ 00363 #define ACR_BYTE0_ADDRESS 0x40023C00U 00364 /** 00365 * @brief OPTCR register byte 0 (Bits[7:0]) base address 00366 */ 00367 #define OPTCR_BYTE0_ADDRESS 0x40023C14U 00368 /** 00369 * @brief OPTCR register byte 1 (Bits[15:8]) base address 00370 */ 00371 #define OPTCR_BYTE1_ADDRESS 0x40023C15U 00372 /** 00373 * @brief OPTCR register byte 2 (Bits[23:16]) base address 00374 */ 00375 #define OPTCR_BYTE2_ADDRESS 0x40023C16U 00376 /** 00377 * @brief OPTCR register byte 3 (Bits[31:24]) base address 00378 */ 00379 #define OPTCR_BYTE3_ADDRESS 0x40023C17U 00380 00381 /** 00382 * @} 00383 */ 00384 00385 /* Private macros ------------------------------------------------------------*/ 00386 /** @defgroup FLASH_Private_Macros FLASH Private Macros 00387 * @{ 00388 */ 00389 00390 /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters 00391 * @{ 00392 */ 00393 #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \ 00394 ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ 00395 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ 00396 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) 00397 /** 00398 * @} 00399 */ 00400 00401 /** 00402 * @} 00403 */ 00404 00405 /* Private functions ---------------------------------------------------------*/ 00406 /** @defgroup FLASH_Private_Functions FLASH Private Functions 00407 * @{ 00408 */ 00409 00410 /** 00411 * @} 00412 */ 00413 00414 /** 00415 * @} 00416 */ 00417 00418 /** 00419 * @} 00420 */ 00421 00422 #ifdef __cplusplus 00423 } 00424 #endif 00425 00426 #endif /* __STM32F4xx_HAL_FLASH_H */ 00427 00428 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/