before merging master
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Inc / stm32f7xx_hal_flash.h
blobe28a9e7a06c0e4ced28b53d4ce62c316765e88b1
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_flash.h
4 * @author MCD Application Team
5 * @version V1.2.2
6 * @date 14-April-2017
7 * @brief Header file of FLASH HAL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 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 ******************************************************************************
36 */
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F7xx_HAL_FLASH_H
40 #define __STM32F7xx_HAL_FLASH_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
49 /** @addtogroup STM32F7xx_HAL_Driver
50 * @{
53 /** @addtogroup FLASH
54 * @{
55 */
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup FLASH_Exported_Types FLASH Exported Types
59 * @{
62 /**
63 * @brief FLASH Procedure structure definition
65 typedef enum
67 FLASH_PROC_NONE = 0U,
68 FLASH_PROC_SECTERASE,
69 FLASH_PROC_MASSERASE,
70 FLASH_PROC_PROGRAM
71 } FLASH_ProcedureTypeDef;
74 /**
75 * @brief FLASH handle Structure definition
77 typedef struct
79 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
81 __IO uint32_t NbSectorsToErase; /* Internal variable to save the remaining sectors to erase in IT context */
83 __IO uint8_t VoltageForErase; /* Internal variable to provide voltage range selected by user in IT context */
85 __IO uint32_t Sector; /* Internal variable to define the current sector which is erasing */
87 __IO uint32_t Address; /* Internal variable to save address selected for program */
89 HAL_LockTypeDef Lock; /* FLASH locking object */
91 __IO uint32_t ErrorCode; /* FLASH error code */
93 }FLASH_ProcessTypeDef;
95 /**
96 * @}
99 /* Exported constants --------------------------------------------------------*/
100 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
101 * @{
104 /** @defgroup FLASH_Error_Code FLASH Error Code
105 * @brief FLASH Error Code
106 * @{
108 #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
109 #define HAL_FLASH_ERROR_ERS ((uint32_t)0x00000002U) /*!< Programming Sequence error */
110 #define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004U) /*!< Programming Parallelism error */
111 #define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008U) /*!< Programming Alignment error */
112 #define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010U) /*!< Write protection error */
113 #define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020U) /*!< Operation Error */
114 #define HAL_FLASH_ERROR_RD ((uint32_t)0x00000040U) /*!< Read Protection Error */
116 * @}
119 /** @defgroup FLASH_Type_Program FLASH Type Program
120 * @{
122 #define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00U) /*!< Program byte (8-bit) at a specified address */
123 #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01U) /*!< Program a half-word (16-bit) at a specified address */
124 #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02U) /*!< Program a word (32-bit) at a specified address */
125 #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03U) /*!< Program a double word (64-bit) at a specified address */
127 * @}
130 /** @defgroup FLASH_Flag_definition FLASH Flag definition
131 * @brief Flag definition
132 * @{
134 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
135 #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */
136 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
137 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
138 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
139 #define FLASH_FLAG_ERSERR FLASH_SR_ERSERR /*!< FLASH Erasing Sequence error flag */
140 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
142 #if defined (FLASH_OPTCR2_PCROP)
143 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH Read protection error flag */
144 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
145 FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR | FLASH_FLAG_RDERR)
146 #else
147 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
148 FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR)
149 #endif /* FLASH_OPTCR2_PCROP */
151 * @}
154 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
155 * @brief FLASH Interrupt definition
156 * @{
158 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
159 #define FLASH_IT_ERR ((uint32_t)0x02000000U) /*!< Error Interrupt source */
161 * @}
164 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
165 * @{
167 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000U)
168 #define FLASH_PSIZE_HALF_WORD ((uint32_t)FLASH_CR_PSIZE_0)
169 #define FLASH_PSIZE_WORD ((uint32_t)FLASH_CR_PSIZE_1)
170 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)FLASH_CR_PSIZE)
171 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFFU)
173 * @}
176 /** @defgroup FLASH_Keys FLASH Keys
177 * @{
179 #define FLASH_KEY1 ((uint32_t)0x45670123U)
180 #define FLASH_KEY2 ((uint32_t)0xCDEF89ABU)
181 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3BU)
182 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7FU)
184 * @}
187 /** @defgroup FLASH_Sectors FLASH Sectors
188 * @{
190 #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
191 #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
192 #define FLASH_SECTOR_2 ((uint32_t)2U) /*!< Sector Number 2 */
193 #define FLASH_SECTOR_3 ((uint32_t)3U) /*!< Sector Number 3 */
194 #define FLASH_SECTOR_4 ((uint32_t)4U) /*!< Sector Number 4 */
195 #define FLASH_SECTOR_5 ((uint32_t)5U) /*!< Sector Number 5 */
196 #define FLASH_SECTOR_6 ((uint32_t)6U) /*!< Sector Number 6 */
197 #define FLASH_SECTOR_7 ((uint32_t)7U) /*!< Sector Number 7 */
199 * @}
203 * @}
206 /* Exported macro ------------------------------------------------------------*/
207 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
208 * @{
211 * @brief Set the FLASH Latency.
212 * @param __LATENCY__: FLASH Latency
213 * The value of this parameter depend on device used within the same series
214 * @retval none
216 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
217 MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
220 * @brief Get the FLASH Latency.
221 * @retval FLASH Latency
222 * The value of this parameter depend on device used within the same series
224 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
227 * @brief Enable the FLASH prefetch buffer.
228 * @retval none
230 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
233 * @brief Disable the FLASH prefetch buffer.
234 * @retval none
236 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
239 * @brief Enable the FLASH Adaptive Real-Time memory accelerator.
240 * @note The ART accelerator is available only for flash access on ITCM interface.
241 * @retval none
243 #define __HAL_FLASH_ART_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
246 * @brief Disable the FLASH Adaptive Real-Time memory accelerator.
247 * @retval none
249 #define __HAL_FLASH_ART_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
252 * @brief Resets the FLASH Adaptive Real-Time memory accelerator.
253 * @note This function must be used only when the Adaptive Real-Time memory accelerator
254 * is disabled.
255 * @retval None
257 #define __HAL_FLASH_ART_RESET() (FLASH->ACR |= FLASH_ACR_ARTRST)
260 * @brief Enable the specified FLASH interrupt.
261 * @param __INTERRUPT__ : FLASH interrupt
262 * This parameter can be any combination of the following values:
263 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
264 * @arg FLASH_IT_ERR: Error Interrupt
265 * @retval none
267 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
270 * @brief Disable the specified FLASH interrupt.
271 * @param __INTERRUPT__ : FLASH interrupt
272 * This parameter can be any combination of the following values:
273 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
274 * @arg FLASH_IT_ERR: Error Interrupt
275 * @retval none
277 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
280 * @brief Get the specified FLASH flag status.
281 * @param __FLAG__: specifies the FLASH flag to check.
282 * This parameter can be one of the following values:
283 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
284 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
285 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
286 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
287 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
288 * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
289 * @arg FLASH_FLAG_BSY : FLASH Busy flag
290 * @retval The new state of __FLAG__ (SET or RESET).
292 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
295 * @brief Clear the specified FLASH flag.
296 * @param __FLAG__: specifies the FLASH flags to clear.
297 * This parameter can be any combination of the following values:
298 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
299 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
300 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
301 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
302 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
303 * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
304 * @retval none
306 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
308 * @}
311 /* Include FLASH HAL Extension module */
312 #include "stm32f7xx_hal_flash_ex.h"
314 /* Exported functions --------------------------------------------------------*/
315 /** @addtogroup FLASH_Exported_Functions
316 * @{
318 /** @addtogroup FLASH_Exported_Functions_Group1
319 * @{
321 /* Program operation functions ***********************************************/
322 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
323 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
324 /* FLASH IRQ handler method */
325 void HAL_FLASH_IRQHandler(void);
326 /* Callbacks in non blocking modes */
327 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
328 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
330 * @}
333 /** @addtogroup FLASH_Exported_Functions_Group2
334 * @{
336 /* Peripheral Control functions **********************************************/
337 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
338 HAL_StatusTypeDef HAL_FLASH_Lock(void);
339 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
340 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
341 /* Option bytes control */
342 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
344 * @}
347 /** @addtogroup FLASH_Exported_Functions_Group3
348 * @{
350 /* Peripheral State functions ************************************************/
351 uint32_t HAL_FLASH_GetError(void);
352 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
354 * @}
358 * @}
360 /* Private types -------------------------------------------------------------*/
361 /* Private variables ---------------------------------------------------------*/
362 /** @defgroup FLASH_Private_Variables FLASH Private Variables
363 * @{
367 * @}
369 /* Private constants ---------------------------------------------------------*/
370 /** @defgroup FLASH_Private_Constants FLASH Private Constants
371 * @{
374 /**
375 * @brief OPTCR register byte 1 (Bits[15:8]) base address
377 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
380 * @}
383 /* Private macros ------------------------------------------------------------*/
384 /** @defgroup FLASH_Private_Macros FLASH Private Macros
385 * @{
388 /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
389 * @{
391 #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
392 ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
393 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
394 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
396 * @}
400 * @}
403 /* Private functions ---------------------------------------------------------*/
404 /** @defgroup FLASH_Private_Functions FLASH Private Functions
405 * @{
409 * @}
413 * @}
417 * @}
420 #ifdef __cplusplus
422 #endif
424 #endif /* __STM32F7xx_HAL_FLASH_H */
426 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/