2 ******************************************************************************
3 * @file stm32f4xx_hal_flash.h
4 * @author MCD Application Team
7 * @brief Header file of FLASH HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 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 __STM32F4xx_HAL_FLASH_H
40 #define __STM32F4xx_HAL_FLASH_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
49 /** @addtogroup STM32F4xx_HAL_Driver
57 /* Exported types ------------------------------------------------------------*/
59 * @brief FLASH Error structure definition
63 FLASH_ERROR_RD
= 0x01,
64 FLASH_ERROR_PGS
= 0x02,
65 FLASH_ERROR_PGP
= 0x04,
66 FLASH_ERROR_PGA
= 0x08,
67 FLASH_ERROR_WRP
= 0x10,
68 FLASH_ERROR_OPERATION
= 0x20
72 * @brief FLASH Procedure structure definition
80 } FLASH_ProcedureTypeDef
;
84 * @brief FLASH handle Structure definition
88 __IO FLASH_ProcedureTypeDef ProcedureOnGoing
; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
90 __IO
uint32_t NbSectorsToErase
; /*Internal variable to save the remaining sectors to erase in IT context*/
92 __IO
uint8_t VoltageForErase
; /*Internal variable to provide voltange range selected by user in IT context*/
94 __IO
uint32_t Sector
; /*Internal variable to define the current sector which is erasing*/
96 __IO
uint32_t Bank
; /*Internal variable to save current bank selected during mass erase*/
98 __IO
uint32_t Address
; /*Internal variable to save address selected for program*/
100 HAL_LockTypeDef Lock
; /* FLASH locking object */
102 __IO FLASH_ErrorTypeDef ErrorCode
; /* FLASH error code */
104 }FLASH_ProcessTypeDef
;
107 * @brief FLASH Error source
109 /* Exported constants --------------------------------------------------------*/
111 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
117 /** @defgroup FLASH_Type_Program FLASH Type Program
120 #define TYPEPROGRAM_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address */
121 #define TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address */
122 #define TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */
123 #define TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!< Program a double word (64-bit) at a specified address */
125 #define IS_TYPEPROGRAM(VALUE)(((VALUE) == TYPEPROGRAM_BYTE) || \
126 ((VALUE) == TYPEPROGRAM_HALFWORD) || \
127 ((VALUE) == TYPEPROGRAM_WORD) || \
128 ((VALUE) == TYPEPROGRAM_DOUBLEWORD))
134 /** @defgroup FLASH_Flag_definition FLASH Flag definition
135 * @brief Flag definition
138 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
139 #define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */
140 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
141 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
142 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
143 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */
144 #define FLASH_FLAG_RDERR ((uint32_t)0x00000100) /*!< Read Protection error flag (PCROP) */
145 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
151 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
152 * @brief FLASH Interrupt definition
155 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
156 #define FLASH_IT_ERR ((uint32_t)0x02000000) /*!< Error Interrupt source */
162 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
165 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
166 #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
167 #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
168 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
169 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
174 /** @defgroup FLASH_Keys FLASH Keys
177 #define RDP_KEY ((uint16_t)0x00A5)
178 #define FLASH_KEY1 ((uint32_t)0x45670123)
179 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
180 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
181 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
187 * @brief ACR register byte 0 (Bits[7:0]) base address
189 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
191 * @brief OPTCR register byte 0 (Bits[7:0]) base address
193 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
195 * @brief OPTCR register byte 1 (Bits[15:8]) base address
197 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
199 * @brief OPTCR register byte 2 (Bits[23:16]) base address
201 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
203 * @brief OPTCR register byte 3 (Bits[31:24]) base address
205 #define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
211 /* Exported macro ------------------------------------------------------------*/
214 * @brief Set the FLASH Latency.
215 * @param __LATENCY__: FLASH Latency
216 * The value of this parameter depend on device used within the same series
219 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
222 * @brief Enable the FLASH prefetch buffer.
225 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
228 * @brief Disable the FLASH prefetch buffer.
231 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
234 * @brief Enable the FLASH instruction cache.
237 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
240 * @brief Disable the FLASH instruction cache.
243 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
246 * @brief Enable the FLASH data cache.
249 #define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
252 * @brief Disable the FLASH data cache.
255 #define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
258 * @brief Resets the FLASH instruction Cache.
259 * @note This function must be used only when the Instruction Cache is disabled.
262 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_ICRST)
265 * @brief Resets the FLASH data Cache.
266 * @note This function must be used only when the data Cache is disabled.
269 #define __HAL_FLASH_DATA_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_DCRST)
272 * @brief Enable the specified FLASH interrupt.
273 * @param __INTERRUPT__ : FLASH interrupt
274 * This parameter can be any combination of the following values:
275 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
276 * @arg FLASH_IT_ERR: Error Interrupt
279 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
282 * @brief Disable the specified FLASH interrupt.
283 * @param __INTERRUPT__ : FLASH interrupt
284 * This parameter can be any combination of the following values:
285 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
286 * @arg FLASH_IT_ERR: Error Interrupt
289 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
292 * @brief Get the specified FLASH flag status.
293 * @param __FLAG__: specifies the FLASH flag to check.
294 * This parameter can be one of the following values:
295 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
296 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
297 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
298 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
299 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
300 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
301 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
302 * @arg FLASH_FLAG_BSY : FLASH Busy flag
303 * @retval The new state of __FLAG__ (SET or RESET).
305 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
308 * @brief Clear the specified FLASH flag.
309 * @param __FLAG__: specifies the FLASH flags to clear.
310 * This parameter can be any combination of the following values:
311 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
312 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
313 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
314 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
315 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
316 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
317 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
320 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
322 /* Include FLASH HAL Extension module */
323 #include "stm32f4xx_hal_flash_ex.h"
324 #include "stm32f4xx_hal_flash_ramfunc.h"
326 /* Exported functions --------------------------------------------------------*/
327 /* Program operation functions ***********************************************/
328 HAL_StatusTypeDef
HAL_FLASH_Program(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
329 HAL_StatusTypeDef
HAL_FLASH_Program_IT(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
);
330 /* FLASH IRQ handler method */
331 void HAL_FLASH_IRQHandler(void);
332 /* Callbacks in non blocking modes */
333 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue
);
334 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue
);
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 /* Peripheral State functions ************************************************/
345 FLASH_ErrorTypeDef
HAL_FLASH_GetError(void);
347 HAL_StatusTypeDef
FLASH_WaitForLastOperation(uint32_t Timeout
);
361 #endif /* __STM32F4xx_HAL_FLASH_H */
363 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/