]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_flash.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_flash.h
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_hal_flash.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 19-June-2014
7 * @brief Header file of FLASH HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 *
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.
23 *
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.
34 *
35 ******************************************************************************
36 */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_FLASH_H
40 #define __STM32F4xx_HAL_FLASH_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup FLASH
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /**
59 * @brief FLASH Error structure definition
60 */
61 typedef enum
62 {
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
69 }FLASH_ErrorTypeDef;
70
71 /**
72 * @brief FLASH Procedure structure definition
73 */
74 typedef enum
75 {
76 FLASH_PROC_NONE = 0,
77 FLASH_PROC_SECTERASE,
78 FLASH_PROC_MASSERASE,
79 FLASH_PROC_PROGRAM
80 } FLASH_ProcedureTypeDef;
81
82
83 /**
84 * @brief FLASH handle Structure definition
85 */
86 typedef struct
87 {
88 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
89
90 __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
91
92 __IO uint8_t VoltageForErase; /*Internal variable to provide voltange range selected by user in IT context*/
93
94 __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/
95
96 __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/
97
98 __IO uint32_t Address; /*Internal variable to save address selected for program*/
99
100 HAL_LockTypeDef Lock; /* FLASH locking object */
101
102 __IO FLASH_ErrorTypeDef ErrorCode; /* FLASH error code */
103
104 }FLASH_ProcessTypeDef;
105
106 /**
107 * @brief FLASH Error source
108 */
109 /* Exported constants --------------------------------------------------------*/
110
111 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
112 * @{
113 */
114
115
116
117 /** @defgroup FLASH_Type_Program FLASH Type Program
118 * @{
119 */
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 */
124
125 #define IS_TYPEPROGRAM(VALUE)(((VALUE) == TYPEPROGRAM_BYTE) || \
126 ((VALUE) == TYPEPROGRAM_HALFWORD) || \
127 ((VALUE) == TYPEPROGRAM_WORD) || \
128 ((VALUE) == TYPEPROGRAM_DOUBLEWORD))
129
130 /**
131 * @}
132 */
133
134 /** @defgroup FLASH_Flag_definition FLASH Flag definition
135 * @brief Flag definition
136 * @{
137 */
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 */
146
147 /**
148 * @}
149 */
150
151 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
152 * @brief FLASH Interrupt definition
153 * @{
154 */
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 */
157
158 /**
159 * @}
160 */
161
162 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
163 * @{
164 */
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)
170 /**
171 * @}
172 */
173
174 /** @defgroup FLASH_Keys FLASH Keys
175 * @{
176 */
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)
182 /**
183 * @}
184 */
185
186 /**
187 * @brief ACR register byte 0 (Bits[7:0]) base address
188 */
189 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
190 /**
191 * @brief OPTCR register byte 0 (Bits[7:0]) base address
192 */
193 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
194 /**
195 * @brief OPTCR register byte 1 (Bits[15:8]) base address
196 */
197 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
198 /**
199 * @brief OPTCR register byte 2 (Bits[23:16]) base address
200 */
201 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
202 /**
203 * @brief OPTCR register byte 3 (Bits[31:24]) base address
204 */
205 #define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
206
207 /**
208 * @}
209 */
210
211 /* Exported macro ------------------------------------------------------------*/
212
213 /**
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
217 * @retval none
218 */
219 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
220
221 /**
222 * @brief Enable the FLASH prefetch buffer.
223 * @retval none
224 */
225 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
226
227 /**
228 * @brief Disable the FLASH prefetch buffer.
229 * @retval none
230 */
231 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
232
233 /**
234 * @brief Enable the FLASH instruction cache.
235 * @retval none
236 */
237 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
238
239 /**
240 * @brief Disable the FLASH instruction cache.
241 * @retval none
242 */
243 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
244
245 /**
246 * @brief Enable the FLASH data cache.
247 * @retval none
248 */
249 #define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
250
251 /**
252 * @brief Disable the FLASH data cache.
253 * @retval none
254 */
255 #define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
256
257 /**
258 * @brief Resets the FLASH instruction Cache.
259 * @note This function must be used only when the Instruction Cache is disabled.
260 * @retval None
261 */
262 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_ICRST)
263
264 /**
265 * @brief Resets the FLASH data Cache.
266 * @note This function must be used only when the data Cache is disabled.
267 * @retval None
268 */
269 #define __HAL_FLASH_DATA_CACHE_RESET() (FLASH->ACR |= FLASH_ACR_DCRST)
270
271 /**
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
277 * @retval none
278 */
279 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
280
281 /**
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
287 * @retval none
288 */
289 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
290
291 /**
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).
304 */
305 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
306
307 /**
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)
318 * @retval none
319 */
320 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
321
322 /* Include FLASH HAL Extension module */
323 #include "stm32f4xx_hal_flash_ex.h"
324 #include "stm32f4xx_hal_flash_ramfunc.h"
325
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);
335
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);
343
344 /* Peripheral State functions ************************************************/
345 FLASH_ErrorTypeDef HAL_FLASH_GetError(void);
346
347 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
348
349 /**
350 * @}
351 */
352
353 /**
354 * @}
355 */
356
357 #ifdef __cplusplus
358 }
359 #endif
360
361 #endif /* __STM32F4xx_HAL_FLASH_H */
362
363 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum