2 ******************************************************************************
3 * @file stm32l0xx_hal_flash.c
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief FLASH HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the internal FLASH memory:
10 * + FLASH Interface configuration
11 * + FLASH Memory Programming
12 * + DATA EEPROM Programming
13 * + Option Bytes Programming
14 * + Interrupts and flags management
18 ==============================================================================
19 ##### FLASH peripheral features #####
20 ==============================================================================
22 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
23 to the Flash memory. It implements the erase and program Flash memory operations
24 and the read and write protection mechanisms.
26 [..] The Flash memory interface accelerates code execution with a system of instruction prefetch.
28 [..] The FLASH main features are:
29 (+) Flash memory read operations
30 (+) Flash memory program/erase operations
31 (+) Read / write protections
32 (+) Prefetch on I-Code
33 (+) Option Bytes programming
35 ##### How to use this driver #####
36 ==============================================================================
37 [..] This driver provides functions to configure and program the Flash
38 memory of all STM32L0xx devices.
40 (#) FLASH Memory Programming functions: this group includes all
41 needed functions to erase and program the main memory:
42 (++) Lock and Unlock the Flash interface.
43 (++) Erase function: Erase Page.
44 (++) Program functions: Fast Word and Half Page(should be
45 executed from internal SRAM).
47 (#) DATA EEPROM Programming functions: this group includes all
48 needed functions to erase and program the DATA EEPROM memory:
49 (++) Lock and Unlock the DATA EEPROM interface.
50 (++) Erase function: Erase Byte, erase HalfWord, erase Word, erase
51 Double Word (should be executed from internal SRAM).
52 (++) Program functions: Fast Program Byte, Fast Program Half-Word,
53 FastProgramWord, Program Byte, Program Half-Word,
54 Program Word and Program Double-Word (should be executed
57 (#) FLASH Option Bytes Programming functions: this group includes
58 all needed functions to:
59 (++) Lock and Unlock the Flash Option bytes.
60 (++) Set/Reset the write protection.
61 (++) Set the Read protection Level.
62 (++) Set the BOR level.
63 (++) Program the user option Bytes.
64 (++) Launch the Option Bytes loader.
65 (++) Get the Write protection.
66 (++) Get the read protection status.
67 (++) Get the BOR level.
68 (++) Get the user option bytes.
70 (#) Interrupts and flags management functions :
71 (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
72 (++) Wait for last FLASH operation according to its status
73 (++) Get error flag status by calling HAL_GetErrorCode()
75 (#) FLASH Interface configuration functions: this group includes
76 the management of following features:
77 (++) Enable/Disable the RUN PowerDown mode.
78 (++) Enable/Disable the SLEEP PowerDown mode.
80 (#) FLASH Peripheral State methods: this group includes
81 the management of following features:
82 (++) Wait for the FLASH operation
83 (++) Get the specific FLASH error flag
85 [..] In addition to these function, this driver includes a set of macros allowing
86 to handle the following operations:
88 (+) Set/Get the latency
89 (+) Enable/Disable the prefetch buffer
90 (+) Enable/Disable the preread buffer
91 (+) Enable/Disable the Flash power-down
92 (+) Enable/Disable the FLASH interrupts
93 (+) Monitor the FLASH flags status
95 ===============================================================================
96 ##### Programming operation functions #####
97 ===============================================================================
99 This subsection provides a set of functions allowing to manage the FLASH
102 [..] The FLASH Memory Programming functions, includes the following functions:
103 (+) HAL_FLASH_Unlock(void);
104 (+) HAL_FLASH_Lock(void);
105 (+) HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
106 (+) HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
108 [..] Any operation of erase or program should follow these steps:
109 (#) Call the HAL_FLASH_Unlock() function to enable the flash control register and
110 program memory access.
111 (#) Call the desired function to erase page or program data.
112 (#) Call the HAL_FLASH_Lock() to disable the flash program memory access
113 (recommended to protect the FLASH memory against possible unwanted operation).
115 ==============================================================================
116 ##### Option Bytes Programming functions #####
117 ==============================================================================
119 [..] The FLASH_Option Bytes Programming_functions, includes the following functions:
120 (+) HAL_FLASH_OB_Unlock(void);
121 (+) HAL_FLASH_OB_Lock(void);
122 (+) HAL_FLASH_OB_Launch(void);
123 (+) HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
124 (+) HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
126 [..] Any operation of erase or program should follow these steps:
127 (#) Call the HAL_FLASH_OB_Unlock() function to enable the Flash option control
129 (#) Call the following functions to program the desired option bytes.
130 (++) HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
131 (#) Once all needed option bytes to be programmed are correctly written, call the
132 HAL_FLASH_OB_Launch(void) function to launch the Option Bytes programming process.
133 (#) Call the HAL_FLASH_OB_Lock() to disable the Flash option control register access (recommended
134 to protect the option Bytes against possible unwanted operations).
136 [..] Proprietary code Read Out Protection (PcROP):
137 (#) The PcROP sector is selected by using the same option bytes as the Write
138 protection. As a result, these 2 options are exclusive each other.
139 (#) To activate PCROP mode for Flash sectors(s), you need to follow the sequence below:
140 (++) Use this function HAL_FLASHEx_AdvOBProgram with PCROPState = OB_PCROP_STATE_ENABLE.
144 ******************************************************************************
147 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
149 * Redistribution and use in source and binary forms, with or without modification,
150 * are permitted provided that the following conditions are met:
151 * 1. Redistributions of source code must retain the above copyright notice,
152 * this list of conditions and the following disclaimer.
153 * 2. Redistributions in binary form must reproduce the above copyright notice,
154 * this list of conditions and the following disclaimer in the documentation
155 * and/or other materials provided with the distribution.
156 * 3. Neither the name of STMicroelectronics nor the names of its contributors
157 * may be used to endorse or promote products derived from this software
158 * without specific prior written permission.
160 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
161 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
163 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
164 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
165 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
166 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
167 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
168 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
169 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
171 ******************************************************************************
174 /* Includes ------------------------------------------------------------------*/
175 #include "stm32l0xx_hal.h"
177 /** @addtogroup STM32L0xx_HAL_Driver
181 #ifdef HAL_FLASH_MODULE_ENABLED
183 /** @addtogroup FLASH FLASH
184 * @brief FLASH driver modules
188 /* Private typedef -----------------------------------------------------------*/
189 /* Private define ------------------------------------------------------------*/
190 /* Private macro -------------------------------------------------------------*/
191 /* Private variables ---------------------------------------------------------*/
192 /** @addtogroup FLASH_Private_Variables FLASH Internal Variables
197 * @brief Variable used for Program/Erase sectors under interruption
199 FLASH_ProcessTypeDef ProcFlash;
204 /* Private function prototypes -----------------------------------------------*/
205 static void FLASH_SetErrorCode(void);
206 static void FLASH_Program_Word(uint32_t Address, uint32_t Data);
208 /* functions -----------------------------------------------------------------*/
210 /** @addtogroup FLASH_Exported_Functions FLASH Exported functions
214 /** @addtogroup FLASH_Exported_Functions_Group1
215 * @brief Programming operation functions
222 * @brief Program word at a specified address
223 * @note To correctly run this function, the HAL_FLASH_Unlock() function
224 * must be called before.
225 * Call the HAL_FLASH_Lock() to disable the flash memory access
226 * (recommended to protect the FLASH memory against possible unwanted operation).
227 * @param TypeProgram: Indicate the way to program at a specified address.
228 * This parameter can be a value of @ref FLASH_Type_Program
229 * @param Address: specifies the address to be programmed.
230 * @param Data: specifies the data to be programmed
232 * @retval HAL_StatusTypeDef HAL Status
234 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
236 HAL_StatusTypeDef status = HAL_ERROR;
239 __HAL_LOCK(&ProcFlash);
241 /* Check the parameters */
242 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
244 /* Wait for last operation to be completed */
245 status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
249 /* Program word (32-bit) at a specified address */
250 FLASH_Program_Word(Address, (uint32_t) Data);
252 /* Wait for last operation to be completed */
253 status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
256 /* Process Unlocked */
257 __HAL_UNLOCK(&ProcFlash);
263 * @brief Program word at a specified address with interrupt enabled.
264 * @param TypeProgram: Indicate the way to program at a specified address.
265 * This parameter can be a value of @ref FLASH_Type_Program
266 * @param Address: specifies the address to be programmed.
267 * @param Data: specifies the data to be programmed
269 * @retval HAL_StatusTypeDef HAL Status
271 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data)
273 HAL_StatusTypeDef status = HAL_OK;
276 __HAL_LOCK(&ProcFlash);
278 /* Check the parameters */
279 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
281 /* Enable End of FLASH Operation interrupt */
282 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
284 /* Enable Error source interrupt */
285 __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR);
287 ProcFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM;
288 ProcFlash.Address = Address;
290 if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
292 /* Program word (32-bit) at a specified address */
293 FLASH_Program_Word(Address, (uint32_t) Data);
300 * @brief This function handles FLASH interrupt request.
304 void HAL_FLASH_IRQHandler(void)
308 /* Check FLASH operation error flags */
309 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | \
310 FLASH_FLAG_RDERR | FLASH_FLAG_FWWERR | FLASH_FLAG_NOTZEROERR) != RESET)
312 if(ProcFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
314 /* Return the faulty sector */
315 temp = ProcFlash.Page;
316 ProcFlash.Page = 0xFFFFFFFF;
320 /* Return the faulty address */
321 temp = ProcFlash.Address;
324 /* Save the Error code */
325 FLASH_SetErrorCode();
327 /* FLASH error interrupt user callback */
328 HAL_FLASH_OperationErrorCallback(temp);
330 /* Stop the procedure ongoing */
331 ProcFlash.ProcedureOnGoing = FLASH_PROC_NONE;
334 /* Check FLASH End of Operation flag */
335 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != RESET)
337 /* Clear FLASH End of Operation pending bit */
338 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
340 /* Process can continue only if no error detected */
341 if(ProcFlash.ProcedureOnGoing != FLASH_PROC_NONE)
343 if(ProcFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
345 /* Nb of sector to erased can be decreased */
346 ProcFlash.NbPagesToErase--;
348 /* Check if there are still sectors to erase */
349 if(ProcFlash.NbPagesToErase != 0)
351 temp = ProcFlash.Page;
352 /* Indicate user which sector has been erased */
353 HAL_FLASH_EndOfOperationCallback(temp);
355 /* Increment sector number */
356 temp = ProcFlash.Page + FLASH_PAGE_SIZE;
357 ProcFlash.Page = ProcFlash.Page + FLASH_PAGE_SIZE;
359 /* If the erase operation is completed, disable the ERASE Bit */
360 CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
362 FLASH_ErasePage(temp);
366 /* No more sectors to Erase, user callback can be called */
367 /* Reset Sector and stop Erase sectors procedure */
368 ProcFlash.Page = temp = 0xFFFFFFFF;
369 ProcFlash.ProcedureOnGoing = FLASH_PROC_NONE;
370 /* FLASH EOP interrupt user callback */
371 HAL_FLASH_EndOfOperationCallback(temp);
376 if(ProcFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM)
378 /* If the program operation is completed, disable the PROG Bit */
379 CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
380 /* Program ended. Return the selected address */
381 /* FLASH EOP interrupt user callback */
382 HAL_FLASH_EndOfOperationCallback(ProcFlash.Address);
384 ProcFlash.ProcedureOnGoing = FLASH_PROC_NONE;
389 if(ProcFlash.ProcedureOnGoing == FLASH_PROC_NONE)
391 /* Operation is completed, disable the PG and PER Bits */
392 CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE | FLASH_PECR_PROG);
394 /* Disable End of FLASH Operation interrupt */
395 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP);
397 /* Disable Error source interrupt */
398 __HAL_FLASH_DISABLE_IT(FLASH_IT_ERR);
400 /* Process Unlocked */
401 __HAL_UNLOCK(&ProcFlash);
407 * @brief FLASH end of operation interrupt callback
408 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
409 * - Pages Erase: Sector which has been erased
410 * (if 0xFFFFFFFF, it means that all the selected sectors have been erased)
411 * - Program: Address which was selected for data program
414 __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
416 /* NOTE : This function Should not be modified, when the callback is needed,
417 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
422 * @brief FLASH operation error interrupt callback
423 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
424 * - Pagess Erase: Sector number which returned an error
425 * - Program: Address which was selected for data program
428 __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
430 /* NOTE : This function Should not be modified, when the callback is needed,
431 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
439 /** @addtogroup FLASH_Exported_Functions_Group2
440 * @brief management functions
443 ===============================================================================
444 ##### Peripheral Control functions #####
445 ===============================================================================
447 This subsection provides a set of functions allowing to control the FLASH
455 * @brief Unlock the FLASH control register access
456 * @retval HAL_StatusTypeDef HAL Status
458 HAL_StatusTypeDef HAL_FLASH_Unlock(void)
460 if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET)
462 /* Unlocking FLASH_PECR register access */
463 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
465 FLASH->PEKEYR = FLASH_PEKEY1;
466 FLASH->PEKEYR = FLASH_PEKEY2;
469 /* Unlocking the program memory access */
470 FLASH->PRGKEYR = FLASH_PRGKEY1;
471 FLASH->PRGKEYR = FLASH_PRGKEY2;
482 * @brief Locks the FLASH control register access
483 * @retval HAL_StatusTypeDef HAL Status
485 HAL_StatusTypeDef HAL_FLASH_Lock(void)
487 /* Set the PRGLOCK Bit to lock the program memory access */
488 SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
494 * @brief Unlock the FLASH Option Control Registers access.
495 * @retval HAL_StatusTypeDef HAL Status
497 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
499 if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET)
501 /* Unlocking FLASH_PECR register access */
502 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
504 FLASH->PEKEYR = FLASH_PEKEY1;
505 FLASH->PEKEYR = FLASH_PEKEY2;
508 /* Unlocking the option bytes block access */
509 FLASH->OPTKEYR = FLASH_OPTKEY1;
510 FLASH->OPTKEYR = FLASH_OPTKEY2;
521 * @brief Lock the FLASH Option Control Registers access.
522 * @retval HAL_StatusTypeDef HAL Status
524 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
526 /* Set the OPTLOCK Bit to lock the option bytes block access */
527 SET_BIT(FLASH->PECR, FLASH_PECR_OPTLOCK);
533 * @brief Launch the option byte loading.
534 * @retval HAL_StatusTypeDef HAL Status
536 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
538 /* Clean the error context */
539 ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
541 /* Set the OBL_Launch bit to lauch the option byte loading */
542 SET_BIT(FLASH->PECR, FLASH_PECR_OBL_LAUNCH);
544 /* Wait for last operation to be completed */
545 return(FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE
553 /** @addtogroup FLASH_Exported_Functions_Group3
554 * @brief Peripheral Errors functions
557 ===============================================================================
558 ##### Peripheral Errors functions #####
559 ===============================================================================
561 This subsection permit to get in run-time Errors of the FLASH peripheral.
568 * @brief Get the specific FLASH error flag.
569 * @retval uint32_t: The returned value can be a mixed of :
570 * @arg HAL_FLASH_ERROR_RD: FLASH Read Protection error flag (PCROP)
571 * @arg HAL_FLASH_ERROR_SIZE: FLASH Programming Parallelism error flag
572 * @arg HAL_FLASH_ERROR_PGA: FLASH Programming Alignment error flag
573 * @arg HAL_FLASH_ERROR_WRP: FLASH Write protected error flag
574 * @arg HAL_FLASH_ERROR_OPTV: FLASH Option valid error flag
575 * @arg HAL_FLASH_ERROR_FWWERR: FLASH Write or Errase operation aborted
576 * @arg HAL_FLASH_ERROR_NOTZERO: FLASH Write operation is done in a not-erased region
578 uint32_t HAL_FLASH_GetError(void)
580 return ProcFlash.ErrorCode;
591 /** @addtogroup FLASH_Private_Functions
596 * @brief Wait for a FLASH operation to complete.
597 * @param Timeout: maximum flash operationtimeout
600 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
602 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
603 Even if the FLASH operation fails, the BUSY flag will be reset and an error
606 uint32_t tickstart = HAL_GetTick();
608 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET)
610 if(Timeout != HAL_MAX_DELAY)
612 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
618 if((__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) != RESET) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR) != RESET) || \
619 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR) != RESET) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) != RESET) || \
620 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR) != RESET) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_FWWERR) != RESET) || \
621 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_NOTZEROERR) != RESET))
623 /* Save the error code */
624 FLASH_SetErrorCode();
628 /* There is no error flag set */
633 * @brief Set the specific FLASH error flag.
637 static void FLASH_SetErrorCode(void)
639 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
641 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
643 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR))
645 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_PGA;
647 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR))
649 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_SIZE;
651 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
653 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
655 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR))
657 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_RD;
659 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_FWWERR))
661 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_FWWERR;
663 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_NOTZEROERR))
665 ProcFlash.ErrorCode |= HAL_FLASH_ERROR_NOTZERO;
668 /* Errors are now stored, clear errors flags */
669 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR |
670 FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR | FLASH_FLAG_FWWERR |
671 FLASH_FLAG_NOTZEROERR);
675 * @brief Erases a specified page in program memory.
676 * @note To correctly run this function, the HAL_FLASH_Unlock() function
677 * must be called before.
678 * Call the HAL_FLASH_Lock() to disable the flash memory access
679 * (recommended to protect the FLASH memory against possible unwanted operation)
680 * @param Page_Address: The page address in program memory to be erased.
681 * @note A Page is erased in the Program memory only if the address to load
682 * is the start address of a page (multiple of 128 bytes).
683 * @retval HAL_StatusTypeDef HAL Status
685 void FLASH_ErasePage(uint32_t Page_Address)
687 /* Clean the error context */
688 ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
690 /* Set the ERASE bit */
691 SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
694 SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
696 /* Write 00000000h to the first word of the program page to erase */
697 *(__IO uint32_t *)Page_Address = 0x00000000;
701 * @brief Program word (32-bit) at a specified address.
702 * @param Address: specifies the address to be programmed.
703 * @param Data: specifies the data to be programmed.
706 static void FLASH_Program_Word(uint32_t Address, uint32_t Data)
708 /* Check the parameters */
709 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
711 /* Clean the error context */
712 ProcFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
714 *(__IO uint32_t*)Address = Data;
725 #endif /* HAL_FLASH_MODULE_ENABLED */
735 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/