Prusa MINI Firmware overview
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  * @brief Header file of FLASH HAL module.
6  ******************************************************************************
7  * @attention
8  *
9  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. Neither the name of STMicroelectronics nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  ******************************************************************************
34  */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F4xx_HAL_FLASH_H
38 #define __STM32F4xx_HAL_FLASH_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f4xx_hal_def.h"
46 
47 /** @addtogroup STM32F4xx_HAL_Driver
48  * @{
49  */
50 
51 /** @addtogroup FLASH
52  * @{
53  */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup FLASH_Exported_Types FLASH Exported Types
57  * @{
58  */
59 
60 /**
61  * @brief FLASH Procedure structure definition
62  */
63 typedef enum
64 {
70 
71 /**
72  * @brief FLASH handle Structure definition
73  */
74 typedef struct
75 {
76  __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
77 
78  __IO uint32_t NbSectorsToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
79 
80  __IO uint8_t VoltageForErase; /*Internal variable to provide voltage range selected by user in IT context*/
81 
82  __IO uint32_t Sector; /*Internal variable to define the current sector which is erasing*/
83 
84  __IO uint32_t Bank; /*Internal variable to save current bank selected during mass erase*/
85 
86  __IO uint32_t Address; /*Internal variable to save address selected for program*/
87 
88  HAL_LockTypeDef Lock; /* FLASH locking object */
89 
90  __IO uint32_t ErrorCode; /* FLASH error code */
91 
93 
94 /**
95  * @}
96  */
97 
98 /* Exported constants --------------------------------------------------------*/
99 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
100  * @{
101  */
102 /** @defgroup FLASH_Error_Code FLASH Error Code
103  * @brief FLASH Error Code
104  * @{
105  */
106 #define HAL_FLASH_ERROR_NONE 0x00000000U /*!< No error */
107 #define HAL_FLASH_ERROR_RD 0x00000001U /*!< Read Protection error */
108 #define HAL_FLASH_ERROR_PGS 0x00000002U /*!< Programming Sequence error */
109 #define HAL_FLASH_ERROR_PGP 0x00000004U /*!< Programming Parallelism error */
110 #define HAL_FLASH_ERROR_PGA 0x00000008U /*!< Programming Alignment error */
111 #define HAL_FLASH_ERROR_WRP 0x00000010U /*!< Write protection error */
112 #define HAL_FLASH_ERROR_OPERATION 0x00000020U /*!< Operation Error */
113 /**
114  * @}
115  */
116 
117 /** @defgroup FLASH_Type_Program FLASH Type Program
118  * @{
119  */
120 #define FLASH_TYPEPROGRAM_BYTE 0x00000000U /*!< Program byte (8-bit) at a specified address */
121 #define FLASH_TYPEPROGRAM_HALFWORD 0x00000001U /*!< Program a half-word (16-bit) at a specified address */
122 #define FLASH_TYPEPROGRAM_WORD 0x00000002U /*!< Program a word (32-bit) at a specified address */
123 #define FLASH_TYPEPROGRAM_DOUBLEWORD 0x00000003U /*!< Program a double word (64-bit) at a specified address */
124 /**
125  * @}
126  */
127 
128 /** @defgroup FLASH_Flag_definition FLASH Flag definition
129  * @brief Flag definition
130  * @{
131  */
132 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
133 #define FLASH_FLAG_OPERR FLASH_SR_SOP /*!< FLASH operation Error flag */
134 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
135 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
136 #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
137 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming Sequence error flag */
138 #if defined(FLASH_SR_RDERR)
139 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< Read Protection error flag (PCROP) */
140 #endif /* FLASH_SR_RDERR */
141 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
142 /**
143  * @}
144  */
145 
146 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
147  * @brief FLASH Interrupt definition
148  * @{
149  */
150 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
151 #define FLASH_IT_ERR 0x02000000U /*!< Error Interrupt source */
152 /**
153  * @}
154  */
155 
156 /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
157  * @{
158  */
159 #define FLASH_PSIZE_BYTE 0x00000000U
160 #define FLASH_PSIZE_HALF_WORD 0x00000100U
161 #define FLASH_PSIZE_WORD 0x00000200U
162 #define FLASH_PSIZE_DOUBLE_WORD 0x00000300U
163 #define CR_PSIZE_MASK 0xFFFFFCFFU
164 /**
165  * @}
166  */
167 
168 /** @defgroup FLASH_Keys FLASH Keys
169  * @{
170  */
171 #define RDP_KEY ((uint16_t)0x00A5)
172 #define FLASH_KEY1 0x45670123U
173 #define FLASH_KEY2 0xCDEF89ABU
174 #define FLASH_OPT_KEY1 0x08192A3BU
175 #define FLASH_OPT_KEY2 0x4C5D6E7FU
176 /**
177  * @}
178  */
179 
180 /**
181  * @}
182  */
183 
184 /* Exported macro ------------------------------------------------------------*/
185 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
186  * @{
187  */
188 /**
189  * @brief Set the FLASH Latency.
190  * @param __LATENCY__ FLASH Latency
191  * The value of this parameter depend on device used within the same series
192  * @retval none
193  */
194 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (*(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)(__LATENCY__))
195 
196 /**
197  * @brief Get the FLASH Latency.
198  * @retval FLASH Latency
199  * The value of this parameter depend on device used within the same series
200  */
201 #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
202 
203 /**
204  * @brief Enable the FLASH prefetch buffer.
205  * @retval none
206  */
207 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
208 
209 /**
210  * @brief Disable the FLASH prefetch buffer.
211  * @retval none
212  */
213 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
214 
215 /**
216  * @brief Enable the FLASH instruction cache.
217  * @retval none
218  */
219 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_ICEN)
220 
221 /**
222  * @brief Disable the FLASH instruction cache.
223  * @retval none
224  */
225 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_ICEN))
226 
227 /**
228  * @brief Enable the FLASH data cache.
229  * @retval none
230  */
231 #define __HAL_FLASH_DATA_CACHE_ENABLE() (FLASH->ACR |= FLASH_ACR_DCEN)
232 
233 /**
234  * @brief Disable the FLASH data cache.
235  * @retval none
236  */
237 #define __HAL_FLASH_DATA_CACHE_DISABLE() (FLASH->ACR &= (~FLASH_ACR_DCEN))
238 
239 /**
240  * @brief Resets the FLASH instruction Cache.
241  * @note This function must be used only when the Instruction Cache is disabled.
242  * @retval None
243  */
244 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_ICRST; \
245  FLASH->ACR &= ~FLASH_ACR_ICRST; \
246  }while(0U)
247 
248 /**
249  * @brief Resets the FLASH data Cache.
250  * @note This function must be used only when the data Cache is disabled.
251  * @retval None
252  */
253 #define __HAL_FLASH_DATA_CACHE_RESET() do {FLASH->ACR |= FLASH_ACR_DCRST; \
254  FLASH->ACR &= ~FLASH_ACR_DCRST; \
255  }while(0U)
256 /**
257  * @brief Enable the specified FLASH interrupt.
258  * @param __INTERRUPT__ FLASH interrupt
259  * This parameter can be any combination of the following values:
260  * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
261  * @arg FLASH_IT_ERR: Error Interrupt
262  * @retval none
263  */
264 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
265 
266 /**
267  * @brief Disable the specified FLASH interrupt.
268  * @param __INTERRUPT__ FLASH interrupt
269  * This parameter can be any combination of the following values:
270  * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
271  * @arg FLASH_IT_ERR: Error Interrupt
272  * @retval none
273  */
274 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
275 
276 /**
277  * @brief Get the specified FLASH flag status.
278  * @param __FLAG__ specifies the FLASH flags to check.
279  * This parameter can be any combination of the following values:
280  * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
281  * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
282  * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
283  * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
284  * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
285  * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
286  * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*)
287  * @arg FLASH_FLAG_BSY : FLASH Busy flag
288  * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices
289  * @retval The new state of __FLAG__ (SET or RESET).
290  */
291 #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
292 
293 /**
294  * @brief Clear the specified FLASH flags.
295  * @param __FLAG__ specifies the FLASH flags to clear.
296  * This parameter can be any combination of the following values:
297  * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
298  * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
299  * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
300  * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
301  * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
302  * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
303  * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (*)
304  * (*) FLASH_FLAG_RDERR is not available for STM32F405xx/407xx/415xx/417xx devices
305  * @retval none
306  */
307 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
308 /**
309  * @}
310  */
311 
312 /* Include FLASH HAL Extension module */
313 #include "stm32f4xx_hal_flash_ex.h"
315 
316 /* Exported functions --------------------------------------------------------*/
317 /** @addtogroup FLASH_Exported_Functions
318  * @{
319  */
320 /** @addtogroup FLASH_Exported_Functions_Group1
321  * @{
322  */
323 /* Program operation functions ***********************************************/
324 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
325 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
326 /* FLASH IRQ handler method */
327 void HAL_FLASH_IRQHandler(void);
328 /* Callbacks in non blocking modes */
329 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
330 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
331 /**
332  * @}
333  */
334 
335 /** @addtogroup FLASH_Exported_Functions_Group2
336  * @{
337  */
338 /* Peripheral Control functions **********************************************/
343 /* Option bytes control */
345 /**
346  * @}
347  */
348 
349 /** @addtogroup FLASH_Exported_Functions_Group3
350  * @{
351  */
352 /* Peripheral State functions ************************************************/
353 uint32_t HAL_FLASH_GetError(void);
355 /**
356  * @}
357  */
358 
359 /**
360  * @}
361  */
362 /* Private types -------------------------------------------------------------*/
363 /* Private variables ---------------------------------------------------------*/
364 /** @defgroup FLASH_Private_Variables FLASH Private Variables
365  * @{
366  */
367 
368 /**
369  * @}
370  */
371 /* Private constants ---------------------------------------------------------*/
372 /** @defgroup FLASH_Private_Constants FLASH Private Constants
373  * @{
374  */
375 
376 /**
377  * @brief ACR register byte 0 (Bits[7:0]) base address
378  */
379 #define ACR_BYTE0_ADDRESS 0x40023C00U
380 /**
381  * @brief OPTCR register byte 0 (Bits[7:0]) base address
382  */
383 #define OPTCR_BYTE0_ADDRESS 0x40023C14U
384 /**
385  * @brief OPTCR register byte 1 (Bits[15:8]) base address
386  */
387 #define OPTCR_BYTE1_ADDRESS 0x40023C15U
388 /**
389  * @brief OPTCR register byte 2 (Bits[23:16]) base address
390  */
391 #define OPTCR_BYTE2_ADDRESS 0x40023C16U
392 /**
393  * @brief OPTCR register byte 3 (Bits[31:24]) base address
394  */
395 #define OPTCR_BYTE3_ADDRESS 0x40023C17U
396 
397 /**
398  * @}
399  */
400 
401 /* Private macros ------------------------------------------------------------*/
402 /** @defgroup FLASH_Private_Macros FLASH Private Macros
403  * @{
404  */
405 
406 /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
407  * @{
408  */
409 #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
410  ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
411  ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
412  ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
413 /**
414  * @}
415  */
416 
417 /**
418  * @}
419  */
420 
421 /* Private functions ---------------------------------------------------------*/
422 /** @defgroup FLASH_Private_Functions FLASH Private Functions
423  * @{
424  */
425 
426 /**
427  * @}
428  */
429 
430 /**
431  * @}
432  */
433 
434 /**
435  * @}
436  */
437 
438 #ifdef __cplusplus
439 }
440 #endif
441 
442 #endif /* __STM32F4xx_HAL_FLASH_H */
443 
444 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
FLASH_PROC_MASSERASE
Definition: stm32f4xx_hal_flash.h:67
stm32f4xx_hal_def.h
This file contains HAL common defines, enumeration, macros and structures definitions.
stm32f4xx_hal_flash_ex.h
Header file of FLASH HAL Extension module.
FLASH_ProcessTypeDef::ProcedureOnGoing
__IO FLASH_ProcedureTypeDef ProcedureOnGoing
Definition: stm32f4xx_hal_flash.h:76
HAL_FLASH_GetError
uint32_t HAL_FLASH_GetError(void)
stm32f4xx_hal_flash_ramfunc.h
Header file of FLASH RAMFUNC driver.
HAL_FLASH_EndOfOperationCallback
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
FLASH_ProcessTypeDef::ErrorCode
__IO uint32_t ErrorCode
Definition: stm32f4xx_hal_flash.h:90
HAL_FLASH_Unlock
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
FLASH_ProcessTypeDef::Bank
__IO uint32_t Bank
Definition: stm32f4xx_hal_flash.h:84
FLASH_PROC_PROGRAM
Definition: stm32f4xx_hal_flash.h:68
HAL_FLASH_OB_Lock
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
FLASH_WaitForLastOperation
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
FLASH_ProcessTypeDef::Lock
HAL_LockTypeDef Lock
Definition: stm32f4xx_hal_flash.h:88
HAL_FLASH_OperationErrorCallback
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
FLASH_ProcedureTypeDef
FLASH_ProcedureTypeDef
FLASH Procedure structure definition.
Definition: stm32f4xx_hal_flash.h:63
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32f4xx_hal_def.h:55
FLASH_ProcessTypeDef::Address
__IO uint32_t Address
Definition: stm32f4xx_hal_flash.h:86
HAL_FLASH_Lock
HAL_StatusTypeDef HAL_FLASH_Lock(void)
FLASH_ProcessTypeDef::VoltageForErase
__IO uint8_t VoltageForErase
Definition: stm32f4xx_hal_flash.h:80
FLASH_ProcessTypeDef::NbSectorsToErase
__IO uint32_t NbSectorsToErase
Definition: stm32f4xx_hal_flash.h:78
HAL_FLASH_IRQHandler
void HAL_FLASH_IRQHandler(void)
HAL_FLASH_Program
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
FLASH_PROC_SECTERASE
Definition: stm32f4xx_hal_flash.h:66
uint8_t
const uint8_t[]
Definition: 404_html.c:3
HAL_FLASH_OB_Unlock
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
HAL_FLASH_Program_IT
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
FLASH_ProcessTypeDef
FLASH handle Structure definition.
Definition: stm32f4xx_hal_flash.h:74
HAL_FLASH_OB_Launch
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
HAL_LockTypeDef
HAL_LockTypeDef
HAL Lock structures definition.
Definition: stm32f4xx_hal_def.h:66
FLASH_ProcessTypeDef::Sector
__IO uint32_t Sector
Definition: stm32f4xx_hal_flash.h:82
FLASH_PROC_NONE
Definition: stm32f4xx_hal_flash.h:65