STM32F103xB HAL User Manual
stm32f1xx_hal_flash.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_flash.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of Flash HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 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 __STM32F1xx_HAL_FLASH_H
00022 #define __STM32F1xx_HAL_FLASH_H
00023 
00024 #ifdef __cplusplus
00025  extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f1xx_hal_def.h"
00030    
00031 /** @addtogroup STM32F1xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup FLASH
00036   * @{
00037   */
00038   
00039 /** @addtogroup FLASH_Private_Constants
00040   * @{
00041   */
00042 #define FLASH_TIMEOUT_VALUE              50000U /* 50 s */
00043 /**
00044   * @}
00045   */
00046 
00047 /** @addtogroup FLASH_Private_Macros
00048   * @{
00049   */
00050 
00051 #define IS_FLASH_TYPEPROGRAM(VALUE)  (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
00052                                       ((VALUE) == FLASH_TYPEPROGRAM_WORD)     || \
00053                                       ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))  
00054 
00055 #if   defined(FLASH_ACR_LATENCY)
00056 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
00057                                        ((__LATENCY__) == FLASH_LATENCY_1) || \
00058                                        ((__LATENCY__) == FLASH_LATENCY_2))
00059 
00060 #else
00061 #define IS_FLASH_LATENCY(__LATENCY__)   ((__LATENCY__) == FLASH_LATENCY_0)
00062 #endif /* FLASH_ACR_LATENCY */
00063 /**
00064   * @}
00065   */  
00066 
00067 /* Exported types ------------------------------------------------------------*/ 
00068 /** @defgroup FLASH_Exported_Types FLASH Exported Types
00069   * @{
00070   */  
00071 
00072 /**
00073   * @brief  FLASH Procedure structure definition
00074   */
00075 typedef enum 
00076 {
00077   FLASH_PROC_NONE              = 0U, 
00078   FLASH_PROC_PAGEERASE         = 1U,
00079   FLASH_PROC_MASSERASE         = 2U,
00080   FLASH_PROC_PROGRAMHALFWORD   = 3U,
00081   FLASH_PROC_PROGRAMWORD       = 4U,
00082   FLASH_PROC_PROGRAMDOUBLEWORD = 5U
00083 } FLASH_ProcedureTypeDef;
00084 
00085 /** 
00086   * @brief  FLASH handle Structure definition  
00087   */
00088 typedef struct
00089 {
00090   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
00091   
00092   __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
00093 
00094   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
00095 
00096   __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
00097 
00098   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
00099 
00100   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
00101                                                      This parameter can be a value of @ref FLASH_Error_Codes  */
00102 } FLASH_ProcessTypeDef;
00103 
00104 /**
00105   * @}
00106   */
00107 
00108 /* Exported constants --------------------------------------------------------*/
00109 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
00110   * @{
00111   */  
00112 
00113 /** @defgroup FLASH_Error_Codes FLASH Error Codes
00114   * @{
00115   */
00116 
00117 #define HAL_FLASH_ERROR_NONE      0x00U  /*!< No error */
00118 #define HAL_FLASH_ERROR_PROG      0x01U  /*!< Programming error */
00119 #define HAL_FLASH_ERROR_WRP       0x02U  /*!< Write protection error */
00120 #define HAL_FLASH_ERROR_OPTV      0x04U  /*!< Option validity error */
00121 
00122 /**
00123   * @}
00124   */
00125 
00126 /** @defgroup FLASH_Type_Program FLASH Type Program
00127   * @{
00128   */ 
00129 #define FLASH_TYPEPROGRAM_HALFWORD             0x01U  /*!<Program a half-word (16-bit) at a specified address.*/
00130 #define FLASH_TYPEPROGRAM_WORD                 0x02U  /*!<Program a word (32-bit) at a specified address.*/
00131 #define FLASH_TYPEPROGRAM_DOUBLEWORD           0x03U  /*!<Program a double word (64-bit) at a specified address*/
00132 
00133 /**
00134   * @}
00135   */
00136 
00137 #if   defined(FLASH_ACR_LATENCY)
00138 /** @defgroup FLASH_Latency FLASH Latency
00139   * @{
00140   */
00141 #define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
00142 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
00143 #define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
00144 
00145 /**
00146   * @}
00147   */
00148 
00149 #else
00150 /** @defgroup FLASH_Latency FLASH Latency
00151   * @{
00152   */
00153 #define FLASH_LATENCY_0            0x00000000U    /*!< FLASH Zero Latency cycle */
00154 
00155 /**
00156   * @}
00157   */
00158 
00159 #endif /* FLASH_ACR_LATENCY */
00160 /**
00161   * @}
00162   */  
00163   
00164 /* Exported macro ------------------------------------------------------------*/
00165 
00166 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
00167  *  @brief macros to control FLASH features 
00168  *  @{
00169  */
00170  
00171 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
00172  *  @brief macros to handle FLASH half cycle
00173  * @{
00174  */
00175 
00176 /**
00177   * @brief  Enable the FLASH half cycle access.
00178   * @note   half cycle access can only be used with a low-frequency clock of less than
00179             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
00180   * @retval None
00181   */
00182 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE()  (FLASH->ACR |= FLASH_ACR_HLFCYA)
00183 
00184 /**
00185   * @brief  Disable the FLASH half cycle access.
00186   * @note   half cycle access can only be used with a low-frequency clock of less than
00187             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
00188   * @retval None
00189   */
00190 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
00191 
00192 /**
00193   * @}
00194   */
00195 
00196 #if defined(FLASH_ACR_LATENCY)
00197 /** @defgroup FLASH_EM_Latency FLASH Latency
00198  *  @brief macros to handle FLASH Latency
00199  * @{
00200  */ 
00201   
00202 /**
00203   * @brief  Set the FLASH Latency.
00204   * @param  __LATENCY__ FLASH Latency                   
00205   *         The value of this parameter depend on device used within the same series
00206   * @retval None
00207   */ 
00208 #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
00209 
00210 
00211 /**
00212   * @brief  Get the FLASH Latency.
00213   * @retval FLASH Latency                   
00214   *         The value of this parameter depend on device used within the same series
00215   */ 
00216 #define __HAL_FLASH_GET_LATENCY()     (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
00217 
00218 /**
00219   * @}
00220   */
00221 
00222 #endif /* FLASH_ACR_LATENCY */
00223 /** @defgroup FLASH_Prefetch FLASH Prefetch
00224  *  @brief macros to handle FLASH Prefetch buffer
00225  * @{
00226  */   
00227 /**
00228   * @brief  Enable the FLASH prefetch buffer.
00229   * @retval None
00230   */ 
00231 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
00232 
00233 /**
00234   * @brief  Disable the FLASH prefetch buffer.
00235   * @retval None
00236   */
00237 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
00238 
00239 /**
00240   * @}
00241   */
00242   
00243 /**
00244   * @}
00245   */ 
00246 
00247 /* Include FLASH HAL Extended module */
00248 #include "stm32f1xx_hal_flash_ex.h"  
00249 
00250 /* Exported functions --------------------------------------------------------*/
00251 /** @addtogroup FLASH_Exported_Functions
00252   * @{
00253   */
00254   
00255 /** @addtogroup FLASH_Exported_Functions_Group1
00256   * @{
00257   */
00258 /* IO operation functions *****************************************************/
00259 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
00260 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
00261 
00262 /* FLASH IRQ handler function */
00263 void       HAL_FLASH_IRQHandler(void);
00264 /* Callbacks in non blocking modes */ 
00265 void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
00266 void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
00267 
00268 /**
00269   * @}
00270   */
00271 
00272 /** @addtogroup FLASH_Exported_Functions_Group2
00273   * @{
00274   */
00275 /* Peripheral Control functions ***********************************************/
00276 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
00277 HAL_StatusTypeDef HAL_FLASH_Lock(void);
00278 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
00279 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
00280 void HAL_FLASH_OB_Launch(void);
00281 
00282 /**
00283   * @}
00284   */
00285 
00286 /** @addtogroup FLASH_Exported_Functions_Group3
00287   * @{
00288   */
00289 /* Peripheral State and Error functions ***************************************/
00290 uint32_t HAL_FLASH_GetError(void);
00291 
00292 /**
00293   * @}
00294   */
00295 
00296 /**
00297   * @}
00298   */
00299 
00300 /* Private function -------------------------------------------------*/
00301 /** @addtogroup FLASH_Private_Functions
00302  * @{
00303  */
00304 HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
00305 #if defined(FLASH_BANK2_END)
00306 HAL_StatusTypeDef       FLASH_WaitForLastOperationBank2(uint32_t Timeout);
00307 #endif /* FLASH_BANK2_END */
00308 
00309 /**
00310   * @}
00311   */
00312 
00313 /**
00314   * @}
00315   */
00316 
00317 /**
00318   * @}
00319   */
00320 
00321 #ifdef __cplusplus
00322 }
00323 #endif
00324 
00325 #endif /* __STM32F1xx_HAL_FLASH_H */
00326 
00327 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00328