2 ******************************************************************************
3 * @file stm32f3xx_hal_flash.h
4 * @author MCD Application Team
5 * @brief Header file of Flash HAL module.
6 ******************************************************************************
9 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F3xx_HAL_FLASH_H
38 #define __STM32F3xx_HAL_FLASH_H
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx_hal_def.h"
47 /** @addtogroup STM32F3xx_HAL_Driver
55 /** @addtogroup FLASH_Private_Constants
58 #define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */
63 /** @addtogroup FLASH_Private_Macros
67 #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
68 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
69 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
71 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
72 ((__LATENCY__) == FLASH_LATENCY_1) || \
73 ((__LATENCY__) == FLASH_LATENCY_2))
79 /* Exported types ------------------------------------------------------------*/
80 /** @defgroup FLASH_Exported_Types FLASH Exported Types
85 * @brief FLASH Procedure structure definition
90 FLASH_PROC_PAGEERASE
= 1U,
91 FLASH_PROC_MASSERASE
= 2U,
92 FLASH_PROC_PROGRAMHALFWORD
= 3U,
93 FLASH_PROC_PROGRAMWORD
= 4U,
94 FLASH_PROC_PROGRAMDOUBLEWORD
= 5U
95 } FLASH_ProcedureTypeDef
;
98 * @brief FLASH handle Structure definition
102 __IO FLASH_ProcedureTypeDef ProcedureOnGoing
; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
104 __IO
uint32_t DataRemaining
; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
106 __IO
uint32_t Address
; /*!< Internal variable to save address selected for program or erase */
108 __IO
uint64_t Data
; /*!< Internal variable to save data to be programmed */
110 HAL_LockTypeDef Lock
; /*!< FLASH locking object */
112 __IO
uint32_t ErrorCode
; /*!< FLASH error code
113 This parameter can be a value of @ref FLASH_Error_Codes */
114 } FLASH_ProcessTypeDef
;
120 /* Exported constants --------------------------------------------------------*/
121 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
125 /** @defgroup FLASH_Error_Codes FLASH Error Codes
129 #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
130 #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */
131 #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
137 /** @defgroup FLASH_Type_Program FLASH Type Program
140 #define FLASH_TYPEPROGRAM_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/
141 #define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
142 #define FLASH_TYPEPROGRAM_DOUBLEWORD (0x03U) /*!<Program a double word (64-bit) at a specified address*/
148 /** @defgroup FLASH_Latency FLASH Latency
151 #define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */
152 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */
153 #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */
160 /** @defgroup FLASH_Flag_definition FLASH Flag definition
163 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
164 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
165 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
166 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
171 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
174 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
175 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
184 /* Exported macro ------------------------------------------------------------*/
186 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
187 * @brief macros to control FLASH features
191 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
192 * @brief macros to handle FLASH half cycle
197 * @brief Enable the FLASH half cycle access.
200 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA)
203 * @brief Disable the FLASH half cycle access.
206 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
212 /** @defgroup FLASH_EM_Latency FLASH Latency
213 * @brief macros to handle FLASH Latency
218 * @brief Set the FLASH Latency.
219 * @param __LATENCY__ FLASH Latency
220 * This parameter can be one of the following values:
221 * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
222 * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
223 * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles
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 * This parameter can be one of the following values:
233 * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
234 * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
235 * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles
237 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
243 /** @defgroup FLASH_Prefetch FLASH Prefetch
244 * @brief macros to handle FLASH Prefetch buffer
248 * @brief Enable the FLASH prefetch buffer.
251 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
254 * @brief Disable the FLASH prefetch buffer.
257 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
263 /** @defgroup FLASH_Interrupt FLASH Interrupts
264 * @brief macros to handle FLASH interrupts
269 * @brief Enable the specified FLASH interrupt.
270 * @param __INTERRUPT__ FLASH interrupt
271 * This parameter can be any combination of the following values:
272 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
273 * @arg @ref FLASH_IT_ERR Error Interrupt
276 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__))
279 * @brief Disable the specified FLASH interrupt.
280 * @param __INTERRUPT__ FLASH interrupt
281 * This parameter can be any combination of the following values:
282 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
283 * @arg @ref FLASH_IT_ERR Error Interrupt
286 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__))
289 * @brief Get the specified FLASH flag status.
290 * @param __FLAG__ specifies the FLASH flag to check.
291 * This parameter can be one of the following values:
292 * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
293 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
294 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
295 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
296 * @retval The new state of __FLAG__ (SET or RESET).
298 #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
301 * @brief Clear the specified FLASH flag.
302 * @param __FLAG__ specifies the FLASH flags to clear.
303 * This parameter can be any combination of the following values:
304 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
305 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
306 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
309 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
319 /* Include FLASH HAL Extended module */
320 #include "stm32f3xx_hal_flash_ex.h"
322 /* Exported functions --------------------------------------------------------*/
323 /** @addtogroup FLASH_Exported_Functions
327 /** @addtogroup FLASH_Exported_Functions_Group1
330 /* IO operation functions *****************************************************/
331 HAL_StatusTypeDef
HAL_FLASH_Program(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
332 HAL_StatusTypeDef
HAL_FLASH_Program_IT(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
334 /* FLASH IRQ handler function */
335 void HAL_FLASH_IRQHandler(void);
336 /* Callbacks in non blocking modes */
337 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue
);
338 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue
);
344 /** @addtogroup FLASH_Exported_Functions_Group2
347 /* Peripheral Control functions ***********************************************/
348 HAL_StatusTypeDef
HAL_FLASH_Unlock(void);
349 HAL_StatusTypeDef
HAL_FLASH_Lock(void);
350 HAL_StatusTypeDef
HAL_FLASH_OB_Unlock(void);
351 HAL_StatusTypeDef
HAL_FLASH_OB_Lock(void);
352 HAL_StatusTypeDef
HAL_FLASH_OB_Launch(void);
358 /** @addtogroup FLASH_Exported_Functions_Group3
361 /* Peripheral State and Error functions ***************************************/
362 uint32_t HAL_FLASH_GetError(void);
372 /* Private function -------------------------------------------------*/
373 /** @addtogroup FLASH_Private_Functions
376 HAL_StatusTypeDef
FLASH_WaitForLastOperation(uint32_t Timeout
);
394 #endif /* __STM32F3xx_HAL_FLASH_H */
396 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/