2 ******************************************************************************
3 * @file stm32f4xx_hal_flash.c
4 * @author MCD Application Team
7 * @brief FLASH HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the internal FLASH memory:
10 * + Program operations functions
11 * + Memory Control functions
12 * + Peripheral Errors functions
15 ==============================================================================
16 ##### FLASH peripheral features #####
17 ==============================================================================
19 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
20 to the Flash memory. It implements the erase and program Flash memory operations
21 and the read and write protection mechanisms.
23 [..] The Flash memory interface accelerates code execution with a system of instruction
24 prefetch and cache lines.
26 [..] The FLASH main features are:
27 (+) Flash memory read operations
28 (+) Flash memory program/erase operations
29 (+) Read / write protections
30 (+) Prefetch on I-Code
31 (+) 64 cache lines of 128 bits on I-Code
32 (+) 8 cache lines of 128 bits on D-Code
35 ##### How to use this driver #####
36 ==============================================================================
38 This driver provides functions and macros to configure and program the FLASH
39 memory of all STM32F4xx devices.
41 (#) FLASH Memory IO Programming functions:
42 (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
43 HAL_FLASH_Lock() functions
44 (++) Program functions: byte, half word, word and double word
45 (++) There Two modes of programming :
46 (+++) Polling mode using HAL_FLASH_Program() function
47 (+++) Interrupt mode using HAL_FLASH_Program_IT() function
49 (#) Interrupts and flags management functions :
50 (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
51 (++) Wait for last FLASH operation according to its status
52 (++) Get error flag status by calling HAL_SetErrorCode()
55 In addition to these functions, this driver includes a set of macros allowing
56 to handle the following operations:
58 (+) Enable/Disable the prefetch buffer
59 (+) Enable/Disable the Instruction cache and the Data cache
60 (+) Reset the Instruction cache and the Data cache
61 (+) Enable/Disable the FLASH interrupts
62 (+) Monitor the FLASH flags status
65 ******************************************************************************
68 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
70 * Redistribution and use in source and binary forms, with or without modification,
71 * are permitted provided that the following conditions are met:
72 * 1. Redistributions of source code must retain the above copyright notice,
73 * this list of conditions and the following disclaimer.
74 * 2. Redistributions in binary form must reproduce the above copyright notice,
75 * this list of conditions and the following disclaimer in the documentation
76 * and/or other materials provided with the distribution.
77 * 3. Neither the name of STMicroelectronics nor the names of its contributors
78 * may be used to endorse or promote products derived from this software
79 * without specific prior written permission.
81 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
82 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
84 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
87 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
88 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
90 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
92 ******************************************************************************
95 /* Includes ------------------------------------------------------------------*/
96 #include "stm32f4xx_hal.h"
98 /** @addtogroup STM32F4xx_HAL_Driver
102 /** @defgroup FLASH FLASH
103 * @brief FLASH HAL module driver
107 #ifdef HAL_FLASH_MODULE_ENABLED
109 /* Private typedef -----------------------------------------------------------*/
110 /* Private define ------------------------------------------------------------*/
111 /** @addtogroup FLASH_Private_Constants
114 #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */
118 /* Private macro -------------------------------------------------------------*/
119 /* Private variables ---------------------------------------------------------*/
120 /** @addtogroup FLASH_Private_Variables
123 /* Variable used for Erase sectors under interruption */
124 FLASH_ProcessTypeDef pFlash
;
129 /* Private function prototypes -----------------------------------------------*/
130 /** @addtogroup FLASH_Private_Functions
133 /* Program operations */
134 static void FLASH_Program_DoubleWord(uint32_t Address
, uint64_t Data
);
135 static void FLASH_Program_Word(uint32_t Address
, uint32_t Data
);
136 static void FLASH_Program_HalfWord(uint32_t Address
, uint16_t Data
);
137 static void FLASH_Program_Byte(uint32_t Address
, uint8_t Data
);
138 static void FLASH_SetErrorCode(void);
140 HAL_StatusTypeDef
FLASH_WaitForLastOperation(uint32_t Timeout
);
145 /* Exported functions --------------------------------------------------------*/
146 /** @defgroup FLASH_Exported_Functions FLASH Exported Functions
150 /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
151 * @brief Programming operation functions
154 ===============================================================================
155 ##### Programming operation functions #####
156 ===============================================================================
158 This subsection provides a set of functions allowing to manage the FLASH
166 * @brief Program byte, halfword, word or double word at a specified address
167 * @param TypeProgram: Indicate the way to program at a specified address.
168 * This parameter can be a value of @ref FLASH_Type_Program
169 * @param Address: specifies the address to be programmed.
170 * @param Data: specifies the data to be programmed
172 * @retval HAL_StatusTypeDef HAL Status
174 HAL_StatusTypeDef
HAL_FLASH_Program(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
)
176 HAL_StatusTypeDef status
= HAL_ERROR
;
181 /* Check the parameters */
182 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram
));
184 /* Wait for last operation to be completed */
185 status
= FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE
);
189 if(TypeProgram
== FLASH_TYPEPROGRAM_BYTE
)
191 /*Program byte (8-bit) at a specified address.*/
192 FLASH_Program_Byte(Address
, (uint8_t) Data
);
194 else if(TypeProgram
== FLASH_TYPEPROGRAM_HALFWORD
)
196 /*Program halfword (16-bit) at a specified address.*/
197 FLASH_Program_HalfWord(Address
, (uint16_t) Data
);
199 else if(TypeProgram
== FLASH_TYPEPROGRAM_WORD
)
201 /*Program word (32-bit) at a specified address.*/
202 FLASH_Program_Word(Address
, (uint32_t) Data
);
206 /*Program double word (64-bit) at a specified address.*/
207 FLASH_Program_DoubleWord(Address
, Data
);
210 /* Wait for last operation to be completed */
211 status
= FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE
);
213 /* If the program operation is completed, disable the PG Bit */
214 FLASH
->CR
&= (~FLASH_CR_PG
);
217 /* Process Unlocked */
218 __HAL_UNLOCK(&pFlash
);
224 * @brief Program byte, halfword, word or double word at a specified address with interrupt enabled.
225 * @param TypeProgram: Indicate the way to program at a specified address.
226 * This parameter can be a value of @ref FLASH_Type_Program
227 * @param Address: specifies the address to be programmed.
228 * @param Data: specifies the data to be programmed
232 HAL_StatusTypeDef
HAL_FLASH_Program_IT(uint32_t TypeProgram
, uint32_t Address
, uint64_t Data
)
234 HAL_StatusTypeDef status
= HAL_OK
;
239 /* Check the parameters */
240 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram
));
242 /* Enable End of FLASH Operation interrupt */
243 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP
);
245 /* Enable Error source interrupt */
246 __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR
);
248 pFlash
.ProcedureOnGoing
= FLASH_PROC_PROGRAM
;
249 pFlash
.Address
= Address
;
251 if(TypeProgram
== FLASH_TYPEPROGRAM_BYTE
)
253 /*Program byte (8-bit) at a specified address.*/
254 FLASH_Program_Byte(Address
, (uint8_t) Data
);
256 else if(TypeProgram
== FLASH_TYPEPROGRAM_HALFWORD
)
258 /*Program halfword (16-bit) at a specified address.*/
259 FLASH_Program_HalfWord(Address
, (uint16_t) Data
);
261 else if(TypeProgram
== FLASH_TYPEPROGRAM_WORD
)
263 /*Program word (32-bit) at a specified address.*/
264 FLASH_Program_Word(Address
, (uint32_t) Data
);
268 /*Program double word (64-bit) at a specified address.*/
269 FLASH_Program_DoubleWord(Address
, Data
);
276 * @brief This function handles FLASH interrupt request.
279 void HAL_FLASH_IRQHandler(void)
281 uint32_t addresstmp
= 0U;
283 /* Check FLASH operation error flags */
284 #if defined(FLASH_SR_RDERR)
285 if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR
| FLASH_FLAG_WRPERR
| FLASH_FLAG_PGAERR
| \
286 FLASH_FLAG_PGPERR
| FLASH_FLAG_PGSERR
| FLASH_FLAG_RDERR
)) != RESET
)
288 if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR
| FLASH_FLAG_WRPERR
| FLASH_FLAG_PGAERR
| \
289 FLASH_FLAG_PGPERR
| FLASH_FLAG_PGSERR
)) != RESET
)
290 #endif /* FLASH_SR_RDERR */
292 if(pFlash
.ProcedureOnGoing
== FLASH_PROC_SECTERASE
)
294 /*return the faulty sector*/
295 addresstmp
= pFlash
.Sector
;
296 pFlash
.Sector
= 0xFFFFFFFFU
;
298 else if(pFlash
.ProcedureOnGoing
== FLASH_PROC_MASSERASE
)
300 /*return the faulty bank*/
301 addresstmp
= pFlash
.Bank
;
305 /*return the faulty address*/
306 addresstmp
= pFlash
.Address
;
309 /*Save the Error code*/
310 FLASH_SetErrorCode();
312 /* FLASH error interrupt user callback */
313 HAL_FLASH_OperationErrorCallback(addresstmp
);
315 /*Stop the procedure ongoing*/
316 pFlash
.ProcedureOnGoing
= FLASH_PROC_NONE
;
319 /* Check FLASH End of Operation flag */
320 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP
) != RESET
)
322 /* Clear FLASH End of Operation pending bit */
323 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP
);
325 if(pFlash
.ProcedureOnGoing
== FLASH_PROC_SECTERASE
)
327 /*Nb of sector to erased can be decreased*/
328 pFlash
.NbSectorsToErase
--;
330 /* Check if there are still sectors to erase*/
331 if(pFlash
.NbSectorsToErase
!= 0U)
333 addresstmp
= pFlash
.Sector
;
334 /*Indicate user which sector has been erased*/
335 HAL_FLASH_EndOfOperationCallback(addresstmp
);
337 /*Increment sector number*/
339 addresstmp
= pFlash
.Sector
;
340 FLASH_Erase_Sector(addresstmp
, pFlash
.VoltageForErase
);
344 /*No more sectors to Erase, user callback can be called.*/
345 /*Reset Sector and stop Erase sectors procedure*/
346 pFlash
.Sector
= addresstmp
= 0xFFFFFFFFU
;
347 pFlash
.ProcedureOnGoing
= FLASH_PROC_NONE
;
349 /* Flush the caches to be sure of the data consistency */
350 FLASH_FlushCaches() ;
352 /* FLASH EOP interrupt user callback */
353 HAL_FLASH_EndOfOperationCallback(addresstmp
);
358 if(pFlash
.ProcedureOnGoing
== FLASH_PROC_MASSERASE
)
360 /* MassErase ended. Return the selected bank */
361 /* Flush the caches to be sure of the data consistency */
362 FLASH_FlushCaches() ;
364 /* FLASH EOP interrupt user callback */
365 HAL_FLASH_EndOfOperationCallback(pFlash
.Bank
);
369 /*Program ended. Return the selected address*/
370 /* FLASH EOP interrupt user callback */
371 HAL_FLASH_EndOfOperationCallback(pFlash
.Address
);
373 pFlash
.ProcedureOnGoing
= FLASH_PROC_NONE
;
377 if(pFlash
.ProcedureOnGoing
== FLASH_PROC_NONE
)
379 /* Operation is completed, disable the PG, SER, SNB and MER Bits */
380 CLEAR_BIT(FLASH
->CR
, (FLASH_CR_PG
| FLASH_CR_SER
| FLASH_CR_SNB
| FLASH_MER_BIT
));
382 /* Disable End of FLASH Operation interrupt */
383 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP
);
385 /* Disable Error source interrupt */
386 __HAL_FLASH_DISABLE_IT(FLASH_IT_ERR
);
388 /* Process Unlocked */
389 __HAL_UNLOCK(&pFlash
);
394 * @brief FLASH end of operation interrupt callback
395 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
396 * Mass Erase: Bank number which has been requested to erase
397 * Sectors Erase: Sector which has been erased
398 * (if 0xFFFFFFFFU, it means that all the selected sectors have been erased)
399 * Program: Address which was selected for data program
402 __weak
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue
)
404 /* Prevent unused argument(s) compilation warning */
406 /* NOTE : This function Should not be modified, when the callback is needed,
407 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
412 * @brief FLASH operation error interrupt callback
413 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
414 * Mass Erase: Bank number which has been requested to erase
415 * Sectors Erase: Sector number which returned an error
416 * Program: Address which was selected for data program
419 __weak
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue
)
421 /* Prevent unused argument(s) compilation warning */
423 /* NOTE : This function Should not be modified, when the callback is needed,
424 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
432 /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
433 * @brief management functions
436 ===============================================================================
437 ##### Peripheral Control functions #####
438 ===============================================================================
440 This subsection provides a set of functions allowing to control the FLASH
448 * @brief Unlock the FLASH control register access
451 HAL_StatusTypeDef
HAL_FLASH_Unlock(void)
453 if((FLASH
->CR
& FLASH_CR_LOCK
) != RESET
)
455 /* Authorize the FLASH Registers access */
456 FLASH
->KEYR
= FLASH_KEY1
;
457 FLASH
->KEYR
= FLASH_KEY2
;
468 * @brief Locks the FLASH control register access
471 HAL_StatusTypeDef
HAL_FLASH_Lock(void)
473 /* Set the LOCK Bit to lock the FLASH Registers access */
474 FLASH
->CR
|= FLASH_CR_LOCK
;
480 * @brief Unlock the FLASH Option Control Registers access.
483 HAL_StatusTypeDef
HAL_FLASH_OB_Unlock(void)
485 if((FLASH
->OPTCR
& FLASH_OPTCR_OPTLOCK
) != RESET
)
487 /* Authorizes the Option Byte register programming */
488 FLASH
->OPTKEYR
= FLASH_OPT_KEY1
;
489 FLASH
->OPTKEYR
= FLASH_OPT_KEY2
;
500 * @brief Lock the FLASH Option Control Registers access.
503 HAL_StatusTypeDef
HAL_FLASH_OB_Lock(void)
505 /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
506 FLASH
->OPTCR
|= FLASH_OPTCR_OPTLOCK
;
512 * @brief Launch the option byte loading.
515 HAL_StatusTypeDef
HAL_FLASH_OB_Launch(void)
517 /* Set the OPTSTRT bit in OPTCR register */
518 *(__IO
uint8_t *)OPTCR_BYTE0_ADDRESS
|= FLASH_OPTCR_OPTSTRT
;
520 /* Wait for last operation to be completed */
521 return(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE
));
528 /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
529 * @brief Peripheral Errors functions
532 ===============================================================================
533 ##### Peripheral Errors functions #####
534 ===============================================================================
536 This subsection permits to get in run-time Errors of the FLASH peripheral.
543 * @brief Get the specific FLASH error flag.
544 * @retval FLASH_ErrorCode: The returned value can be a combination of:
545 * @arg HAL_FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP)
546 * @arg HAL_FLASH_ERROR_PGS: FLASH Programming Sequence error flag
547 * @arg HAL_FLASH_ERROR_PGP: FLASH Programming Parallelism error flag
548 * @arg HAL_FLASH_ERROR_PGA: FLASH Programming Alignment error flag
549 * @arg HAL_FLASH_ERROR_WRP: FLASH Write protected error flag
550 * @arg HAL_FLASH_ERROR_OPERATION: FLASH operation Error flag
552 uint32_t HAL_FLASH_GetError(void)
554 return pFlash
.ErrorCode
;
562 * @brief Wait for a FLASH operation to complete.
563 * @param Timeout: maximum flash operationtimeout
566 HAL_StatusTypeDef
FLASH_WaitForLastOperation(uint32_t Timeout
)
568 uint32_t tickstart
= 0U;
570 /* Clear Error Code */
571 pFlash
.ErrorCode
= HAL_FLASH_ERROR_NONE
;
573 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
574 Even if the FLASH operation fails, the BUSY flag will be reset and an error
577 tickstart
= HAL_GetTick();
579 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY
) != RESET
)
581 if(Timeout
!= HAL_MAX_DELAY
)
583 if((Timeout
== 0U)||((HAL_GetTick() - tickstart
) > Timeout
))
590 /* Check FLASH End of Operation flag */
591 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP
) != RESET
)
593 /* Clear FLASH End of Operation pending bit */
594 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP
);
596 #if defined(FLASH_SR_RDERR)
597 if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR
| FLASH_FLAG_WRPERR
| FLASH_FLAG_PGAERR
| \
598 FLASH_FLAG_PGPERR
| FLASH_FLAG_PGSERR
| FLASH_FLAG_RDERR
)) != RESET
)
600 if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR
| FLASH_FLAG_WRPERR
| FLASH_FLAG_PGAERR
| \
601 FLASH_FLAG_PGPERR
| FLASH_FLAG_PGSERR
)) != RESET
)
602 #endif /* FLASH_SR_RDERR */
604 /*Save the error code*/
605 FLASH_SetErrorCode();
609 /* If there is no error flag set */
615 * @brief Program a double word (64-bit) at a specified address.
616 * @note This function must be used when the device voltage range is from
617 * 2.7V to 3.6V and Vpp in the range 7V to 9V.
619 * @note If an erase and a program operations are requested simultaneously,
620 * the erase operation is performed before the program one.
622 * @param Address: specifies the address to be programmed.
623 * @param Data: specifies the data to be programmed.
626 static void FLASH_Program_DoubleWord(uint32_t Address
, uint64_t Data
)
628 /* Check the parameters */
629 assert_param(IS_FLASH_ADDRESS(Address
));
631 /* If the previous operation is completed, proceed to program the new data */
632 CLEAR_BIT(FLASH
->CR
, FLASH_CR_PSIZE
);
633 FLASH
->CR
|= FLASH_PSIZE_DOUBLE_WORD
;
634 FLASH
->CR
|= FLASH_CR_PG
;
636 /* Program the double-word */
637 *(__IO
uint32_t*)Address
= (uint32_t)Data
;
638 *(__IO
uint32_t*)(Address
+4) = (uint32_t)(Data
>> 32);
643 * @brief Program word (32-bit) at a specified address.
644 * @note This function must be used when the device voltage range is from
647 * @note If an erase and a program operations are requested simultaneously,
648 * the erase operation is performed before the program one.
650 * @param Address: specifies the address to be programmed.
651 * @param Data: specifies the data to be programmed.
654 static void FLASH_Program_Word(uint32_t Address
, uint32_t Data
)
656 /* Check the parameters */
657 assert_param(IS_FLASH_ADDRESS(Address
));
659 /* If the previous operation is completed, proceed to program the new data */
660 CLEAR_BIT(FLASH
->CR
, FLASH_CR_PSIZE
);
661 FLASH
->CR
|= FLASH_PSIZE_WORD
;
662 FLASH
->CR
|= FLASH_CR_PG
;
664 *(__IO
uint32_t*)Address
= Data
;
668 * @brief Program a half-word (16-bit) at a specified address.
669 * @note This function must be used when the device voltage range is from
672 * @note If an erase and a program operations are requested simultaneously,
673 * the erase operation is performed before the program one.
675 * @param Address: specifies the address to be programmed.
676 * @param Data: specifies the data to be programmed.
679 static void FLASH_Program_HalfWord(uint32_t Address
, uint16_t Data
)
681 /* Check the parameters */
682 assert_param(IS_FLASH_ADDRESS(Address
));
684 /* If the previous operation is completed, proceed to program the new data */
685 CLEAR_BIT(FLASH
->CR
, FLASH_CR_PSIZE
);
686 FLASH
->CR
|= FLASH_PSIZE_HALF_WORD
;
687 FLASH
->CR
|= FLASH_CR_PG
;
689 *(__IO
uint16_t*)Address
= Data
;
693 * @brief Program byte (8-bit) at a specified address.
694 * @note This function must be used when the device voltage range is from
697 * @note If an erase and a program operations are requested simultaneously,
698 * the erase operation is performed before the program one.
700 * @param Address: specifies the address to be programmed.
701 * @param Data: specifies the data to be programmed.
704 static void FLASH_Program_Byte(uint32_t Address
, uint8_t Data
)
706 /* Check the parameters */
707 assert_param(IS_FLASH_ADDRESS(Address
));
709 /* If the previous operation is completed, proceed to program the new data */
710 CLEAR_BIT(FLASH
->CR
, FLASH_CR_PSIZE
);
711 FLASH
->CR
|= FLASH_PSIZE_BYTE
;
712 FLASH
->CR
|= FLASH_CR_PG
;
714 *(__IO
uint8_t*)Address
= Data
;
718 * @brief Set the specific FLASH error flag.
721 static void FLASH_SetErrorCode(void)
723 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR
) != RESET
)
725 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_WRP
;
727 /* Clear FLASH write protection error pending bit */
728 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR
);
731 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR
) != RESET
)
733 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_PGA
;
735 /* Clear FLASH Programming alignment error pending bit */
736 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGAERR
);
739 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGPERR
) != RESET
)
741 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_PGP
;
743 /* Clear FLASH Programming parallelism error pending bit */
744 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGPERR
);
747 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR
) != RESET
)
749 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_PGS
;
751 /* Clear FLASH Programming sequence error pending bit */
752 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGSERR
);
754 #if defined(FLASH_SR_RDERR)
755 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR
) != RESET
)
757 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_RD
;
759 /* Clear FLASH Proprietary readout protection error pending bit */
760 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_RDERR
);
762 #endif /* FLASH_SR_RDERR */
763 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR
) != RESET
)
765 pFlash
.ErrorCode
|= HAL_FLASH_ERROR_OPERATION
;
767 /* Clear FLASH Operation error pending bit */
768 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR
);
776 #endif /* HAL_FLASH_MODULE_ENABLED */
786 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/