Updated and Validated
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_flash.c
blob9cb569e55d9a8f688063809fdbef905a896c8a72
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_flash.c
4 * @author MCD Application Team
5 * @brief FLASH HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the internal FLASH memory:
8 * + Program operations functions
9 * + Memory Control functions
10 * + Peripheral Errors functions
12 @verbatim
13 ==============================================================================
14 ##### FLASH peripheral features #####
15 ==============================================================================
17 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
18 to the Flash memory. It implements the erase and program Flash memory operations
19 and the read and write protection mechanisms.
21 [..] The Flash memory interface accelerates code execution with a system of instruction
22 prefetch and cache lines.
24 [..] The FLASH main features are:
25 (+) Flash memory read operations
26 (+) Flash memory program/erase operations
27 (+) Read / write protections
28 (+) Prefetch on I-Code
29 (+) 64 cache lines of 128 bits on I-Code
30 (+) 8 cache lines of 128 bits on D-Code
32 ##### How to use this driver #####
33 ==============================================================================
34 [..]
35 This driver provides functions and macros to configure and program the FLASH
36 memory of all STM32F7xx devices.
38 (#) FLASH Memory IO Programming functions:
39 (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
40 HAL_FLASH_Lock() functions
41 (++) Program functions: byte, half word, word and double word
42 (++) There Two modes of programming :
43 (+++) Polling mode using HAL_FLASH_Program() function
44 (+++) Interrupt mode using HAL_FLASH_Program_IT() function
46 (#) Interrupts and flags management functions :
47 (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
48 (++) Wait for last FLASH operation according to its status
49 (++) Get error flag status by calling HAL_SetErrorCode()
50 [..]
51 In addition to these functions, this driver includes a set of macros allowing
52 to handle the following operations:
53 (+) Set the latency
54 (+) Enable/Disable the prefetch buffer
55 (+) Enable/Disable the Instruction cache and the Data cache
56 (+) Reset the Instruction cache and the Data cache
57 (+) Enable/Disable the FLASH interrupts
58 (+) Monitor the FLASH flags status
59 [..]
60 (@) For any Flash memory program operation (erase or program), the CPU clock frequency
61 (HCLK) must be at least 1MHz.
62 (@) The contents of the Flash memory are not guaranteed if a device reset occurs during
63 a Flash memory operation.
64 (@) Any attempt to read the Flash memory while it is being written or erased, causes the
65 bus to stall. Read operations are processed correctly once the program operation has
66 completed. This means that code or data fetches cannot be performed while a write/erase
67 operation is ongoing.
69 @endverbatim
70 ******************************************************************************
71 * @attention
73 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
74 * All rights reserved.</center></h2>
76 * This software component is licensed by ST under BSD 3-Clause license,
77 * the "License"; You may not use this file except in compliance with the
78 * License. You may obtain a copy of the License at:
79 * opensource.org/licenses/BSD-3-Clause
81 ******************************************************************************
82 */
84 /* Includes ------------------------------------------------------------------*/
85 #include "stm32f7xx_hal.h"
87 /** @addtogroup STM32F7xx_HAL_Driver
88 * @{
91 /** @defgroup FLASH FLASH
92 * @brief FLASH HAL module driver
93 * @{
96 #ifdef HAL_FLASH_MODULE_ENABLED
98 /* Private typedef -----------------------------------------------------------*/
99 /* Private define ------------------------------------------------------------*/
100 /** @addtogroup FLASH_Private_Constants
101 * @{
103 #define SECTOR_MASK ((uint32_t)0xFFFFFF07U)
104 #define FLASH_TIMEOUT_VALUE ((uint32_t)50000U)/* 50 s */
106 * @}
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /** @addtogroup FLASH_Private_Variables
111 * @{
113 /* Variable used for Erase sectors under interruption */
114 FLASH_ProcessTypeDef pFlash;
116 * @}
119 /* Private function prototypes -----------------------------------------------*/
120 /** @addtogroup FLASH_Private_Functions
121 * @{
123 /* Program operations */
124 static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data);
125 static void FLASH_Program_Word(uint32_t Address, uint32_t Data);
126 static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
127 static void FLASH_Program_Byte(uint32_t Address, uint8_t Data);
128 static void FLASH_SetErrorCode(void);
130 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
132 * @}
135 /* Exported functions --------------------------------------------------------*/
136 /** @defgroup FLASH_Exported_Functions FLASH Exported Functions
137 * @{
140 /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
141 * @brief Programming operation functions
143 @verbatim
144 ===============================================================================
145 ##### Programming operation functions #####
146 ===============================================================================
147 [..]
148 This subsection provides a set of functions allowing to manage the FLASH
149 program operations.
151 @endverbatim
152 * @{
156 * @brief Program byte, halfword, word or double word at a specified address
157 * @param TypeProgram Indicate the way to program at a specified address.
158 * This parameter can be a value of @ref FLASH_Type_Program
159 * @param Address specifies the address to be programmed.
160 * @param Data specifies the data to be programmed
162 * @retval HAL_StatusTypeDef HAL Status
164 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
166 HAL_StatusTypeDef status = HAL_ERROR;
168 /* Process Locked */
169 __HAL_LOCK(&pFlash);
171 /* Check the parameters */
172 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
174 /* Wait for last operation to be completed */
175 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
177 if(status == HAL_OK)
179 switch(TypeProgram)
181 case FLASH_TYPEPROGRAM_BYTE :
183 /*Program byte (8-bit) at a specified address.*/
184 FLASH_Program_Byte(Address, (uint8_t) Data);
185 break;
188 case FLASH_TYPEPROGRAM_HALFWORD :
190 /*Program halfword (16-bit) at a specified address.*/
191 FLASH_Program_HalfWord(Address, (uint16_t) Data);
192 break;
195 case FLASH_TYPEPROGRAM_WORD :
197 /*Program word (32-bit) at a specified address.*/
198 FLASH_Program_Word(Address, (uint32_t) Data);
199 break;
202 case FLASH_TYPEPROGRAM_DOUBLEWORD :
204 /*Program double word (64-bit) at a specified address.*/
205 FLASH_Program_DoubleWord(Address, Data);
206 break;
208 default :
209 break;
211 /* Wait for last operation to be completed */
212 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
214 /* If the program operation is completed, disable the PG Bit */
215 FLASH->CR &= (~FLASH_CR_PG);
218 /* Process Unlocked */
219 __HAL_UNLOCK(&pFlash);
221 return status;
225 * @brief Program byte, halfword, word or double word at a specified address with interrupt enabled.
226 * @param TypeProgram Indicate the way to program at a specified address.
227 * This parameter can be a value of @ref FLASH_Type_Program
228 * @param Address specifies the address to be programmed.
229 * @param Data specifies the data to be programmed
231 * @retval HAL Status
233 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
235 HAL_StatusTypeDef status = HAL_OK;
237 /* Process Locked */
238 __HAL_LOCK(&pFlash);
240 /* Check the parameters */
241 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
243 /* Enable End of FLASH Operation interrupt */
244 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
246 /* Enable Error source interrupt */
247 __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR);
249 /* Clear pending flags (if any) */
250 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\
251 FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_ERSERR);
253 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM;
254 pFlash.Address = Address;
256 switch(TypeProgram)
258 case FLASH_TYPEPROGRAM_BYTE :
260 /*Program byte (8-bit) at a specified address.*/
261 FLASH_Program_Byte(Address, (uint8_t) Data);
262 break;
265 case FLASH_TYPEPROGRAM_HALFWORD :
267 /*Program halfword (16-bit) at a specified address.*/
268 FLASH_Program_HalfWord(Address, (uint16_t) Data);
269 break;
272 case FLASH_TYPEPROGRAM_WORD :
274 /*Program word (32-bit) at a specified address.*/
275 FLASH_Program_Word(Address, (uint32_t) Data);
276 break;
279 case FLASH_TYPEPROGRAM_DOUBLEWORD :
281 /*Program double word (64-bit) at a specified address.*/
282 FLASH_Program_DoubleWord(Address, Data);
283 break;
285 default :
286 break;
288 return status;
292 * @brief This function handles FLASH interrupt request.
293 * @retval None
295 void HAL_FLASH_IRQHandler(void)
297 uint32_t temp = 0;
299 /* If the program operation is completed, disable the PG Bit */
300 FLASH->CR &= (~FLASH_CR_PG);
302 /* If the erase operation is completed, disable the SER Bit */
303 FLASH->CR &= (~FLASH_CR_SER);
304 FLASH->CR &= SECTOR_MASK;
306 /* if the erase operation is completed, disable the MER Bit */
307 FLASH->CR &= (~FLASH_MER_BIT);
309 /* Check FLASH End of Operation flag */
310 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != RESET)
312 /* Clear FLASH End of Operation pending bit */
313 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
315 switch (pFlash.ProcedureOnGoing)
317 case FLASH_PROC_SECTERASE :
319 /* Nb of sector to erased can be decreased */
320 pFlash.NbSectorsToErase--;
322 /* Check if there are still sectors to erase */
323 if(pFlash.NbSectorsToErase != 0)
325 temp = pFlash.Sector;
326 /* Indicate user which sector has been erased */
327 HAL_FLASH_EndOfOperationCallback(temp);
329 /* Increment sector number */
330 temp = ++pFlash.Sector;
331 FLASH_Erase_Sector(temp, pFlash.VoltageForErase);
333 else
335 /* No more sectors to Erase, user callback can be called.*/
336 /* Reset Sector and stop Erase sectors procedure */
337 pFlash.Sector = temp = 0xFFFFFFFFU;
338 /* FLASH EOP interrupt user callback */
339 HAL_FLASH_EndOfOperationCallback(temp);
340 /* Sector Erase procedure is completed */
341 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
343 break;
346 case FLASH_PROC_MASSERASE :
348 /* MassErase ended. Return the selected bank : in this product we don't have Banks */
349 /* FLASH EOP interrupt user callback */
350 HAL_FLASH_EndOfOperationCallback(0);
351 /* MAss Erase procedure is completed */
352 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
353 break;
356 case FLASH_PROC_PROGRAM :
358 /*Program ended. Return the selected address*/
359 /* FLASH EOP interrupt user callback */
360 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
361 /* Programming procedure is completed */
362 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
363 break;
365 default :
366 break;
370 /* Check FLASH operation error flags */
371 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ALL_ERRORS) != RESET)
373 switch (pFlash.ProcedureOnGoing)
375 case FLASH_PROC_SECTERASE :
377 /* return the faulty sector */
378 temp = pFlash.Sector;
379 pFlash.Sector = 0xFFFFFFFFU;
380 break;
382 case FLASH_PROC_MASSERASE :
384 /* No return in case of Mass Erase */
385 temp = 0;
386 break;
388 case FLASH_PROC_PROGRAM :
390 /*return the faulty address*/
391 temp = pFlash.Address;
392 break;
394 default :
395 break;
397 /*Save the Error code*/
398 FLASH_SetErrorCode();
400 /* FLASH error interrupt user callback */
401 HAL_FLASH_OperationErrorCallback(temp);
403 /*Stop the procedure ongoing */
404 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
407 if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
409 /* Disable End of FLASH Operation interrupt */
410 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP);
412 /* Disable Error source interrupt */
413 __HAL_FLASH_DISABLE_IT(FLASH_IT_ERR);
415 /* Process Unlocked */
416 __HAL_UNLOCK(&pFlash);
422 * @brief FLASH end of operation interrupt callback
423 * @param ReturnValue The value saved in this parameter depends on the ongoing procedure
424 * - Sectors Erase: Sector which has been erased (if 0xFFFFFFFF, it means that
425 * all the selected sectors have been erased)
426 * - Program : Address which was selected for data program
427 * - Mass Erase : No return value expected
428 * @retval None
430 __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
432 /* Prevent unused argument(s) compilation warning */
433 UNUSED(ReturnValue);
434 /* NOTE : This function Should not be modified, when the callback is needed,
435 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
440 * @brief FLASH operation error interrupt callback
441 * @param ReturnValue The value saved in this parameter depends on the ongoing procedure
442 * - Sectors Erase: Sector which has been erased (if 0xFFFFFFFF, it means that
443 * all the selected sectors have been erased)
444 * - Program : Address which was selected for data program
445 * - Mass Erase : No return value expected
446 * @retval None
448 __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
450 /* Prevent unused argument(s) compilation warning */
451 UNUSED(ReturnValue);
452 /* NOTE : This function Should not be modified, when the callback is needed,
453 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
458 * @}
461 /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
462 * @brief management functions
464 @verbatim
465 ===============================================================================
466 ##### Peripheral Control functions #####
467 ===============================================================================
468 [..]
469 This subsection provides a set of functions allowing to control the FLASH
470 memory operations.
472 @endverbatim
473 * @{
477 * @brief Unlock the FLASH control register access
478 * @retval HAL Status
480 HAL_StatusTypeDef HAL_FLASH_Unlock(void)
482 HAL_StatusTypeDef status = HAL_OK;
484 if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
486 /* Authorize the FLASH Registers access */
487 WRITE_REG(FLASH->KEYR, FLASH_KEY1);
488 WRITE_REG(FLASH->KEYR, FLASH_KEY2);
490 /* Verify Flash is unlocked */
491 if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
493 status = HAL_ERROR;
497 return status;
501 * @brief Locks the FLASH control register access
502 * @retval HAL Status
504 HAL_StatusTypeDef HAL_FLASH_Lock(void)
506 /* Set the LOCK Bit to lock the FLASH Registers access */
507 FLASH->CR |= FLASH_CR_LOCK;
509 return HAL_OK;
513 * @brief Unlock the FLASH Option Control Registers access.
514 * @retval HAL Status
516 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
518 if((FLASH->OPTCR & FLASH_OPTCR_OPTLOCK) != RESET)
520 /* Authorizes the Option Byte register programming */
521 FLASH->OPTKEYR = FLASH_OPT_KEY1;
522 FLASH->OPTKEYR = FLASH_OPT_KEY2;
524 else
526 return HAL_ERROR;
529 return HAL_OK;
533 * @brief Lock the FLASH Option Control Registers access.
534 * @retval HAL Status
536 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
538 /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
539 FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK;
541 return HAL_OK;
545 * @brief Launch the option byte loading.
546 * @retval HAL Status
548 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
550 /* Set the OPTSTRT bit in OPTCR register */
551 FLASH->OPTCR |= FLASH_OPTCR_OPTSTRT;
553 /* Wait for last operation to be completed */
554 return(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE));
558 * @}
561 /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
562 * @brief Peripheral Errors functions
564 @verbatim
565 ===============================================================================
566 ##### Peripheral Errors functions #####
567 ===============================================================================
568 [..]
569 This subsection permits to get in run-time Errors of the FLASH peripheral.
571 @endverbatim
572 * @{
576 * @brief Get the specific FLASH error flag.
577 * @retval FLASH_ErrorCode: The returned value can be:
578 * @arg FLASH_ERROR_ERS: FLASH Erasing Sequence error flag
579 * @arg FLASH_ERROR_PGP: FLASH Programming Parallelism error flag
580 * @arg FLASH_ERROR_PGA: FLASH Programming Alignment error flag
581 * @arg FLASH_ERROR_WRP: FLASH Write protected error flag
582 * @arg FLASH_ERROR_OPERATION: FLASH operation Error flag
584 uint32_t HAL_FLASH_GetError(void)
586 return pFlash.ErrorCode;
590 * @}
594 * @brief Wait for a FLASH operation to complete.
595 * @param Timeout maximum flash operationtimeout
596 * @retval HAL Status
598 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
600 uint32_t tickstart = 0;
602 /* Clear Error Code */
603 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
605 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
606 Even if the FLASH operation fails, the BUSY flag will be reset and an error
607 flag will be set */
608 /* Get tick */
609 tickstart = HAL_GetTick();
611 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET)
613 if(Timeout != HAL_MAX_DELAY)
615 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
617 return HAL_TIMEOUT;
622 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ALL_ERRORS) != RESET)
624 /*Save the error code*/
625 FLASH_SetErrorCode();
626 return HAL_ERROR;
629 /* Check FLASH End of Operation flag */
630 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != RESET)
632 /* Clear FLASH End of Operation pending bit */
633 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
636 /* If there is an error flag set */
637 return HAL_OK;
642 * @brief Program a double word (64-bit) at a specified address.
643 * @note This function must be used when the device voltage range is from
644 * 2.7V to 3.6V and an External Vpp is present.
646 * @note If an erase and a program operations are requested simultaneously,
647 * the erase operation is performed before the program one.
649 * @param Address specifies the address to be programmed.
650 * @param Data specifies the data to be programmed.
651 * @retval None
653 static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
655 /* Check the parameters */
656 assert_param(IS_FLASH_ADDRESS(Address));
658 /* If the previous operation is completed, proceed to program the new data */
659 FLASH->CR &= CR_PSIZE_MASK;
660 FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD;
661 FLASH->CR |= FLASH_CR_PG;
663 /* Program the double-word */
664 *(__IO uint32_t*)Address = (uint32_t)Data;
665 *(__IO uint32_t*)(Address+4) = (uint32_t)(Data >> 32);
667 /* Data synchronous Barrier (DSB) Just after the write operation
668 This will force the CPU to respect the sequence of instruction (no optimization).*/
669 __DSB();
674 * @brief Program word (32-bit) at a specified address.
675 * @note This function must be used when the device voltage range is from
676 * 2.7V to 3.6V.
678 * @note If an erase and a program operations are requested simultaneously,
679 * the erase operation is performed before the program one.
681 * @param Address specifies the address to be programmed.
682 * @param Data specifies the data to be programmed.
683 * @retval None
685 static void FLASH_Program_Word(uint32_t Address, uint32_t Data)
687 /* Check the parameters */
688 assert_param(IS_FLASH_ADDRESS(Address));
690 /* If the previous operation is completed, proceed to program the new data */
691 FLASH->CR &= CR_PSIZE_MASK;
692 FLASH->CR |= FLASH_PSIZE_WORD;
693 FLASH->CR |= FLASH_CR_PG;
695 *(__IO uint32_t*)Address = Data;
697 /* Data synchronous Barrier (DSB) Just after the write operation
698 This will force the CPU to respect the sequence of instruction (no optimization).*/
699 __DSB();
703 * @brief Program a half-word (16-bit) at a specified address.
704 * @note This function must be used when the device voltage range is from
705 * 2.7V to 3.6V.
707 * @note If an erase and a program operations are requested simultaneously,
708 * the erase operation is performed before the program one.
710 * @param Address specifies the address to be programmed.
711 * @param Data specifies the data to be programmed.
712 * @retval None
714 static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
716 /* Check the parameters */
717 assert_param(IS_FLASH_ADDRESS(Address));
719 /* If the previous operation is completed, proceed to program the new data */
720 FLASH->CR &= CR_PSIZE_MASK;
721 FLASH->CR |= FLASH_PSIZE_HALF_WORD;
722 FLASH->CR |= FLASH_CR_PG;
724 *(__IO uint16_t*)Address = Data;
726 /* Data synchronous Barrier (DSB) Just after the write operation
727 This will force the CPU to respect the sequence of instruction (no optimization).*/
728 __DSB();
733 * @brief Program byte (8-bit) at a specified address.
734 * @note This function must be used when the device voltage range is from
735 * 2.7V to 3.6V.
737 * @note If an erase and a program operations are requested simultaneously,
738 * the erase operation is performed before the program one.
740 * @param Address specifies the address to be programmed.
741 * @param Data specifies the data to be programmed.
742 * @retval None
744 static void FLASH_Program_Byte(uint32_t Address, uint8_t Data)
746 /* Check the parameters */
747 assert_param(IS_FLASH_ADDRESS(Address));
749 /* If the previous operation is completed, proceed to program the new data */
750 FLASH->CR &= CR_PSIZE_MASK;
751 FLASH->CR |= FLASH_PSIZE_BYTE;
752 FLASH->CR |= FLASH_CR_PG;
754 *(__IO uint8_t*)Address = Data;
756 /* Data synchronous Barrier (DSB) Just after the write operation
757 This will force the CPU to respect the sequence of instruction (no optimization).*/
758 __DSB();
762 * @brief Set the specific FLASH error flag.
763 * @retval None
765 static void FLASH_SetErrorCode(void)
767 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR) != RESET)
769 pFlash.ErrorCode |= HAL_FLASH_ERROR_OPERATION;
772 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) != RESET)
774 pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
777 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR) != RESET)
779 pFlash.ErrorCode |= HAL_FLASH_ERROR_PGA;
782 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGPERR) != RESET)
784 pFlash.ErrorCode |= HAL_FLASH_ERROR_PGP;
787 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ERSERR) != RESET)
789 pFlash.ErrorCode |= HAL_FLASH_ERROR_ERS;
792 #if defined (FLASH_OPTCR2_PCROP)
793 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR) != RESET)
795 pFlash.ErrorCode |= HAL_FLASH_ERROR_RD;
797 #endif /* FLASH_OPTCR2_PCROP */
799 /* Clear error programming flags */
800 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
804 * @}
807 #endif /* HAL_FLASH_MODULE_ENABLED */
810 * @}
814 * @}
817 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/