Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F1xx_HAL_Driver / Inc / stm32f1xx_hal_flash.h
blob3ad72508374afdadcb2e3c042f8320964d421825
1 /**
2 ******************************************************************************
3 * @file stm32f1xx_hal_flash.h
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 12-May-2017
7 * @brief Header file of Flash HAL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; 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
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx_hal_def.h"
49 /** @addtogroup STM32F1xx_HAL_Driver
50 * @{
53 /** @addtogroup FLASH
54 * @{
57 /** @addtogroup FLASH_Private_Constants
58 * @{
60 #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */
61 /**
62 * @}
65 /** @addtogroup FLASH_Private_Macros
66 * @{
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))
78 #else
79 #define IS_FLASH_LATENCY(__LATENCY__) ((__LATENCY__) == FLASH_LATENCY_0)
80 #endif /* FLASH_ACR_LATENCY */
81 /**
82 * @}
83 */
85 /* Exported types ------------------------------------------------------------*/
86 /** @defgroup FLASH_Exported_Types FLASH Exported Types
87 * @{
88 */
90 /**
91 * @brief FLASH Procedure structure definition
93 typedef enum
95 FLASH_PROC_NONE = 0U,
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;
103 /**
104 * @brief FLASH handle Structure definition
106 typedef struct
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;
123 * @}
126 /* Exported constants --------------------------------------------------------*/
127 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
128 * @{
131 /** @defgroup FLASH_Error_Codes FLASH Error Codes
132 * @{
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 */
141 * @}
144 /** @defgroup FLASH_Type_Program FLASH Type Program
145 * @{
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*/
152 * @}
155 #if defined(FLASH_ACR_LATENCY)
156 /** @defgroup FLASH_Latency FLASH Latency
157 * @{
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 */
164 * @}
167 #else
168 /** @defgroup FLASH_Latency FLASH Latency
169 * @{
171 #define FLASH_LATENCY_0 0x00000000U /*!< FLASH Zero Latency cycle */
174 * @}
177 #endif /* FLASH_ACR_LATENCY */
179 * @}
182 /* Exported macro ------------------------------------------------------------*/
184 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
185 * @brief macros to control FLASH features
186 * @{
189 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
190 * @brief macros to handle FLASH half cycle
191 * @{
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.
198 * @retval None
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.
206 * @retval None
208 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
211 * @}
214 #if defined(FLASH_ACR_LATENCY)
215 /** @defgroup FLASH_EM_Latency FLASH Latency
216 * @brief macros to handle FLASH Latency
217 * @{
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
224 * @retval None
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))
237 * @}
240 #endif /* FLASH_ACR_LATENCY */
241 /** @defgroup FLASH_Prefetch FLASH Prefetch
242 * @brief macros to handle FLASH Prefetch buffer
243 * @{
246 * @brief Enable the FLASH prefetch buffer.
247 * @retval None
249 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
252 * @brief Disable the FLASH prefetch buffer.
253 * @retval None
255 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
258 * @}
262 * @}
265 /* Include FLASH HAL Extended module */
266 #include "stm32f1xx_hal_flash_ex.h"
268 /* Exported functions --------------------------------------------------------*/
269 /** @addtogroup FLASH_Exported_Functions
270 * @{
273 /** @addtogroup FLASH_Exported_Functions_Group1
274 * @{
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);
287 * @}
290 /** @addtogroup FLASH_Exported_Functions_Group2
291 * @{
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);
301 * @}
304 /** @addtogroup FLASH_Exported_Functions_Group3
305 * @{
307 /* Peripheral State and Error functions ***************************************/
308 uint32_t HAL_FLASH_GetError(void);
311 * @}
315 * @}
318 /* Private function -------------------------------------------------*/
319 /** @addtogroup FLASH_Private_Functions
320 * @{
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 */
328 * @}
332 * @}
336 * @}
339 #ifdef __cplusplus
341 #endif
343 #endif /* __STM32F1xx_HAL_FLASH_H */
345 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/