提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_flash.h
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief Header file of Flash HAL module.
|
|
6 |
******************************************************************************
|
|
7 |
* @attention
|
|
8 |
*
|
|
9 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
10 |
*
|
|
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.
|
|
21 |
*
|
|
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.
|
|
32 |
*
|
|
33 |
******************************************************************************
|
|
34 |
*/
|
|
35 |
|
|
36 |
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
37 |
#ifndef __STM32F0xx_HAL_FLASH_H
|
|
38 |
#define __STM32F0xx_HAL_FLASH_H
|
|
39 |
|
|
40 |
#ifdef __cplusplus
|
|
41 |
extern "C" {
|
|
42 |
#endif
|
|
43 |
|
|
44 |
/* Includes ------------------------------------------------------------------*/
|
|
45 |
#include "stm32f0xx_hal_def.h"
|
|
46 |
|
|
47 |
/** @addtogroup STM32F0xx_HAL_Driver
|
|
48 |
* @{
|
|
49 |
*/
|
|
50 |
|
|
51 |
/** @addtogroup FLASH
|
|
52 |
* @{
|
|
53 |
*/
|
|
54 |
|
|
55 |
/** @addtogroup FLASH_Private_Constants
|
|
56 |
* @{
|
|
57 |
*/
|
|
58 |
#define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */
|
|
59 |
/**
|
|
60 |
* @}
|
|
61 |
*/
|
|
62 |
|
|
63 |
/** @addtogroup FLASH_Private_Macros
|
|
64 |
* @{
|
|
65 |
*/
|
|
66 |
|
|
67 |
#define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
|
|
68 |
((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
|
|
69 |
((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
|
|
70 |
|
|
71 |
#define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
|
|
72 |
((__LATENCY__) == FLASH_LATENCY_1))
|
|
73 |
|
|
74 |
/**
|
|
75 |
* @}
|
|
76 |
*/
|
|
77 |
|
|
78 |
/* Exported types ------------------------------------------------------------*/
|
|
79 |
/** @defgroup FLASH_Exported_Types FLASH Exported Types
|
|
80 |
* @{
|
|
81 |
*/
|
|
82 |
|
|
83 |
/**
|
|
84 |
* @brief FLASH Procedure structure definition
|
|
85 |
*/
|
|
86 |
typedef enum
|
|
87 |
{
|
|
88 |
FLASH_PROC_NONE = 0U,
|
|
89 |
FLASH_PROC_PAGEERASE = 1U,
|
|
90 |
FLASH_PROC_MASSERASE = 2U,
|
|
91 |
FLASH_PROC_PROGRAMHALFWORD = 3U,
|
|
92 |
FLASH_PROC_PROGRAMWORD = 4U,
|
|
93 |
FLASH_PROC_PROGRAMDOUBLEWORD = 5U
|
|
94 |
} FLASH_ProcedureTypeDef;
|
|
95 |
|
|
96 |
/**
|
|
97 |
* @brief FLASH handle Structure definition
|
|
98 |
*/
|
|
99 |
typedef struct
|
|
100 |
{
|
|
101 |
__IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
|
|
102 |
|
|
103 |
__IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
|
|
104 |
|
|
105 |
__IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
|
|
106 |
|
|
107 |
__IO uint64_t Data; /*!< Internal variable to save data to be programmed */
|
|
108 |
|
|
109 |
HAL_LockTypeDef Lock; /*!< FLASH locking object */
|
|
110 |
|
|
111 |
__IO uint32_t ErrorCode; /*!< FLASH error code
|
|
112 |
This parameter can be a value of @ref FLASH_Error_Codes */
|
|
113 |
} FLASH_ProcessTypeDef;
|
|
114 |
|
|
115 |
/**
|
|
116 |
* @}
|
|
117 |
*/
|
|
118 |
|
|
119 |
/* Exported constants --------------------------------------------------------*/
|
|
120 |
/** @defgroup FLASH_Exported_Constants FLASH Exported Constants
|
|
121 |
* @{
|
|
122 |
*/
|
|
123 |
|
|
124 |
/** @defgroup FLASH_Error_Codes FLASH Error Codes
|
|
125 |
* @{
|
|
126 |
*/
|
|
127 |
|
|
128 |
#define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
|
|
129 |
#define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */
|
|
130 |
#define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
|
|
131 |
|
|
132 |
/**
|
|
133 |
* @}
|
|
134 |
*/
|
|
135 |
|
|
136 |
/** @defgroup FLASH_Type_Program FLASH Type Program
|
|
137 |
* @{
|
|
138 |
*/
|
|
139 |
#define FLASH_TYPEPROGRAM_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/
|
|
140 |
#define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
|
|
141 |
#define FLASH_TYPEPROGRAM_DOUBLEWORD (0x03U) /*!<Program a double word (64-bit) at a specified address*/
|
|
142 |
|
|
143 |
/**
|
|
144 |
* @}
|
|
145 |
*/
|
|
146 |
|
|
147 |
/** @defgroup FLASH_Latency FLASH Latency
|
|
148 |
* @{
|
|
149 |
*/
|
|
150 |
#define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */
|
|
151 |
#define FLASH_LATENCY_1 FLASH_ACR_LATENCY /*!< FLASH One Latency cycle */
|
|
152 |
|
|
153 |
/**
|
|
154 |
* @}
|
|
155 |
*/
|
|
156 |
|
|
157 |
|
|
158 |
/** @defgroup FLASH_Flag_definition FLASH Flag definition
|
|
159 |
* @{
|
|
160 |
*/
|
|
161 |
#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
|
|
162 |
#define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
|
|
163 |
#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
|
|
164 |
#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
|
|
165 |
/**
|
|
166 |
* @}
|
|
167 |
*/
|
|
168 |
|
|
169 |
/** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
|
|
170 |
* @{
|
|
171 |
*/
|
|
172 |
#define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
|
|
173 |
#define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
|
|
174 |
/**
|
|
175 |
* @}
|
|
176 |
*/
|
|
177 |
|
|
178 |
/**
|
|
179 |
* @}
|
|
180 |
*/
|
|
181 |
|
|
182 |
/* Exported macro ------------------------------------------------------------*/
|
|
183 |
|
|
184 |
/** @defgroup FLASH_Exported_Macros FLASH Exported Macros
|
|
185 |
* @brief macros to control FLASH features
|
|
186 |
* @{
|
|
187 |
*/
|
|
188 |
|
|
189 |
|
|
190 |
/** @defgroup FLASH_EM_Latency FLASH Latency
|
|
191 |
* @brief macros to handle FLASH Latency
|
|
192 |
* @{
|
|
193 |
*/
|
|
194 |
|
|
195 |
/**
|
|
196 |
* @brief Set the FLASH Latency.
|
|
197 |
* @param __LATENCY__ FLASH Latency
|
|
198 |
* The value of this parameter depend on device used within the same series
|
|
199 |
* @retval None
|
|
200 |
*/
|
|
201 |
#define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
|
|
202 |
|
|
203 |
|
|
204 |
/**
|
|
205 |
* @brief Get the FLASH Latency.
|
|
206 |
* @retval FLASH Latency
|
|
207 |
* The value of this parameter depend on device used within the same series
|
|
208 |
*/
|
|
209 |
#define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
|
|
210 |
|
|
211 |
/**
|
|
212 |
* @}
|
|
213 |
*/
|
|
214 |
|
|
215 |
/** @defgroup FLASH_Prefetch FLASH Prefetch
|
|
216 |
* @brief macros to handle FLASH Prefetch buffer
|
|
217 |
* @{
|
|
218 |
*/
|
|
219 |
/**
|
|
220 |
* @brief Enable the FLASH prefetch buffer.
|
|
221 |
* @retval None
|
|
222 |
*/
|
|
223 |
#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
|
|
224 |
|
|
225 |
/**
|
|
226 |
* @brief Disable the FLASH prefetch buffer.
|
|
227 |
* @retval None
|
|
228 |
*/
|
|
229 |
#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
|
|
230 |
|
|
231 |
/**
|
|
232 |
* @}
|
|
233 |
*/
|
|
234 |
|
|
235 |
/** @defgroup FLASH_Interrupt FLASH Interrupts
|
|
236 |
* @brief macros to handle FLASH interrupts
|
|
237 |
* @{
|
|
238 |
*/
|
|
239 |
|
|
240 |
/**
|
|
241 |
* @brief Enable the specified FLASH interrupt.
|
|
242 |
* @param __INTERRUPT__ FLASH interrupt
|
|
243 |
* This parameter can be any combination of the following values:
|
|
244 |
* @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
|
|
245 |
* @arg @ref FLASH_IT_ERR Error Interrupt
|
|
246 |
* @retval none
|
|
247 |
*/
|
|
248 |
#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__))
|
|
249 |
|
|
250 |
/**
|
|
251 |
* @brief Disable the specified FLASH interrupt.
|
|
252 |
* @param __INTERRUPT__ FLASH interrupt
|
|
253 |
* This parameter can be any combination of the following values:
|
|
254 |
* @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
|
|
255 |
* @arg @ref FLASH_IT_ERR Error Interrupt
|
|
256 |
* @retval none
|
|
257 |
*/
|
|
258 |
#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__))
|
|
259 |
|
|
260 |
/**
|
|
261 |
* @brief Get the specified FLASH flag status.
|
|
262 |
* @param __FLAG__ specifies the FLASH flag to check.
|
|
263 |
* This parameter can be one of the following values:
|
|
264 |
* @arg @ref FLASH_FLAG_BSY FLASH Busy flag
|
|
265 |
* @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
|
|
266 |
* @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
|
|
267 |
* @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
|
|
268 |
* @retval The new state of __FLAG__ (SET or RESET).
|
|
269 |
*/
|
|
270 |
#define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
|
|
271 |
|
|
272 |
/**
|
|
273 |
* @brief Clear the specified FLASH flag.
|
|
274 |
* @param __FLAG__ specifies the FLASH flags to clear.
|
|
275 |
* This parameter can be any combination of the following values:
|
|
276 |
* @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
|
|
277 |
* @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
|
|
278 |
* @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
|
|
279 |
* @retval none
|
|
280 |
*/
|
|
281 |
#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
|
|
282 |
|
|
283 |
/**
|
|
284 |
* @}
|
|
285 |
*/
|
|
286 |
|
|
287 |
/**
|
|
288 |
* @}
|
|
289 |
*/
|
|
290 |
|
|
291 |
/* Include FLASH HAL Extended module */
|
|
292 |
#include "stm32f0xx_hal_flash_ex.h"
|
|
293 |
|
|
294 |
/* Exported functions --------------------------------------------------------*/
|
|
295 |
/** @addtogroup FLASH_Exported_Functions
|
|
296 |
* @{
|
|
297 |
*/
|
|
298 |
|
|
299 |
/** @addtogroup FLASH_Exported_Functions_Group1
|
|
300 |
* @{
|
|
301 |
*/
|
|
302 |
/* IO operation functions *****************************************************/
|
|
303 |
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
|
|
304 |
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
|
|
305 |
|
|
306 |
/* FLASH IRQ handler function */
|
|
307 |
void HAL_FLASH_IRQHandler(void);
|
|
308 |
/* Callbacks in non blocking modes */
|
|
309 |
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
|
|
310 |
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
|
|
311 |
|
|
312 |
/**
|
|
313 |
* @}
|
|
314 |
*/
|
|
315 |
|
|
316 |
/** @addtogroup FLASH_Exported_Functions_Group2
|
|
317 |
* @{
|
|
318 |
*/
|
|
319 |
/* Peripheral Control functions ***********************************************/
|
|
320 |
HAL_StatusTypeDef HAL_FLASH_Unlock(void);
|
|
321 |
HAL_StatusTypeDef HAL_FLASH_Lock(void);
|
|
322 |
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
|
|
323 |
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
|
|
324 |
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
|
|
325 |
|
|
326 |
/**
|
|
327 |
* @}
|
|
328 |
*/
|
|
329 |
|
|
330 |
/** @addtogroup FLASH_Exported_Functions_Group3
|
|
331 |
* @{
|
|
332 |
*/
|
|
333 |
/* Peripheral State and Error functions ***************************************/
|
|
334 |
uint32_t HAL_FLASH_GetError(void);
|
|
335 |
|
|
336 |
/**
|
|
337 |
* @}
|
|
338 |
*/
|
|
339 |
|
|
340 |
/**
|
|
341 |
* @}
|
|
342 |
*/
|
|
343 |
|
|
344 |
/* Private function -------------------------------------------------*/
|
|
345 |
/** @addtogroup FLASH_Private_Functions
|
|
346 |
* @{
|
|
347 |
*/
|
|
348 |
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
|
|
349 |
|
|
350 |
/**
|
|
351 |
* @}
|
|
352 |
*/
|
|
353 |
|
|
354 |
/**
|
|
355 |
* @}
|
|
356 |
*/
|
|
357 |
|
|
358 |
/**
|
|
359 |
* @}
|
|
360 |
*/
|
|
361 |
|
|
362 |
#ifdef __cplusplus
|
|
363 |
}
|
|
364 |
#endif
|
|
365 |
|
|
366 |
#endif /* __STM32F0xx_HAL_FLASH_H */
|
|
367 |
|
|
368 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
369 |
|