2 ******************************************************************************
\r
3 * @file stm32f4xx_hal_flash.h
\r
4 * @author MCD Application Team
\r
6 * @date 18-February-2014
\r
7 * @brief Header file of FLASH HAL module.
\r
8 ******************************************************************************
\r
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
\r
13 * Redistribution and use in source and binary forms, with or without modification,
\r
14 * are permitted provided that the following conditions are met:
\r
15 * 1. Redistributions of source code must retain the above copyright notice,
\r
16 * this list of conditions and the following disclaimer.
\r
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
18 * this list of conditions and the following disclaimer in the documentation
\r
19 * and/or other materials provided with the distribution.
\r
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
21 * may be used to endorse or promote products derived from this software
\r
22 * without specific prior written permission.
\r
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
35 ******************************************************************************
\r
38 /* Define to prevent recursive inclusion -------------------------------------*/
\r
39 #ifndef __STM32F4xx_HAL_FLASH_H
\r
40 #define __STM32F4xx_HAL_FLASH_H
\r
46 /* Includes ------------------------------------------------------------------*/
\r
47 #include "stm32f4xx_hal_def.h"
\r
49 /** @addtogroup STM32F4xx_HAL_Driver
\r
53 /** @addtogroup FLASH
\r
57 /* Exported types ------------------------------------------------------------*/
\r
59 * @brief FLASH Error structure definition
\r
63 FLASH_ERROR_RD = 0x01,
\r
64 FLASH_ERROR_PGS = 0x02,
\r
65 FLASH_ERROR_PGP = 0x04,
\r
66 FLASH_ERROR_PGA = 0x08,
\r
67 FLASH_ERROR_WRP = 0x10,
\r
68 FLASH_ERROR_OPERATION = 0x20
\r
69 }FLASH_ErrorTypeDef;
\r
72 * @brief FLASH Procedure structure definition
\r
76 FLASH_PROC_NONE = 0,
\r
77 FLASH_PROC_SECTERASE,
\r
78 FLASH_PROC_MASSERASE,
\r
80 } FLASH_ProcedureTypeDef;
\r
84 * @brief FLASH handle Structure definition
\r
88 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
\r
90 __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
\r
92 __IO uint8_t VoltageForErase; /*Internal variable to provide voltange range selected by user in IT context*/
\r
94 __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/
\r
96 __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/
\r
98 __IO uint32_t Address; /*Internal variable to save address selected for program*/
\r
100 HAL_LockTypeDef Lock; /* FLASH locking object */
\r
102 __IO FLASH_ErrorTypeDef ErrorCode; /* FLASH error code */
\r
104 }FLASH_ProcessTypeDef;
\r
107 * @brief FLASH Error source
\r
109 /* Exported constants --------------------------------------------------------*/
\r
111 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
\r
117 /** @defgroup FLASH_Type_Program FLASH Type Program
\r
120 #define TYPEPROGRAM_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address */
\r
121 #define TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address */
\r
122 #define TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */
\r
123 #define TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!< Program a double word (64-bit) at a specified address */
\r
125 #define IS_TYPEPROGRAM(VALUE)(((VALUE) == TYPEPROGRAM_BYTE) || \
\r
126 ((VALUE) == TYPEPROGRAM_HALFWORD) || \
\r
127 ((VALUE) == TYPEPROGRAM_WORD) || \
\r
128 ((VALUE) == TYPEPROGRAM_DOUBLEWORD))
\r
134 /** @defgroup FLASH_Flag_definition FLASH Flag definition
\r
135 * @brief Flag definition
\r
138 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
\r
139 #define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */
\r
140 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
\r
141 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
\r
142 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
\r
143 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */
\r
144 #define FLASH_FLAG_RDERR ((uint32_t)0x00000100) /*!< Read Protection error flag (PCROP) */
\r
145 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
\r
151 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
\r
152 * @brief FLASH Interrupt definition
\r
155 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
\r
156 #define FLASH_IT_ERR ((uint32_t)0x02000000) /*!< Error Interrupt source */
\r
162 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
\r
165 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
\r
166 #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
\r
167 #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
\r
168 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
\r
169 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
\r
174 /** @defgroup FLASH_Keys FLASH Keys
\r
177 #define RDP_KEY ((uint16_t)0x00A5)
\r
178 #define FLASH_KEY1 ((uint32_t)0x45670123)
\r
179 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
\r
180 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
\r
181 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
\r
187 * @brief ACR register byte 0 (Bits[7:0]) base address
\r
189 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
\r
191 * @brief OPTCR register byte 0 (Bits[7:0]) base address
\r
193 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
\r
195 * @brief OPTCR register byte 1 (Bits[15:8]) base address
\r
197 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
\r
199 * @brief OPTCR register byte 2 (Bits[23:16]) base address
\r
201 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
\r
203 * @brief OPTCR register byte 3 (Bits[31:24]) base address
\r
205 #define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
\r
211 /* Exported macro ------------------------------------------------------------*/
\r
214 * @brief Set the FLASH Latency.
\r
215 * @param __LATENCY__: FLASH Latency
\r
216 * The value of this parameter depend on device used within the same series
\r
219 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
\r
222 * @brief Enable the FLASH prefetch buffer.
\r
225 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
\r
228 * @brief Disable the FLASH prefetch buffer.
\r
231 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
\r
234 * @brief Enable the FLASH instruction cache.
\r
237 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
\r
240 * @brief Disable the FLASH instruction cache.
\r
243 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
\r
246 * @brief Enable the FLASH data cache.
\r
249 #define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
\r
252 * @brief Disable the FLASH data cache.
\r
255 #define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
\r
258 * @brief Resets the FLASH instruction Cache.
\r
259 * @note This function must be used only when the Instruction Cache is disabled.
\r
262 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_ICRST)
\r
265 * @brief Resets the FLASH data Cache.
\r
266 * @note This function must be used only when the data Cache is disabled.
\r
269 #define __HAL_FLASH_DATA_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_DCRST)
\r
272 * @brief Enable the specified FLASH interrupt.
\r
273 * @param __INTERRUPT__ : FLASH interrupt
\r
274 * This parameter can be any combination of the following values:
\r
275 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
\r
276 * @arg FLASH_IT_ERR: Error Interrupt
\r
279 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
\r
282 * @brief Disable the specified FLASH interrupt.
\r
283 * @param __INTERRUPT__ : FLASH interrupt
\r
284 * This parameter can be any combination of the following values:
\r
285 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
\r
286 * @arg FLASH_IT_ERR: Error Interrupt
\r
289 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
\r
292 * @brief Get the specified FLASH flag status.
\r
293 * @param __FLAG__: specifies the FLASH flag to check.
\r
294 * This parameter can be one of the following values:
\r
295 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
\r
296 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
\r
297 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
298 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
299 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
\r
300 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
\r
301 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
\r
302 * @arg FLASH_FLAG_BSY : FLASH Busy flag
\r
303 * @retval The new state of __FLAG__ (SET or RESET).
\r
305 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
\r
308 * @brief Clear the specified FLASH flag.
\r
309 * @param __FLAG__: specifies the FLASH flags to clear.
\r
310 * This parameter can be any combination of the following values:
\r
311 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
\r
312 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
\r
313 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
314 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
315 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
\r
316 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
\r
317 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
\r
320 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
\r
322 /* Include FLASH HAL Extension module */
\r
323 #include "stm32f4xx_hal_flash_ex.h"
\r
325 /* Exported functions --------------------------------------------------------*/
\r
326 /* Program operation functions ***********************************************/
\r
327 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
\r
328 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
\r
329 /* FLASH IRQ handler method */
\r
330 void HAL_FLASH_IRQHandler(void);
\r
331 /* Callbacks in non blocking modes */
\r
332 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
\r
333 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
\r
335 /* Peripheral Control functions **********************************************/
\r
336 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
\r
337 HAL_StatusTypeDef HAL_FLASH_Lock(void);
\r
338 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
\r
339 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
\r
340 /* Option bytes control */
\r
341 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
\r
343 /* Peripheral State functions ************************************************/
\r
344 FLASH_ErrorTypeDef HAL_FLASH_GetError(void);
\r
346 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
\r
360 #endif /* __STM32F4xx_HAL_FLASH_H */
\r
362 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r