2 ******************************************************************************
3 * @file stm32f1xx_hal_flash.h
4 * @author MCD Application Team
6 * @date 15-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 __STM32F1xx_HAL_FLASH_H
40 #define __STM32F1xx_HAL_FLASH_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx_hal_def.h"
49 /** @addtogroup STM32F1xx_HAL_Driver
57 /** @addtogroup FLASH_Private_Constants
60 #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */
65 /** @addtogroup FLASH_Private_Macros
69 #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
70 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
71 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
77 /* Exported types ------------------------------------------------------------*/
78 /** @defgroup FLASH_Exported_Types FLASH Exported Types
84 * @brief FLASH Procedure structure definition
89 FLASH_PROC_PAGEERASE = 1,
90 FLASH_PROC_MASSERASE = 2,
91 FLASH_PROC_PROGRAMHALFWORD = 3,
92 FLASH_PROC_PROGRAMWORD = 4,
93 FLASH_PROC_PROGRAMDOUBLEWORD = 5
94 } FLASH_ProcedureTypeDef;
97 * @brief FLASH handle Structure definition
101 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
103 __IO uint32_t DataRemaining; /* Internal variable to save the remaining pages to erase or half-word to program in IT context */
105 __IO uint32_t Address; /* Internal variable to save address selected for program or erase */
107 __IO uint64_t Data; /* Internal variable to save data to be programmed */
109 HAL_LockTypeDef Lock; /* FLASH locking object */
111 __IO uint32_t ErrorCode; /* FLASH error code */
113 } FLASH_ProcessTypeDef;
119 /* Exported constants --------------------------------------------------------*/
120 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
124 /** @defgroup FLASH_Error_Codes FLASH Error Codes
128 #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00)
129 #define HAL_FLASH_ERROR_PROG ((uint32_t)0x01)
130 #define HAL_FLASH_ERROR_WRP ((uint32_t)0x02)
131 #define HAL_FLASH_ERROR_OPTV ((uint32_t)0x04)
138 /** @defgroup FLASH_Type_Program Type Program
141 #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!<Program a half-word (16-bit) at a specified address.*/
142 #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02) /*!<Program a word (32-bit) at a specified address.*/
143 #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!<Program a double word (64-bit) at a specified address*/
153 /* Exported macro ------------------------------------------------------------*/
155 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
156 * @brief macros to control FLASH features
161 * @brief Enable the FLASH half cycle access.
162 * @note halfcycle access can only be used with a low-frequency clock of less than
163 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
166 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA)
169 * @brief Disable the FLASH half cycle access.
170 * @note halfcycle access can only be used with a low-frequency clock of less than
171 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
174 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
180 /* Include FLASH HAL Extended module */
181 #include "stm32f1xx_hal_flash_ex.h"
183 /* Exported functions --------------------------------------------------------*/
184 /** @addtogroup FLASH_Exported_Functions
188 /** @addtogroup FLASH_Exported_Functions_Group1
191 /* IO operation functions *****************************************************/
192 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
193 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
195 /* FLASH IRQ handler method */
196 void HAL_FLASH_IRQHandler(void);
197 /* Callbacks in non blocking modes */
198 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
199 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
205 /** @addtogroup FLASH_Exported_Functions_Group2
208 /* Peripheral Control functions ***********************************************/
209 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
210 HAL_StatusTypeDef HAL_FLASH_Lock(void);
211 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
212 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
213 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
219 /** @addtogroup FLASH_Exported_Functions_Group3
222 /* Peripheral State and Error functions ***************************************/
223 uint32_t HAL_FLASH_GetError(void);
233 /* Private function -------------------------------------------------*/
234 /** @addtogroup FLASH_Private_Functions
237 void FLASH_PageErase(uint32_t PageAddress);
238 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
239 void FLASH_SetErrorCode(void);
240 void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
258 #endif /* __STM32F1xx_HAL_FLASH_H */
260 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/