rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
stm32f4xx_hal_flash.h
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32f4xx_hal_flash.h
4 * @author MCD Application Team
5 * @version V1.4.0
6 * @date 14-August-2015
7 * @brief Header file of FLASH HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2015 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/** @defgroup FLASH_Exported_Types FLASH Exported Types
59 * @{
60 */
61
62/**
63 * @brief FLASH Procedure structure definition
64 */
65typedef enum
66{
67 FLASH_PROC_NONE = 0,
68 FLASH_PROC_SECTERASE,
69 FLASH_PROC_MASSERASE,
70 FLASH_PROC_PROGRAM
71} FLASH_ProcedureTypeDef;
72
73/**
74 * @brief FLASH handle Structure definition
75 */
76typedef struct
77{
78 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
79
80 __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
81
82 __IO uint8_t VoltageForErase; /*Internal variable to provide voltage range selected by user in IT context*/
83
84 __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/
85
86 __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/
87
88 __IO uint32_t Address; /*Internal variable to save address selected for program*/
89
90 HAL_LockTypeDef Lock; /* FLASH locking object */
91
92 __IO uint32_t ErrorCode; /* FLASH error code */
93
95
96/**
97 * @}
98 */
99
100/* Exported constants --------------------------------------------------------*/
101/** @defgroup FLASH_Exported_Constants FLASH Exported Constants
102 * @{
103 */
104/** @defgroup FLASH_Error_Code FLASH Error Code
105 * @brief FLASH Error Code
106 * @{
107 */
108#define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
109#define HAL_FLASH_ERROR_RD ((uint32_t)0x00000001) /*!< Read Protection error */
110#define HAL_FLASH_ERROR_PGS ((uint32_t)0x00000002) /*!< Programming Sequence error */
111#define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004) /*!< Programming Parallelism error */
112#define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008) /*!< Programming Alignment error */
113#define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010) /*!< Write protection error */
114#define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020) /*!< Operation Error */
115/**
116 * @}
117 */
118
119/** @defgroup FLASH_Type_Program FLASH Type Program
120 * @{
121 */
122#define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address */
123#define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address */
124#define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */
125#define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!< Program a double word (64-bit) at a specified address */
126/**
127 * @}
128 */
129
130/** @defgroup FLASH_Flag_definition FLASH Flag definition
131 * @brief Flag definition
132 * @{
133 */
134#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
135/* migrate to updated header */
136#ifdef FLASH_SR_OPERR
137#define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */
138#else
139#define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */
140#endif
141#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
142#define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
143#define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
144#define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */
145#define FLASH_FLAG_RDERR ((uint32_t)0x00000100) /*!< Read Protection error flag (PCROP) */
146#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
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/** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
162 * @{
163 */
164#define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
165#define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
166#define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
167#define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
168#define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
169/**
170 * @}
171 */
172
173/** @defgroup FLASH_Keys FLASH Keys
174 * @{
175 */
176#define RDP_KEY ((uint16_t)0x00A5)
177#define FLASH_KEY1 ((uint32_t)0x45670123)
178#define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
179#define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
180#define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
181/**
182 * @}
183 */
184
185/**
186 * @}
187 */
188
189/* Exported macro ------------------------------------------------------------*/
190/** @defgroup FLASH_Exported_Macros FLASH Exported Macros
191 * @{
192 */
193/**
194 * @brief Set the FLASH Latency.
195 * @param __LATENCY__: FLASH Latency
196 * The value of this parameter depend on device used within the same series
197 * @retval none
198 */
199#define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
200
201/**
202 * @brief Get the FLASH Latency.
203 * @retval FLASH Latency
204 * The value of this parameter depend on device used within the same series
205 */
206#define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
207
208/**
209 * @brief Enable the FLASH prefetch buffer.
210 * @retval none
211 */
212#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
213
214/**
215 * @brief Disable the FLASH prefetch buffer.
216 * @retval none
217 */
218#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
219
220/**
221 * @brief Enable the FLASH instruction cache.
222 * @retval none
223 */
224#define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
225
226/**
227 * @brief Disable the FLASH instruction cache.
228 * @retval none
229 */
230#define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
231
232/**
233 * @brief Enable the FLASH data cache.
234 * @retval none
235 */
236#define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
237
238/**
239 * @brief Disable the FLASH data cache.
240 * @retval none
241 */
242#define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
243
244/**
245 * @brief Resets the FLASH instruction Cache.
246 * @note This function must be used only when the Instruction Cache is disabled.
247 * @retval None
248 */
249#define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_ICRST; \
250 FLASH->ACR &= ~FLASH_ACR_ICRST; \
251 }while(0)
252
253/**
254 * @brief Resets the FLASH data Cache.
255 * @note This function must be used only when the data Cache is disabled.
256 * @retval None
257 */
258#define __HAL_FLASH_DATA_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_DCRST; \
259 FLASH->ACR &= ~FLASH_ACR_DCRST; \
260 }while(0)
261/**
262 * @brief Enable the specified FLASH interrupt.
263 * @param __INTERRUPT__ : FLASH interrupt
264 * This parameter can be any combination of the following values:
265 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
266 * @arg FLASH_IT_ERR: Error Interrupt
267 * @retval none
268 */
269#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
270
271/**
272 * @brief Disable 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_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
280
281/**
282 * @brief Get the specified FLASH flag status.
283 * @param __FLAG__: specifies the FLASH flag to check.
284 * This parameter can be one of the following values:
285 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
286 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
287 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
288 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
289 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
290 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
291 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
292 * @arg FLASH_FLAG_BSY : FLASH Busy flag
293 * @retval The new state of __FLAG__ (SET or RESET).
294 */
295#define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
296
297/**
298 * @brief Clear the specified FLASH flag.
299 * @param __FLAG__: specifies the FLASH flags to clear.
300 * This parameter can be any combination of the following values:
301 * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
302 * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
303 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
304 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
305 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
306 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
307 * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP)
308 * @retval none
309 */
310#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
311/**
312 * @}
313 */
314
315/* Include FLASH HAL Extension module */
318
319/* Exported functions --------------------------------------------------------*/
320/** @addtogroup FLASH_Exported_Functions
321 * @{
322 */
323/** @addtogroup FLASH_Exported_Functions_Group1
324 * @{
325 */
326/* Program operation functions ***********************************************/
327HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
328HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
329/* FLASH IRQ handler method */
330void HAL_FLASH_IRQHandler(void);
331/* Callbacks in non blocking modes */
332void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
333void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
334/**
335 * @}
336 */
337
338/** @addtogroup FLASH_Exported_Functions_Group2
339 * @{
340 */
341/* Peripheral Control functions **********************************************/
342HAL_StatusTypeDef HAL_FLASH_Unlock(void);
343HAL_StatusTypeDef HAL_FLASH_Lock(void);
344HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
345HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
346/* Option bytes control */
347HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
348/**
349 * @}
350 */
351
352/** @addtogroup FLASH_Exported_Functions_Group3
353 * @{
354 */
355/* Peripheral State functions ************************************************/
356uint32_t HAL_FLASH_GetError(void);
357HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
358/**
359 * @}
360 */
361
362/**
363 * @}
364 */
365/* Private types -------------------------------------------------------------*/
366/* Private variables ---------------------------------------------------------*/
367/** @defgroup FLASH_Private_Variables FLASH Private Variables
368 * @{
369 */
370
371/**
372 * @}
373 */
374/* Private constants ---------------------------------------------------------*/
375/** @defgroup FLASH_Private_Constants FLASH Private Constants
376 * @{
377 */
378
379/**
380 * @brief ACR register byte 0 (Bits[7:0]) base address
381 */
382#define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
383/**
384 * @brief OPTCR register byte 0 (Bits[7:0]) base address
385 */
386#define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
387/**
388 * @brief OPTCR register byte 1 (Bits[15:8]) base address
389 */
390#define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
391/**
392 * @brief OPTCR register byte 2 (Bits[23:16]) base address
393 */
394#define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
395/**
396 * @brief OPTCR register byte 3 (Bits[31:24]) base address
397 */
398#define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
399
400/**
401 * @}
402 */
403
404/* Private macros ------------------------------------------------------------*/
405/** @defgroup FLASH_Private_Macros FLASH Private Macros
406 * @{
407 */
408
409/** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
410 * @{
411 */
412#define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
413 ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
414 ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
415 ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
416/**
417 * @}
418 */
419
420/**
421 * @}
422 */
423
424/* Private functions ---------------------------------------------------------*/
425/** @defgroup FLASH_Private_Functions FLASH Private Functions
426 * @{
427 */
428
429/**
430 * @}
431 */
432
433/**
434 * @}
435 */
436
437/**
438 * @}
439 */
440
441#ifdef __cplusplus
442}
443#endif
444
445#endif /* __STM32F4xx_HAL_FLASH_H */
446
447/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void HAL_FLASH_IRQHandler(void)
This function handles FLASH interrupt request.
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
FLASH operation error interrupt callback.
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
FLASH end of operation interrupt callback.
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
Program byte, halfword, word or double word at a specified address with interrupt enabled.
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
Program byte, halfword, word or double word at a specified address.
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
Launch the option byte loading.
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
Unlock the FLASH control register access.
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
Lock the FLASH Option Control Registers access.
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
Unlock the FLASH Option Control Registers access.
HAL_StatusTypeDef HAL_FLASH_Lock(void)
Locks the FLASH control register access.
uint32_t HAL_FLASH_GetError(void)
Get the specific FLASH error flag.
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
Wait for a FLASH operation to complete.
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_LockTypeDef
HAL Lock structures definition
Header file of FLASH HAL Extension module.
Header file of FLASH RAMFUNC driver.
FLASH handle Structure definition
__IO FLASH_ProcedureTypeDef ProcedureOnGoing