2 ******************************************************************************
3 * @file stm32f1xx_hal_flash.h
4 * @author MCD Application Team
7 * @brief Header file of Flash HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F1xx_HAL_FLASH_H
40 #define __STM32F1xx_HAL_FLASH_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx_hal_def.h"
49 /** @addtogroup STM32F1xx_HAL_Driver
57 /** @addtogroup FLASH_Private_Constants
60 #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */
65 /** @addtogroup FLASH_Private_Macros
69 #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
70 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
71 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
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))
79 #define IS_FLASH_LATENCY(__LATENCY__) ((__LATENCY__) == FLASH_LATENCY_0)
80 #endif /* FLASH_ACR_LATENCY */
85 /* Exported types ------------------------------------------------------------*/
86 /** @defgroup FLASH_Exported_Types FLASH Exported Types
91 * @brief FLASH Procedure structure definition
96 FLASH_PROC_PAGEERASE
= 1U,
97 FLASH_PROC_MASSERASE
= 2U,
98 FLASH_PROC_PROGRAMHALFWORD
= 3U,
99 FLASH_PROC_PROGRAMWORD
= 4U,
100 FLASH_PROC_PROGRAMDOUBLEWORD
= 5U
101 } FLASH_ProcedureTypeDef
;
104 * @brief FLASH handle Structure definition
108 __IO FLASH_ProcedureTypeDef ProcedureOnGoing
; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
110 __IO
uint32_t DataRemaining
; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
112 __IO
uint32_t Address
; /*!< Internal variable to save address selected for program or erase */
114 __IO
uint64_t Data
; /*!< Internal variable to save data to be programmed */
116 HAL_LockTypeDef Lock
; /*!< FLASH locking object */
118 __IO
uint32_t ErrorCode
; /*!< FLASH error code
119 This parameter can be a value of @ref FLASH_Error_Codes */
120 } FLASH_ProcessTypeDef
;
126 /* Exported constants --------------------------------------------------------*/
127 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
131 /** @defgroup FLASH_Error_Codes FLASH Error Codes
135 #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
136 #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */
137 #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
138 #define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */
144 /** @defgroup FLASH_Type_Program FLASH Type Program
147 #define FLASH_TYPEPROGRAM_HALFWORD 0x01U /*!<Program a half-word (16-bit) at a specified address.*/
148 #define FLASH_TYPEPROGRAM_WORD 0x02U /*!<Program a word (32-bit) at a specified address.*/
149 #define FLASH_TYPEPROGRAM_DOUBLEWORD 0x03U /*!<Program a double word (64-bit) at a specified address*/
155 #if defined(FLASH_ACR_LATENCY)
156 /** @defgroup FLASH_Latency FLASH Latency
159 #define FLASH_LATENCY_0 0x00000000U /*!< FLASH Zero Latency cycle */
160 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */
161 #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */
168 /** @defgroup FLASH_Latency FLASH Latency
171 #define FLASH_LATENCY_0 0x00000000U /*!< FLASH Zero Latency cycle */
177 #endif /* FLASH_ACR_LATENCY */
182 /* Exported macro ------------------------------------------------------------*/
184 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
185 * @brief macros to control FLASH features
189 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
190 * @brief macros to handle FLASH half cycle
195 * @brief Enable the FLASH half cycle access.
196 * @note half cycle access can only be used with a low-frequency clock of less than
197 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
200 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA)
203 * @brief Disable the FLASH half cycle access.
204 * @note half cycle access can only be used with a low-frequency clock of less than
205 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
208 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
214 #if defined(FLASH_ACR_LATENCY)
215 /** @defgroup FLASH_EM_Latency FLASH Latency
216 * @brief macros to handle FLASH Latency
221 * @brief Set the FLASH Latency.
222 * @param __LATENCY__ FLASH Latency
223 * The value of this parameter depend on device used within the same series
226 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
230 * @brief Get the FLASH Latency.
231 * @retval FLASH Latency
232 * The value of this parameter depend on device used within the same series
234 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
240 #endif /* FLASH_ACR_LATENCY */
241 /** @defgroup FLASH_Prefetch FLASH Prefetch
242 * @brief macros to handle FLASH Prefetch buffer
246 * @brief Enable the FLASH prefetch buffer.
249 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
252 * @brief Disable the FLASH prefetch buffer.
255 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
265 /* Include FLASH HAL Extended module */
266 #include "stm32f1xx_hal_flash_ex.h"
268 /* Exported functions --------------------------------------------------------*/
269 /** @addtogroup FLASH_Exported_Functions
273 /** @addtogroup FLASH_Exported_Functions_Group1
276 /* IO operation functions *****************************************************/
277 HAL_StatusTypeDef
HAL_FLASH_Program(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
278 HAL_StatusTypeDef
HAL_FLASH_Program_IT(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
280 /* FLASH IRQ handler function */
281 void HAL_FLASH_IRQHandler(void);
282 /* Callbacks in non blocking modes */
283 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue
);
284 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue
);
290 /** @addtogroup FLASH_Exported_Functions_Group2
293 /* Peripheral Control functions ***********************************************/
294 HAL_StatusTypeDef
HAL_FLASH_Unlock(void);
295 HAL_StatusTypeDef
HAL_FLASH_Lock(void);
296 HAL_StatusTypeDef
HAL_FLASH_OB_Unlock(void);
297 HAL_StatusTypeDef
HAL_FLASH_OB_Lock(void);
298 void HAL_FLASH_OB_Launch(void);
304 /** @addtogroup FLASH_Exported_Functions_Group3
307 /* Peripheral State and Error functions ***************************************/
308 uint32_t HAL_FLASH_GetError(void);
318 /* Private function -------------------------------------------------*/
319 /** @addtogroup FLASH_Private_Functions
322 HAL_StatusTypeDef
FLASH_WaitForLastOperation(uint32_t Timeout
);
323 #if defined(FLASH_BANK2_END)
324 HAL_StatusTypeDef
FLASH_WaitForLastOperationBank2(uint32_t Timeout
);
325 #endif /* FLASH_BANK2_END */
343 #endif /* __STM32F1xx_HAL_FLASH_H */
345 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/