source: S-port/trunk/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 14.7 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32f4xx_hal_flash.h
4 * @author MCD Application Team
5 * @brief Header file of FLASH HAL module.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
16 *
17 ******************************************************************************
18 */
19
20/* Define to prevent recursive inclusion -------------------------------------*/
21#ifndef __STM32F4xx_HAL_FLASH_H
22#define __STM32F4xx_HAL_FLASH_H
23
24#ifdef __cplusplus
25 extern "C" {
26#endif
27
28/* Includes ------------------------------------------------------------------*/
29#include "stm32f4xx_hal_def.h"
30
31/** @addtogroup STM32F4xx_HAL_Driver
32 * @{
33 */
34
35/** @addtogroup FLASH
36 * @{
37 */
38
39/* Exported types ------------------------------------------------------------*/
40/** @defgroup FLASH_Exported_Types FLASH Exported Types
41 * @{
42 */
43
44/**
45 * @brief FLASH Procedure structure definition
46 */
47typedef enum
48{
49 FLASH_PROC_NONE = 0U,
50 FLASH_PROC_SECTERASE,
51 FLASH_PROC_MASSERASE,
52 FLASH_PROC_PROGRAM
53} FLASH_ProcedureTypeDef;
54
55/**
56 * @brief FLASH handle Structure definition
57 */
58typedef struct
59{
60 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
61
62 __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
63
64 __IO uint8_t VoltageForErase; /*Internal variable to provide voltage range selected by user in IT context*/
65
66 __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/
67
68 __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/
69
70 __IO uint32_t Address; /*Internal variable to save address selected for program*/
71
72 HAL_LockTypeDef Lock; /* FLASH locking object */
73
74 __IO uint32_t ErrorCode; /* FLASH error code */
75
76}FLASH_ProcessTypeDef;
77
78/**
79 * @}
80 */
81
82/* Exported constants --------------------------------------------------------*/
83/** @defgroup FLASH_Exported_Constants FLASH Exported Constants
84 * @{
85 */
86/** @defgroup FLASH_Error_Code FLASH Error Code
87 * @brief FLASH Error Code
88 * @{
89 */
90#define HAL_FLASH_ERROR_NONE 0x00000000U /*!< No error */
91#define HAL_FLASH_ERROR_RD 0x00000001U /*!< Read Protection error */
92#define HAL_FLASH_ERROR_PGS 0x00000002U /*!< Programming Sequence error */
93#define HAL_FLASH_ERROR_PGP 0x00000004U /*!< Programming Parallelism error */
94#define HAL_FLASH_ERROR_PGA 0x00000008U /*!< Programming Alignment error */
95#define HAL_FLASH_ERROR_WRP 0x00000010U /*!< Write protection error */
96#define HAL_FLASH_ERROR_OPERATION 0x00000020U /*!< Operation Error */
97/**
98 * @}
99 */
100
101/** @defgroup FLASH_Type_Program FLASH Type Program
102 * @{
103 */
104#define FLASH_TYPEPROGRAM_BYTE 0x00000000U /*!< Program byte (8-bit) at a specified address */
105#define FLASH_TYPEPROGRAM_HALFWORD 0x00000001U /*!< Program a half-word (16-bit) at a specified address */
106#define FLASH_TYPEPROGRAM_WORD 0x00000002U /*!< Program a word (32-bit) at a specified address */
107#define FLASH_TYPEPROGRAM_DOUBLEWORD 0x00000003U /*!< Program a double word (64-bit) at a specified address */
108/**
109 * @}
110 */
111
112/** @defgroup FLASH_Flag_definition FLASH Flag definition
113 * @brief Flag definition
114 * @{
115 */
116#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
117#define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */
118#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
119#define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
120#define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
121#define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */
122#if defined(FLASH_SR_RDERR)
123#define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< Read Protection error flag (PCROP) */
124#endif /* FLASH_SR_RDERR */
125#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
126/**
127 * @}
128 */
129
130/** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
131 * @brief FLASH Interrupt definition
132 * @{
133 */
134#define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
135#define FLASH_IT_ERR 0x02000000U /*!< Error Interrupt source */
136/**
137 * @}
138 */
139
140/** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
141 * @{
142 */
143#define FLASH_PSIZE_BYTE 0x00000000U
144#define FLASH_PSIZE_HALF_WORD 0x00000100U
145#define FLASH_PSIZE_WORD 0x00000200U
146#define FLASH_PSIZE_DOUBLE_WORD 0x00000300U
147#define CR_PSIZE_MASK 0xFFFFFCFFU
148/**
149 * @}
150 */
151
152/** @defgroup FLASH_Keys FLASH Keys
153 * @{
154 */
155#define RDP_KEY ((uint16_t)0x00A5)
156#define FLASH_KEY1 0x45670123U
157#define FLASH_KEY2 0xCDEF89ABU
158#define FLASH_OPT_KEY1 0x08192A3BU
159#define FLASH_OPT_KEY2 0x4C5D6E7FU
160/**
161 * @}
162 */
163
164/**
165 * @}
166 */
167
168/* Exported macro ------------------------------------------------------------*/
169/** @defgroup FLASH_Exported_Macros FLASH Exported Macros
170 * @{
171 */
172/**
173 * @brief Set the FLASH Latency.
174 * @param __LATENCY__ FLASH Latency
175 * The value of this parameter depend on device used within the same series
176 * @retval none
177 */
178#define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
179
180/**
181 * @brief Get the FLASH Latency.
182 * @retval FLASH Latency
183 * The value of this parameter depend on device used within the same series
184 */
185#define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
186
187/**
188 * @brief Enable the FLASH prefetch buffer.
189 * @retval none
190 */
191#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
192
193/**
194 * @brief Disable the FLASH prefetch buffer.
195 * @retval none
196 */
197#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
198
199/**
200 * @brief Enable the FLASH instruction cache.
201 * @retval none
202 */
203#define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
204
205/**
206 * @brief Disable the FLASH instruction cache.
207 * @retval none
208 */
209#define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
210
211/**
212 * @brief Enable the FLASH data cache.
213 * @retval none
214 */
215#define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
216
217/**
218 * @brief Disable the FLASH data cache.
219 * @retval none
220 */
221#define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
222
223/**
224 * @brief Resets the FLASH instruction Cache.
225 * @note This function must be used only when the Instruction Cache is disabled.
226 * @retval None
227 */
228#define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_ICRST; \
229 FLASH->ACR &= ~FLASH_ACR_ICRST; \
230 }while(0U)
231
232/**
233 * @brief Resets the FLASH data Cache.
234 * @note This function must be used only when the data Cache is disabled.
235 * @retval None
236 */
237#define __HAL_FLASH_DATA_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_DCRST; \
238 FLASH->ACR &= ~FLASH_ACR_DCRST; \
239 }while(0U)
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 FLASH_IT_EOP: End of FLASH Operation Interrupt
245 * @arg FLASH_IT_ERR: Error Interrupt
246 * @retval none
247 */
248#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (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 FLASH_IT_EOP: End of FLASH Operation Interrupt
255 * @arg FLASH_IT_ERR: Error Interrupt
256 * @retval none
257 */
258#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
259
260/**
261 * @brief Get the specified FLASH flag status.
262 * @param __FLAG__ specifies the FLASH flags to check.
263 * This parameter can be any combination of the following values:
264 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
265 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
266 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
267 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
268 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
269 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
270 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*)
271 * @arg FLASH_FLAG_BSY : FLASH Busy flag
272 * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices
273 * @retval The new state of __FLAG__ (SET or RESET).
274 */
275#define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
276
277/**
278 * @brief Clear the specified FLASH flags.
279 * @param __FLAG__ specifies the FLASH flags to clear.
280 * This parameter can be any combination of the following values:
281 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
282 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
283 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
284 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
285 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
286 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
287 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*)
288 * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices
289 * @retval none
290 */
291#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
292/**
293 * @}
294 */
295
296/* Include FLASH HAL Extension module */
297#include "stm32f4xx_hal_flash_ex.h"
298#include "stm32f4xx_hal_flash_ramfunc.h"
299
300/* Exported functions --------------------------------------------------------*/
301/** @addtogroup FLASH_Exported_Functions
302 * @{
303 */
304/** @addtogroup FLASH_Exported_Functions_Group1
305 * @{
306 */
307/* Program operation functions ***********************************************/
308HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
309HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
310/* FLASH IRQ handler method */
311void HAL_FLASH_IRQHandler(void);
312/* Callbacks in non blocking modes */
313void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
314void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
315/**
316 * @}
317 */
318
319/** @addtogroup FLASH_Exported_Functions_Group2
320 * @{
321 */
322/* Peripheral Control functions **********************************************/
323HAL_StatusTypeDef HAL_FLASH_Unlock(void);
324HAL_StatusTypeDef HAL_FLASH_Lock(void);
325HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
326HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
327/* Option bytes control */
328HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
329/**
330 * @}
331 */
332
333/** @addtogroup FLASH_Exported_Functions_Group3
334 * @{
335 */
336/* Peripheral State functions ************************************************/
337uint32_t HAL_FLASH_GetError(void);
338HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
339/**
340 * @}
341 */
342
343/**
344 * @}
345 */
346/* Private types -------------------------------------------------------------*/
347/* Private variables ---------------------------------------------------------*/
348/** @defgroup FLASH_Private_Variables FLASH Private Variables
349 * @{
350 */
351
352/**
353 * @}
354 */
355/* Private constants ---------------------------------------------------------*/
356/** @defgroup FLASH_Private_Constants FLASH Private Constants
357 * @{
358 */
359
360/**
361 * @brief ACR register byte 0 (Bits[7:0]) base address
362 */
363#define ACR_BYTE0_ADDRESS 0x40023C00U
364/**
365 * @brief OPTCR register byte 0 (Bits[7:0]) base address
366 */
367#define OPTCR_BYTE0_ADDRESS 0x40023C14U
368/**
369 * @brief OPTCR register byte 1 (Bits[15:8]) base address
370 */
371#define OPTCR_BYTE1_ADDRESS 0x40023C15U
372/**
373 * @brief OPTCR register byte 2 (Bits[23:16]) base address
374 */
375#define OPTCR_BYTE2_ADDRESS 0x40023C16U
376/**
377 * @brief OPTCR register byte 3 (Bits[31:24]) base address
378 */
379#define OPTCR_BYTE3_ADDRESS 0x40023C17U
380
381/**
382 * @}
383 */
384
385/* Private macros ------------------------------------------------------------*/
386/** @defgroup FLASH_Private_Macros FLASH Private Macros
387 * @{
388 */
389
390/** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
391 * @{
392 */
393#define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
394 ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
395 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
396 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
397/**
398 * @}
399 */
400
401/**
402 * @}
403 */
404
405/* Private functions ---------------------------------------------------------*/
406/** @defgroup FLASH_Private_Functions FLASH Private Functions
407 * @{
408 */
409
410/**
411 * @}
412 */
413
414/**
415 * @}
416 */
417
418/**
419 * @}
420 */
421
422#ifdef __cplusplus
423}
424#endif
425
426#endif /* __STM32F4xx_HAL_FLASH_H */
427
428/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.