2 ******************************************************************************
3 * @file stm32f0xx_hal_flash.h
4 * @author MCD Application Team
6 * @date 11-December-2014
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 __STM32F0xx_HAL_FLASH_H
40 #define __STM32F0xx_HAL_FLASH_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
49 /** @addtogroup STM32F0xx_HAL_Driver
57 /* Exported types ------------------------------------------------------------*/
59 /** @defgroup FLASH_Exported_Types FLASH Exported Types
64 * @brief FLASH Erase structure definition
68 uint32_t TypeErase; /*!< TypeErase: Mass erase or page erase.
69 This parameter can be a value of @ref FLASH_Type_Erase */
71 uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled
72 This parameter must be a value of @ref FLASHEx_Address */
74 uint32_t NbPages; /*!< NbPages: Number of pagess to be erased.
75 This parameter must be a value between 1 and (max number of pages - value of initial page)*/
77 } FLASH_EraseInitTypeDef;
80 * @brief FLASH Options bytes program structure definition
84 uint32_t OptionType; /*!< OptionType: Option byte to be configured.
85 This parameter can be a value of @ref FLASH_OB_Type */
87 uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
88 This parameter can be a value of @ref FLASH_OB_WRP_State */
90 uint32_t WRPPage; /*!< WRPSector: specifies the page(s) to be write protected
91 This parameter can be a value of @ref FLASHEx_OB_Write_Protection */
93 uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level..
94 This parameter can be a value of @ref FLASH_OB_Read_Protection */
96 uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
97 IWDG / STOP / STDBY / BOOT1 / VDDA_ANALOG / SRAM_PARITY
98 This parameter can be a combination of @ref FLASH_OB_Watchdog, @ref FLASH_OB_nRST_STOP,
99 @ref FLASH_OB_nRST_STDBY, @ref FLASH_OB_BOOT1, @ref FLASH_OB_VDDA_Analog_Monitoring and
100 @ref FLASH_OB_RAM_Parity_Check_Enable */
102 uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be prgrammed
103 This parameter can be a value of @ref FLASH_OB_Data_Address */
105 uint8_t DATAData; /*!< DATAData: Data to be stored in the option byte DATA
106 This parameter can have any value */
108 } FLASH_OBProgramInitTypeDef;
111 * @brief FLASH Procedure structure definition
116 FLASH_PROC_PAGEERASE = 1,
117 FLASH_PROC_MASSERASE = 2,
118 FLASH_PROC_PROGRAMHALFWORD = 3,
119 FLASH_PROC_PROGRAMWORD = 4,
120 FLASH_PROC_PROGRAMDOUBLEWORD = 5
121 } FLASH_ProcedureTypeDef;
124 * @brief FLASH handle Structure definition
128 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
130 __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
132 __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
134 __IO uint64_t Data; /*!< Internal variable to save data to be programmed */
136 HAL_LockTypeDef Lock; /*!< FLASH locking object */
138 __IO uint32_t ErrorCode; /*!< FLASH error code
139 This parameter can be a value of @ref FLASH_Error */
141 } FLASH_ProcessTypeDef;
147 /* Exported constants --------------------------------------------------------*/
149 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
153 /** @defgroup FLASH_Error FLASH Error
156 #define FLASH_ERROR_NONE ((uint32_t)0x00000000)
157 #define FLASH_ERROR_PG ((uint32_t)0x00000001)
158 #define FLASH_ERROR_WRP ((uint32_t)0x00000002)
163 /** @defgroup FLASH_Type_Erase FLASH Type Erase
166 #define TYPEERASE_PAGES ((uint32_t)0x00) /*!<Pages erase only*/
167 #define TYPEERASE_MASSERASE ((uint32_t)0x01) /*!<Flash mass erase activation*/
169 #define IS_TYPEERASE(VALUE) (((VALUE) == TYPEERASE_PAGES) || \
170 ((VALUE) == TYPEERASE_MASSERASE))
175 /** @defgroup FLASH_Type_Program FLASH Type Program
178 #define TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!<Program a half-word (16-bit) at a specified address.*/
179 #define TYPEPROGRAM_WORD ((uint32_t)0x02) /*!<Program a word (32-bit) at a specified address.*/
180 #define TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!<Program a double word (64-bit) at a specified address*/
182 #define IS_TYPEPROGRAM(VALUE) (((VALUE) == TYPEPROGRAM_HALFWORD) || \
183 ((VALUE) == TYPEPROGRAM_WORD) || \
184 ((VALUE) == TYPEPROGRAM_DOUBLEWORD))
189 /** @defgroup FLASH_OB_WRP_State FLASH WRP State
192 #define WRPSTATE_DISABLE ((uint32_t)0x00) /*!<Disable the write protection of the desired pages*/
193 #define WRPSTATE_ENABLE ((uint32_t)0x01) /*!<Enable the write protection of the desired pagess*/
195 #define IS_WRPSTATE(VALUE) (((VALUE) == WRPSTATE_DISABLE) || \
196 ((VALUE) == WRPSTATE_ENABLE))
201 /** @defgroup FLASH_OB_Type FLASH Option Bytes Type
204 #define OPTIONBYTE_WRP ((uint32_t)0x01) /*!<WRP option byte configuration*/
205 #define OPTIONBYTE_RDP ((uint32_t)0x02) /*!<RDP option byte configuration*/
206 #define OPTIONBYTE_USER ((uint32_t)0x04) /*!<USER option byte configuration*/
207 #define OPTIONBYTE_DATA ((uint32_t)0x08) /*!<DATA option byte configuration*/
209 #define IS_OPTIONBYTE(VALUE) ((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA))
214 /** @defgroup FLASH_Latency FLASH Latency
217 #define FLASH_LATENCY_0 ((uint32_t)0x00000000) /*!< FLASH Zero Latency cycle */
218 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY /*!< FLASH One Latency cycle */
220 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
221 ((LATENCY) == FLASH_LATENCY_1))
226 /** @defgroup FLASH_OB_Data_Address FLASH OB Data Address
229 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
234 /** @defgroup FLASH_OB_Read_Protection FLASH OB Read Protection
237 #define OB_RDP_LEVEL_0 ((uint8_t)0xAA)
238 #define OB_RDP_LEVEL_1 ((uint8_t)0xBB)
239 #define OB_RDP_LEVEL_2 ((uint8_t)0xCC) /*!< Warning: When enabling read protection level 2
240 it's no more possible to go back to level 1 or 0 */
241 #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
242 ((LEVEL) == OB_RDP_LEVEL_1))/*||\
243 ((LEVEL) == OB_RDP_LEVEL_2))*/
248 /** @defgroup FLASH_OB_Watchdog FLASH OB Watchdog
251 #define OB_WDG_SW ((uint8_t)0x01) /*!< Software WDG selected */
252 #define OB_WDG_HW ((uint8_t)0x00) /*!< Hardware WDG selected */
253 #define IS_OB_WDG_SOURCE(SOURCE) (((SOURCE) == OB_WDG_SW) || ((SOURCE) == OB_WDG_HW))
258 /** @defgroup FLASH_OB_nRST_STOP FLASH OB nRST STOP
261 #define OB_STOP_NO_RST ((uint8_t)0x02) /*!< No reset generated when entering in STOP */
262 #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
263 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
268 /** @defgroup FLASH_OB_nRST_STDBY FLASH OB nRST STDBY
271 #define OB_STDBY_NO_RST ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */
272 #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
273 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
278 /** @defgroup FLASH_OB_BOOT1 FLASH OB BOOT1
281 #define OB_BOOT1_RESET ((uint8_t)0x00) /*!< BOOT1 Reset */
282 #define OB_BOOT1_SET ((uint8_t)0x10) /*!< BOOT1 Set */
283 #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
288 /** @defgroup FLASH_OB_VDDA_Analog_Monitoring FLASH OB VDDA Analog Monitoring
291 #define OB_VDDA_ANALOG_ON ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source ON */
292 #define OB_VDDA_ANALOG_OFF ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */
293 #define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
298 /** @defgroup FLASH_OB_RAM_Parity_Check_Enable FLASH OB RAM Parity Check Enable
301 #define OB_RAM_PARITY_CHECK_SET ((uint8_t)0x00) /*!< RAM parity check enable set */
302 #define OB_RAM_PARITY_CHECK_RESET ((uint8_t)0x40) /*!< RAM parity check enable reset */
303 #define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_RAM_PARITY_CHECK_SET) || ((PARITY) == OB_RAM_PARITY_CHECK_RESET))
308 /** @defgroup FLASH_Flag_definition FLASH Flag definition
311 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
312 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
313 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
314 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
319 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
322 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
323 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
328 /** @defgroup FLASH_Timeout_definition FLASH Timeout definition
329 * @brief FLASH Timeout definition
332 #define HAL_FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */
341 /* Exported macro ------------------------------------------------------------*/
343 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
344 * @brief macros to control FLASH features
348 /** @defgroup FLASH_Latency FLASH Latency
349 * @brief macros to handle FLASH Latency
354 * @brief Set the FLASH Latency.
355 * @param __LATENCY__: FLASH Latency
356 * The value of this parameter depend on device used within the same series
359 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
364 /** @defgroup FLASH_Prefetch FLASH Prefetch
365 * @brief macros to handle FLASH Prefetch buffer
369 * @brief Enable the FLASH prefetch buffer.
372 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
375 * @brief Disable the FLASH prefetch buffer.
378 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
384 /** @defgroup FLASH_Interrupt FLASH Interrupt
385 * @brief macros to handle FLASH interrupts
390 * @brief Enable the specified FLASH interrupt.
391 * @param __INTERRUPT__ : FLASH interrupt
392 * This parameter can be any combination of the following values:
393 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
394 * @arg FLASH_IT_ERR: Error Interrupt
397 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
400 * @brief Disable the specified FLASH interrupt.
401 * @param __INTERRUPT__ : FLASH interrupt
402 * This parameter can be any combination of the following values:
403 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
404 * @arg FLASH_IT_ERR: Error Interrupt
407 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
410 * @brief Get the specified FLASH flag status.
411 * @param __FLAG__: specifies the FLASH flag to check.
412 * This parameter can be one of the following values:
413 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
414 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
415 * @arg FLASH_FLAG_PGERR : FLASH Programming error flag
416 * @arg FLASH_FLAG_BSY : FLASH Busy flag
417 * @retval The new state of __FLAG__ (SET or RESET).
419 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)) == (__FLAG__))
422 * @brief Clear the specified FLASH flag.
423 * @param __FLAG__: specifies the FLASH flags to clear.
424 * This parameter can be any combination of the following values:
425 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
426 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
427 * @arg FLASH_FLAG_PGERR : FLASH Programming error flag
430 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
440 /* Include FLASH HAL Extension module */
441 #include "stm32f0xx_hal_flash_ex.h"
443 /* Exported functions --------------------------------------------------------*/
445 /** @addtogroup FLASH_Exported_Functions
449 /** @addtogroup FLASH_Exported_Functions_Group1
450 * @brief Data transfers functions
454 /* IO operation functions *****************************************************/
455 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
456 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
458 /* FLASH IRQ handler method */
459 void HAL_FLASH_IRQHandler(void);
460 /* Callbacks in non blocking modes */
461 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
462 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
468 /** @addtogroup FLASH_Exported_Functions_Group2
469 * @brief management functions
473 /* FLASH Memory Programming functions *****************************************/
474 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
475 HAL_StatusTypeDef HAL_FLASH_Lock(void);
477 /* Option Bytes Programming functions *****************************************/
478 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
479 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
480 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
486 /** @addtogroup FLASH_Exported_Functions_Group3
489 /* Peripheral State and Error functions ***************************************/
490 uint32_t HAL_FLASH_GetError(void);
512 #endif /* __STM32F0xx_HAL_FLASH_H */
514 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/