Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f1xx_hal_flash.h Source File

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   * @version V1.0.4
00006   * @date    29-April-2016
00007   * @brief   Header file of Flash HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************  
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32F1xx_HAL_FLASH_H
00040 #define __STM32F1xx_HAL_FLASH_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32f1xx_hal_def.h"
00048    
00049 /** @addtogroup STM32F1xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup FLASH
00054   * @{
00055   */
00056   
00057 /** @addtogroup FLASH_Private_Constants
00058   * @{
00059   */
00060 #define FLASH_TIMEOUT_VALUE   ((uint32_t)50000)/* 50 s */
00061 /**
00062   * @}
00063   */
00064 
00065 /** @addtogroup FLASH_Private_Macros
00066   * @{
00067   */
00068 
00069 #define IS_FLASH_TYPEPROGRAM(VALUE)  (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
00070                                       ((VALUE) == FLASH_TYPEPROGRAM_WORD)     || \
00071                                       ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))  
00072 
00073 #if   defined(FLASH_ACR_LATENCY)
00074 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
00075                                        ((__LATENCY__) == FLASH_LATENCY_1) || \
00076                                        ((__LATENCY__) == FLASH_LATENCY_2))
00077 
00078 #else
00079 #define IS_FLASH_LATENCY(__LATENCY__)   ((__LATENCY__) == FLASH_LATENCY_0)
00080 #endif /* FLASH_ACR_LATENCY */
00081 /**
00082   * @}
00083   */  
00084 
00085 /* Exported types ------------------------------------------------------------*/ 
00086 /** @defgroup FLASH_Exported_Types FLASH Exported Types
00087   * @{
00088   */  
00089 
00090 
00091 /**
00092   * @brief  FLASH Procedure structure definition
00093   */
00094 typedef enum 
00095 {
00096   FLASH_PROC_NONE              = 0, 
00097   FLASH_PROC_PAGEERASE         = 1,
00098   FLASH_PROC_MASSERASE         = 2,
00099   FLASH_PROC_PROGRAMHALFWORD   = 3,
00100   FLASH_PROC_PROGRAMWORD       = 4,
00101   FLASH_PROC_PROGRAMDOUBLEWORD = 5
00102 } FLASH_ProcedureTypeDef;
00103 
00104 /** 
00105   * @brief  FLASH handle Structure definition  
00106   */
00107 typedef struct
00108 {
00109   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
00110   
00111   __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
00112 
00113   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
00114 
00115   __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
00116 
00117   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
00118 
00119   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
00120                                                      This parameter can be a value of @ref FLASH_Error_Codes  */
00121 } FLASH_ProcessTypeDef;
00122 
00123 /**
00124   * @}
00125   */
00126 
00127 /* Exported constants --------------------------------------------------------*/
00128 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
00129   * @{
00130   */  
00131 
00132 /** @defgroup FLASH_Error_Codes FLASH Error Codes
00133   * @{
00134   */
00135 
00136 #define HAL_FLASH_ERROR_NONE      ((uint32_t)0x00)  /*!< No error */
00137 #define HAL_FLASH_ERROR_PROG      ((uint32_t)0x01)  /*!< Programming error */
00138 #define HAL_FLASH_ERROR_WRP       ((uint32_t)0x02)  /*!< Write protection error */
00139 #define HAL_FLASH_ERROR_OPTV      ((uint32_t)0x04)  /*!< Option validity error */
00140 
00141 /**
00142   * @}
00143   */
00144 
00145 /** @defgroup FLASH_Type_Program FLASH Type Program
00146   * @{
00147   */ 
00148 #define FLASH_TYPEPROGRAM_HALFWORD   ((uint32_t)0x01)  /*!<Program a half-word (16-bit) at a specified address.*/
00149 #define FLASH_TYPEPROGRAM_WORD       ((uint32_t)0x02)  /*!<Program a word (32-bit) at a specified address.*/
00150 #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03)  /*!<Program a double word (64-bit) at a specified address*/
00151 
00152 /**
00153   * @}
00154   */
00155 
00156 #if   defined(FLASH_ACR_LATENCY)
00157 /** @defgroup FLASH_Latency FLASH Latency
00158   * @{
00159   */
00160 #define FLASH_LATENCY_0            ((uint32_t)0x00000000)    /*!< FLASH Zero Latency cycle */
00161 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
00162 #define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
00163 
00164 /**
00165   * @}
00166   */
00167 
00168 #else
00169 /** @defgroup FLASH_Latency FLASH Latency
00170   * @{
00171   */
00172 #define FLASH_LATENCY_0            ((uint32_t)0x00000000)    /*!< FLASH Zero Latency cycle */
00173 
00174 /**
00175   * @}
00176   */
00177 
00178 #endif /* FLASH_ACR_LATENCY */
00179 /**
00180   * @}
00181   */  
00182   
00183 /* Exported macro ------------------------------------------------------------*/
00184 
00185 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
00186  *  @brief macros to control FLASH features 
00187  *  @{
00188  */
00189  
00190 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
00191  *  @brief macros to handle FLASH half cycle
00192  * @{
00193  */
00194 
00195 /**
00196   * @brief  Enable the FLASH half cycle access.
00197   * @note   half cycle access can only be used with a low-frequency clock of less than
00198             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
00199   * @retval None
00200   */
00201 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE()  (FLASH->ACR |= FLASH_ACR_HLFCYA)
00202 
00203 /**
00204   * @brief  Disable the FLASH half cycle access.
00205   * @note   half cycle access can only be used with a low-frequency clock of less than
00206             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
00207   * @retval None
00208   */
00209 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
00210 
00211 /**
00212   * @}
00213   */
00214 
00215 #if defined(FLASH_ACR_LATENCY)
00216 /** @defgroup FLASH_EM_Latency FLASH Latency
00217  *  @brief macros to handle FLASH Latency
00218  * @{
00219  */ 
00220   
00221 /**
00222   * @brief  Set the FLASH Latency.
00223   * @param  __LATENCY__ FLASH Latency                   
00224   *         The value of this parameter depend on device used within the same series
00225   * @retval None
00226   */ 
00227 #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
00228 
00229 
00230 /**
00231   * @brief  Get the FLASH Latency.
00232   * @retval FLASH Latency                   
00233   *         The value of this parameter depend on device used within the same series
00234   */ 
00235 #define __HAL_FLASH_GET_LATENCY()     (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
00236 
00237 /**
00238   * @}
00239   */
00240 
00241 #endif /* FLASH_ACR_LATENCY */
00242 /** @defgroup FLASH_Prefetch FLASH Prefetch
00243  *  @brief macros to handle FLASH Prefetch buffer
00244  * @{
00245  */   
00246 /**
00247   * @brief  Enable the FLASH prefetch buffer.
00248   * @retval None
00249   */ 
00250 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
00251 
00252 /**
00253   * @brief  Disable the FLASH prefetch buffer.
00254   * @retval None
00255   */
00256 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
00257 
00258 /**
00259   * @}
00260   */
00261   
00262 /**
00263   * @}
00264   */ 
00265 
00266 /* Include FLASH HAL Extended module */
00267 #include "stm32f1xx_hal_flash_ex.h"  
00268 
00269 /* Exported functions --------------------------------------------------------*/
00270 /** @addtogroup FLASH_Exported_Functions
00271   * @{
00272   */
00273   
00274 /** @addtogroup FLASH_Exported_Functions_Group1
00275   * @{
00276   */
00277 /* IO operation functions *****************************************************/
00278 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
00279 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
00280 
00281 /* FLASH IRQ handler function */
00282 void       HAL_FLASH_IRQHandler(void);
00283 /* Callbacks in non blocking modes */ 
00284 void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
00285 void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
00286 
00287 /**
00288   * @}
00289   */
00290 
00291 /** @addtogroup FLASH_Exported_Functions_Group2
00292   * @{
00293   */
00294 /* Peripheral Control functions ***********************************************/
00295 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
00296 HAL_StatusTypeDef HAL_FLASH_Lock(void);
00297 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
00298 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
00299 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
00300 
00301 /**
00302   * @}
00303   */
00304 
00305 /** @addtogroup FLASH_Exported_Functions_Group3
00306   * @{
00307   */
00308 /* Peripheral State and Error functions ***************************************/
00309 uint32_t HAL_FLASH_GetError(void);
00310 
00311 /**
00312   * @}
00313   */
00314 
00315 /**
00316   * @}
00317   */
00318 
00319 /* Private function -------------------------------------------------*/
00320 /** @addtogroup FLASH_Private_Functions
00321  * @{
00322  */
00323 void                    FLASH_PageErase(uint32_t PageAddress);
00324 HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
00325 #if defined(FLASH_BANK2_END)
00326 HAL_StatusTypeDef       FLASH_WaitForLastOperationBank2(uint32_t Timeout);
00327 #endif /* FLASH_BANK2_END */
00328 
00329 /**
00330   * @}
00331   */
00332 
00333 /**
00334   * @}
00335   */
00336 
00337 /**
00338   * @}
00339   */
00340 
00341 #ifdef __cplusplus
00342 }
00343 #endif
00344 
00345 #endif /* __STM32F1xx_HAL_FLASH_H */
00346 
00347 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00348