2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_flash.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of FLASH HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef __STM32F7xx_HAL_FLASH_H
\r
22 #define __STM32F7xx_HAL_FLASH_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32f7xx_hal_def.h"
\r
31 /** @addtogroup STM32F7xx_HAL_Driver
\r
35 /** @addtogroup FLASH
\r
39 /* Exported types ------------------------------------------------------------*/
\r
40 /** @defgroup FLASH_Exported_Types FLASH Exported Types
\r
45 * @brief FLASH Procedure structure definition
\r
49 FLASH_PROC_NONE = 0U,
\r
50 FLASH_PROC_SECTERASE,
\r
51 FLASH_PROC_MASSERASE,
\r
53 } FLASH_ProcedureTypeDef;
\r
57 * @brief FLASH handle Structure definition
\r
61 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
\r
63 __IO uint32_t NbSectorsToErase; /* Internal variable to save the remaining sectors to erase in IT context */
\r
65 __IO uint8_t VoltageForErase; /* Internal variable to provide voltage range selected by user in IT context */
\r
67 __IO uint32_t Sector; /* Internal variable to define the current sector which is erasing */
\r
69 __IO uint32_t Address; /* Internal variable to save address selected for program */
\r
71 HAL_LockTypeDef Lock; /* FLASH locking object */
\r
73 __IO uint32_t ErrorCode; /* FLASH error code */
\r
75 }FLASH_ProcessTypeDef;
\r
81 /* Exported constants --------------------------------------------------------*/
\r
82 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
\r
86 /** @defgroup FLASH_Error_Code FLASH Error Code
\r
87 * @brief FLASH Error Code
\r
90 #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
\r
91 #define HAL_FLASH_ERROR_ERS ((uint32_t)0x00000002U) /*!< Programming Sequence error */
\r
92 #define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004U) /*!< Programming Parallelism error */
\r
93 #define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008U) /*!< Programming Alignment error */
\r
94 #define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010U) /*!< Write protection error */
\r
95 #define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020U) /*!< Operation Error */
\r
96 #define HAL_FLASH_ERROR_RD ((uint32_t)0x00000040U) /*!< Read Protection Error */
\r
101 /** @defgroup FLASH_Type_Program FLASH Type Program
\r
104 #define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00U) /*!< Program byte (8-bit) at a specified address */
\r
105 #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01U) /*!< Program a half-word (16-bit) at a specified address */
\r
106 #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02U) /*!< Program a word (32-bit) at a specified address */
\r
107 #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03U) /*!< Program a double word (64-bit) at a specified address */
\r
112 /** @defgroup FLASH_Flag_definition FLASH Flag definition
\r
113 * @brief Flag definition
\r
116 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
\r
117 #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */
\r
118 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
\r
119 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
\r
120 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
\r
121 #define FLASH_FLAG_ERSERR FLASH_SR_ERSERR /*!< FLASH Erasing Sequence error flag */
\r
122 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
\r
124 #if defined (FLASH_OPTCR2_PCROP)
\r
125 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH Read protection error flag */
\r
126 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
\r
127 FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR | FLASH_FLAG_RDERR)
\r
129 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
\r
130 FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR)
\r
131 #endif /* FLASH_OPTCR2_PCROP */
\r
136 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
\r
137 * @brief FLASH Interrupt definition
\r
140 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
\r
141 #define FLASH_IT_ERR ((uint32_t)0x02000000U) /*!< Error Interrupt source */
\r
146 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
\r
149 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000U)
\r
150 #define FLASH_PSIZE_HALF_WORD ((uint32_t)FLASH_CR_PSIZE_0)
\r
151 #define FLASH_PSIZE_WORD ((uint32_t)FLASH_CR_PSIZE_1)
\r
152 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)FLASH_CR_PSIZE)
\r
153 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFFU)
\r
158 /** @defgroup FLASH_Keys FLASH Keys
\r
161 #define FLASH_KEY1 ((uint32_t)0x45670123U)
\r
162 #define FLASH_KEY2 ((uint32_t)0xCDEF89ABU)
\r
163 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3BU)
\r
164 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7FU)
\r
169 /** @defgroup FLASH_Sectors FLASH Sectors
\r
172 #if (FLASH_SECTOR_TOTAL == 2)
\r
173 #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
\r
174 #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
\r
175 #elif (FLASH_SECTOR_TOTAL == 4)
\r
176 #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
\r
177 #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
\r
178 #define FLASH_SECTOR_2 ((uint32_t)2U) /*!< Sector Number 2 */
\r
179 #define FLASH_SECTOR_3 ((uint32_t)3U) /*!< Sector Number 3 */
\r
181 #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
\r
182 #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
\r
183 #define FLASH_SECTOR_2 ((uint32_t)2U) /*!< Sector Number 2 */
\r
184 #define FLASH_SECTOR_3 ((uint32_t)3U) /*!< Sector Number 3 */
\r
185 #define FLASH_SECTOR_4 ((uint32_t)4U) /*!< Sector Number 4 */
\r
186 #define FLASH_SECTOR_5 ((uint32_t)5U) /*!< Sector Number 5 */
\r
187 #define FLASH_SECTOR_6 ((uint32_t)6U) /*!< Sector Number 6 */
\r
188 #define FLASH_SECTOR_7 ((uint32_t)7U) /*!< Sector Number 7 */
\r
189 #endif /* FLASH_SECTOR_TOTAL */
\r
198 /* Exported macro ------------------------------------------------------------*/
\r
199 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
\r
203 * @brief Set the FLASH Latency.
\r
204 * @param __LATENCY__ FLASH Latency
\r
205 * The value of this parameter depend on device used within the same series
\r
208 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
\r
209 MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
\r
212 * @brief Get the FLASH Latency.
\r
213 * @retval FLASH Latency
\r
214 * The value of this parameter depend on device used within the same series
\r
216 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
\r
219 * @brief Enable the FLASH prefetch buffer.
\r
222 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
\r
225 * @brief Disable the FLASH prefetch buffer.
\r
228 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
\r
231 * @brief Enable the FLASH Adaptive Real-Time memory accelerator.
\r
232 * @note The ART accelerator is available only for flash access on ITCM interface.
\r
235 #define __HAL_FLASH_ART_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
\r
238 * @brief Disable the FLASH Adaptive Real-Time memory accelerator.
\r
241 #define __HAL_FLASH_ART_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
\r
244 * @brief Resets the FLASH Adaptive Real-Time memory accelerator.
\r
245 * @note This function must be used only when the Adaptive Real-Time memory accelerator
\r
249 #define __HAL_FLASH_ART_RESET() (FLASH->ACR |= FLASH_ACR_ARTRST)
\r
252 * @brief Enable the specified FLASH interrupt.
\r
253 * @param __INTERRUPT__ FLASH interrupt
\r
254 * This parameter can be any combination of the following values:
\r
255 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
\r
256 * @arg FLASH_IT_ERR: Error Interrupt
\r
259 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
\r
262 * @brief Disable the specified FLASH interrupt.
\r
263 * @param __INTERRUPT__ FLASH interrupt
\r
264 * This parameter can be any combination of the following values:
\r
265 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
\r
266 * @arg FLASH_IT_ERR: Error Interrupt
\r
269 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
\r
272 * @brief Get the specified FLASH flag status.
\r
273 * @param __FLAG__ specifies the FLASH flag to check.
\r
274 * This parameter can be one of the following values:
\r
275 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
\r
276 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
\r
277 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
278 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
279 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
\r
280 * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
\r
281 * @arg FLASH_FLAG_BSY : FLASH Busy flag
\r
282 * @retval The new state of __FLAG__ (SET or RESET).
\r
284 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
\r
287 * @brief Clear the specified FLASH flag.
\r
288 * @param __FLAG__ specifies the FLASH flags to clear.
\r
289 * This parameter can be any combination of the following values:
\r
290 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
\r
291 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
\r
292 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
293 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
294 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
\r
295 * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
\r
298 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
\r
303 /* Include FLASH HAL Extension module */
\r
304 #include "stm32f7xx_hal_flash_ex.h"
\r
306 /* Exported functions --------------------------------------------------------*/
\r
307 /** @addtogroup FLASH_Exported_Functions
\r
310 /** @addtogroup FLASH_Exported_Functions_Group1
\r
313 /* Program operation functions ***********************************************/
\r
314 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
\r
315 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
\r
316 /* FLASH IRQ handler method */
\r
317 void HAL_FLASH_IRQHandler(void);
\r
318 /* Callbacks in non blocking modes */
\r
319 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
\r
320 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
\r
325 /** @addtogroup FLASH_Exported_Functions_Group2
\r
328 /* Peripheral Control functions **********************************************/
\r
329 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
\r
330 HAL_StatusTypeDef HAL_FLASH_Lock(void);
\r
331 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
\r
332 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
\r
333 /* Option bytes control */
\r
334 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
\r
339 /** @addtogroup FLASH_Exported_Functions_Group3
\r
342 /* Peripheral State functions ************************************************/
\r
343 uint32_t HAL_FLASH_GetError(void);
\r
344 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
\r
352 /* Private types -------------------------------------------------------------*/
\r
353 /* Private variables ---------------------------------------------------------*/
\r
354 /** @defgroup FLASH_Private_Variables FLASH Private Variables
\r
361 /* Private constants ---------------------------------------------------------*/
\r
362 /** @defgroup FLASH_Private_Constants FLASH Private Constants
\r
367 * @brief OPTCR register byte 1 (Bits[15:8]) base address
\r
369 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
\r
375 /* Private macros ------------------------------------------------------------*/
\r
376 /** @defgroup FLASH_Private_Macros FLASH Private Macros
\r
380 /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
\r
383 #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
\r
384 ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
\r
385 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
\r
386 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
\r
395 /* Private functions ---------------------------------------------------------*/
\r
396 /** @defgroup FLASH_Private_Functions FLASH Private Functions
\r
416 #endif /* __STM32F7xx_HAL_FLASH_H */
\r
418 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r