2 ******************************************************************************
\r
3 * @file stm32l1xx_flash.c
\r
4 * @author MCD Application Team
\r
6 * @date 31-December-2010
\r
7 * @brief This file provides all the Flash firmware functions. These functions
\r
8 * can be executed from Internal FLASH or Internal SRAM memories.
\r
9 * The functions that should be called from SRAM are defined inside
\r
10 * the "stm32l1xx_flash_ramfunc.c" file.
\r
11 * This file provides firmware functions to manage the following
\r
12 * functionalities of the FLASH peripheral:
\r
13 * - FLASH Interface configuration
\r
14 * - FLASH Memory Programming
\r
15 * - DATA EEPROM Programming
\r
16 * - Option Bytes Programming
\r
17 * - Interrupts and flags management
\r
21 * ===================================================================
\r
22 * How to use this driver
\r
23 * ===================================================================
\r
25 * This driver provides functions to configure and program the Flash
\r
26 * memory of all STM32L1xx devices
\r
27 * These functions are split in 5 groups
\r
29 * 1. FLASH Interface configuration functions: this group includes
\r
30 * the management of following features:
\r
32 * - Enable/Disable the prefetch buffer
\r
33 * - Enable/Disable the 64 bit Read Access
\r
34 * - Enable/Disable the RUN PowerDown mode
\r
35 * - Enable/Disable the SLEEP PowerDown mode
\r
37 * 2. FLASH Memory Programming functions: this group includes all
\r
38 * needed functions to erase and program the main memory:
\r
39 * - Lock and Unlock the Flash interface.
\r
40 * - Erase function: Erase Page.
\r
41 * - Program functions: Fast Word and Half Page(should be
\r
42 * executed from internal SRAM).
\r
44 * 3. DATA EEPROM Programming functions: this group includes all
\r
45 * needed functions to erase and program the DATA EEPROM memory:
\r
46 * - Lock and Unlock the DATA EEPROM interface.
\r
47 * - Erase function: Erase Word, erase Double Word (should be
\r
48 * executed from internal SRAM).
\r
49 * - Program functions: Fast Program Byte, Fast Program Half-Word,
\r
50 * FastProgramWord, Program Byte, Program Half-Word,
\r
51 * Program Word and Program Double-Word (should be executed
\r
52 * from internal SRAM).
\r
54 * 4. FLASH Option Bytes Programming functions: this group includes
\r
55 * all needed functions to:
\r
56 * - Lock and Unlock the Flash Option bytes.
\r
57 * - Set/Reset the write protection
\r
58 * - Set the Read protection Level
\r
59 * - Set the BOR level
\r
60 * - Program the user option Bytes
\r
61 * - Launch the Option Bytes loader
\r
62 * - Get the Write protection
\r
63 * - Get the read protection status
\r
64 * - Get the BOR level
\r
65 * - Get the user option bytes
\r
67 * 5. FLASH Interrupts and flag management functions: this group
\r
68 * includes all needed functions to:
\r
69 * - Enable/Disable the flash interrupt sources
\r
70 * - Get flags status
\r
72 * - Get Flash operation status
\r
73 * - Wait for last flash operation
\r
77 ******************************************************************************
\r
80 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
81 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
82 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
83 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
84 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
85 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
87 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
88 ******************************************************************************
\r
91 /* Includes ------------------------------------------------------------------*/
\r
92 #include "stm32l1xx_flash.h"
\r
94 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
98 /** @defgroup FLASH
\r
99 * @brief FLASH driver modules
\r
103 /* Private typedef -----------------------------------------------------------*/
\r
104 /* Private define ------------------------------------------------------------*/
\r
107 #define RDPRT_MASK ((uint32_t)0x00000002)
\r
108 #define WRP01_MASK ((uint32_t)0x0000FFFF)
\r
109 #define WRP23_MASK ((uint32_t)0xFFFF0000)
\r
111 /* Private macro -------------------------------------------------------------*/
\r
112 /* Private variables ---------------------------------------------------------*/
\r
113 /* Private function prototypes -----------------------------------------------*/
\r
114 /* Private functions ---------------------------------------------------------*/
\r
116 /** @defgroup FLASH_Private_Functions
\r
120 /** @defgroup FLASH_Group1 FLASH Interface configuration functions
\r
121 * @brief FLASH Interface configuration functions
\r
124 ===============================================================================
\r
125 FLASH Interface configuration functions
\r
126 ===============================================================================
\r
128 FLASH_Interface configuration_Functions, includes the following functions:
\r
129 - void FLASH_SetLatency(uint32_t FLASH_Latency):
\r
130 To correctly read data from Flash memory, the number of wait states (LATENCY)
\r
131 must be correctly programmed according to the frequency of the CPU clock
\r
132 (HCLK) and the supply voltage of the device.
\r
133 ----------------------------------------------------------------
\r
134 | Wait states | HCLK clock frequency (MHz) |
\r
135 | |------------------------------------------------|
\r
136 | (Latency) | voltage range | voltage range |
\r
137 | | 1.65 V - 3.6 V | 2.0 V - 3.6 V |
\r
138 | |----------------|---------------|---------------|
\r
139 | | VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |
\r
140 |-------------- |----------------|---------------|---------------|
\r
141 |0WS(1CPU cycle)|0 < HCLK <= 2 |0 < HCLK <= 8 |0 < HCLK <= 16 |
\r
142 |---------------|----------------|---------------|---------------|
\r
143 |1WS(2CPU cycle)|2 < HCLK <= 4 |8 < HCLK <= 16 |16 < HCLK <= 32|
\r
144 ----------------------------------------------------------------
\r
146 - void FLASH_PrefetchBufferCmd(FunctionalState NewState);
\r
147 - void FLASH_ReadAccess64Cmd(FunctionalState NewState);
\r
148 - void FLASH_RUNPowerDownCmd(FunctionalState NewState);
\r
149 - void FLASH_SLEEPPowerDownCmd(FunctionalState NewState);
\r
150 - void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
\r
152 Here below the allowed configuration of Latency, 64Bit access and prefetch buffer
\r
153 --------------------------------------------------------------------------------
\r
154 | | ACC64 = 0 | ACC64 = 1 |
\r
155 | Latency |----------------|---------------|---------------|---------------|
\r
156 | | PRFTEN = 0 | PRFTEN = 1 | PRFTEN = 0 | PRFTEN = 1 |
\r
157 |---------------|----------------|---------------|---------------|---------------|
\r
158 |0WS(1CPU cycle)| YES | NO | YES | YES |
\r
159 |---------------|----------------|---------------|---------------|---------------|
\r
160 |1WS(2CPU cycle)| NO | NO | YES | YES |
\r
161 --------------------------------------------------------------------------------
\r
162 All these functions don't need the unlock sequence.
\r
169 * @brief Sets the code latency value.
\r
170 * @param FLASH_Latency: specifies the FLASH Latency value.
\r
171 * This parameter can be one of the following values:
\r
172 * @arg FLASH_Latency_0: FLASH Zero Latency cycle
\r
173 * @arg FLASH_Latency_1: FLASH One Latency cycle
\r
176 void FLASH_SetLatency(uint32_t FLASH_Latency)
\r
178 uint32_t tmpreg = 0;
\r
180 /* Check the parameters */
\r
181 assert_param(IS_FLASH_LATENCY(FLASH_Latency));
\r
183 /* Read the ACR register */
\r
184 tmpreg = FLASH->ACR;
\r
186 /* Sets the Latency value */
\r
187 tmpreg &= (uint32_t) (~((uint32_t)FLASH_ACR_LATENCY));
\r
188 tmpreg |= FLASH_Latency;
\r
190 /* Write the ACR register */
\r
191 FLASH->ACR = tmpreg;
\r
195 * @brief Enables or disables the Prefetch Buffer.
\r
196 * @param NewState: new state of the FLASH prefetch buffer.
\r
197 * This parameter can be: ENABLE or DISABLE.
\r
200 void FLASH_PrefetchBufferCmd(FunctionalState NewState)
\r
202 /* Check the parameters */
\r
203 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
205 if(NewState != DISABLE)
\r
207 FLASH->ACR |= FLASH_ACR_PRFTEN;
\r
211 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_PRFTEN));
\r
216 * @brief Enables or disables read access to flash by 64 bits.
\r
217 * @param NewState: new state of the FLASH read access mode.
\r
218 * This parameter can be: ENABLE or DISABLE.
\r
219 * @note - If this bit is set, the Read access 64 bit is used.
\r
220 * - If this bit is reset, the Read access 32 bit is used.
\r
221 * @note - This bit cannot be written at the same time as the LATENCY and
\r
223 * - To reset this bit, the LATENCY should be zero wait state and the
\r
227 void FLASH_ReadAccess64Cmd(FunctionalState NewState)
\r
229 /* Check the parameters */
\r
230 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
232 if(NewState != DISABLE)
\r
234 FLASH->ACR |= FLASH_ACR_ACC64;
\r
238 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_ACC64));
\r
243 * @brief Enable or disable the power down mode during Sleep mode.
\r
244 * @note This function is used to power down the FLASH when the system is in SLEEP LP mode.
\r
245 * @param NewState: new state of the power down mode during sleep mode.
\r
246 * This parameter can be: ENABLE or DISABLE.
\r
249 void FLASH_SLEEPPowerDownCmd(FunctionalState NewState)
\r
251 /* Check the parameters */
\r
252 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
254 if (NewState != DISABLE)
\r
256 /* Set the SLEEP_PD bit to put Flash in power down mode during sleep mode */
\r
257 FLASH->ACR |= FLASH_ACR_SLEEP_PD;
\r
261 /* Clear the SLEEP_PD bit in to put Flash in idle mode during sleep mode */
\r
262 FLASH->ACR &= (uint32_t)(~((uint32_t)FLASH_ACR_SLEEP_PD));
\r
270 /** @defgroup FLASH_Group2 FLASH Memory Programming functions
\r
271 * @brief FLASH Memory Programming functions
\r
274 ===============================================================================
\r
275 FLASH Memory Programming functions
\r
276 ===============================================================================
\r
278 The FLASH Memory Programming functions, includes the following functions:
\r
279 - void FLASH_Unlock(void);
\r
280 - void FLASH_Lock(void);
\r
281 - FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
\r
282 - FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data);
\r
284 Any operation of erase or program should follow these steps:
\r
286 1. Call the FLASH_Unlock() function to enable the flash control register and
\r
287 program memory access
\r
289 2. Call the desired function to erase page or program data
\r
291 3. Call the FLASH_Lock() to disable the flash program memory access
\r
292 (recommended to protect the FLASH memory against possible unwanted operation)
\r
299 * @brief Unlocks the FLASH control register and program memory access.
\r
303 void FLASH_Unlock(void)
\r
305 if((FLASH->PECR & FLASH_PECR_PRGLOCK) != RESET)
\r
307 /* Unlocking the data memory and FLASH_PECR register access */
\r
308 DATA_EEPROM_Unlock();
\r
310 /* Unlocking the program memory access */
\r
311 FLASH->PRGKEYR = FLASH_PRGKEY1;
\r
312 FLASH->PRGKEYR = FLASH_PRGKEY2;
\r
317 * @brief Locks the Program memory access.
\r
321 void FLASH_Lock(void)
\r
323 /* Set the PRGLOCK Bit to lock the program memory access */
\r
324 FLASH->PECR |= FLASH_PECR_PRGLOCK;
\r
328 * @brief Erases a specified page in program memory.
\r
329 * @note - To correctly run this function, the FLASH_Unlock() function
\r
330 * must be called before.
\r
331 * - Call the FLASH_Lock() to disable the flash memory access
\r
332 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
333 * @param Page_Address: The page address in program memory to be erased.
\r
334 * @note A Page is erased in the Program memory only if the address to load
\r
335 * is the start address of a page (multiple of 256 bytes).
\r
336 * @retval FLASH Status: The returned value can be:
\r
337 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
339 FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
\r
341 FLASH_Status status = FLASH_COMPLETE;
\r
343 /* Check the parameters */
\r
344 assert_param(IS_FLASH_PROGRAM_ADDRESS(Page_Address));
\r
346 /* Wait for last operation to be completed */
\r
347 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
349 if(status == FLASH_COMPLETE)
\r
351 /* If the previous operation is completed, proceed to erase the page */
\r
353 /* Set the ERASE bit */
\r
354 FLASH->PECR |= FLASH_PECR_ERASE;
\r
357 FLASH->PECR |= FLASH_PECR_PROG;
\r
359 /* Write 00000000h to the first word of the program page to erase */
\r
360 *(__IO uint32_t *)Page_Address = 0x00000000;
\r
362 /* Wait for last operation to be completed */
\r
363 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
365 /* If the erase operation is completed, disable the ERASE and PROG bits */
\r
366 FLASH->PECR &= (uint32_t)(~FLASH_PECR_PROG);
\r
367 FLASH->PECR &= (uint32_t)(~FLASH_PECR_ERASE);
\r
369 /* Return the Erase Status */
\r
374 * @brief Programs a word at a specified address in program memory.
\r
375 * @note - To correctly run this function, the FLASH_Unlock() function
\r
376 * must be called before.
\r
377 * - Call the FLASH_Lock() to disable the flash memory access
\r
378 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
379 * @param Address: specifies the address to be written.
\r
380 * @param Data: specifies the data to be written.
\r
381 * @retval FLASH Status: The returned value can be:
\r
382 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
384 FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data)
\r
386 FLASH_Status status = FLASH_COMPLETE;
\r
388 /* Check the parameters */
\r
389 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
\r
391 /* Wait for last operation to be completed */
\r
392 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
394 if(status == FLASH_COMPLETE)
\r
396 /* If the previous operation is completed, proceed to program the new word */
\r
397 *(__IO uint32_t *)Address = Data;
\r
399 /* Wait for last operation to be completed */
\r
400 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
402 /* Return the Write Status */
\r
410 /** @defgroup FLASH_Group3 DATA EEPROM Programming functions
\r
411 * @brief DATA EEPROM Programming functions
\r
414 ===============================================================================
\r
415 DATA EEPROM Programming functions
\r
416 ===============================================================================
\r
418 The DATA_EEPROM Programming_Functions, includes the following functions:
\r
419 - void DATA_EEPROM_Unlock(void);
\r
420 - void DATA_EEPROM_Lock(void);
\r
421 - FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address);
\r
422 - FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data);
\r
423 - FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data);
\r
424 - FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data);
\r
425 - FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data);
\r
426 - FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data);
\r
427 - FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data);
\r
429 Any operation of erase or program should follow these steps:
\r
431 1. Call the DATA_EEPROM_Unlock() function to enable the data EEPROM access
\r
432 and Flash program erase control register access.
\r
434 2. Call the desired function to erase or program data
\r
436 3. Call the DATA_EEPROM_Lock() to disable the data EEPROM access
\r
437 and Flash program erase control register access(recommended
\r
438 to protect the DATA_EEPROM against possible unwanted operation)
\r
445 * @brief Unlocks the data memory and FLASH_PECR register access.
\r
449 void DATA_EEPROM_Unlock(void)
\r
451 if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
\r
453 /* Unlocking the Data memory and FLASH_PECR register access*/
\r
454 FLASH->PEKEYR = FLASH_PEKEY1;
\r
455 FLASH->PEKEYR = FLASH_PEKEY2;
\r
460 * @brief Locks the Data memory and FLASH_PECR register access.
\r
464 void DATA_EEPROM_Lock(void)
\r
466 /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */
\r
467 FLASH->PECR |= FLASH_PECR_PELOCK;
\r
471 * @brief Enables or disables DATA EEPROM fixed Time programming (2*Tprog).
\r
472 * @param NewState: new state of the DATA EEPROM fixed Time programming mode.
\r
473 * This parameter can be: ENABLE or DISABLE.
\r
476 void DATA_EEPROM_FixedTimeProgramCmd(FunctionalState NewState)
\r
478 /* Check the parameters */
\r
479 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
481 if(NewState != DISABLE)
\r
483 FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW;
\r
487 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
\r
492 * @brief Erase a word in data memory.
\r
493 * @param Address: specifies the address to be erased
\r
494 * @note1 - A data memory word is erased in the data memory only if the address
\r
495 * to load is the start address of a word (multiple of a word).
\r
496 * @note2 - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
497 * must be called before.
\r
498 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
499 * and Flash program erase control register access(recommended to protect
\r
500 * the DATA_EEPROM against possible unwanted operation)
\r
501 * @retval FLASH Status: The returned value can be:
\r
502 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
504 FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address)
\r
506 FLASH_Status status = FLASH_COMPLETE;
\r
508 /* Check the parameters */
\r
509 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
511 /* Wait for last operation to be completed */
\r
512 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
514 if(status == FLASH_COMPLETE)
\r
516 /* Write "00000000h" to valid address in the data memory" */
\r
517 *(__IO uint32_t *) Address = 0x00000000;
\r
520 /* Return the erase status */
\r
525 * @brief Write a Byte at a specified address in data memory.
\r
526 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
527 * must be called before.
\r
528 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
529 * and Flash program erase control register access(recommended to protect
\r
530 * the DATA_EEPROM against possible unwanted operation)
\r
531 * @param Address: specifies the address to be written.
\r
532 * @param Data: specifies the data to be written.
\r
533 * @note This function assumes that the is data word is already erased.
\r
534 * @retval FLASH Status: The returned value can be:
\r
535 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
537 FLASH_Status DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data)
\r
539 FLASH_Status status = FLASH_COMPLETE;
\r
540 uint32_t tmp = 0, tmpaddr = 0;
\r
542 /* Check the parameters */
\r
543 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
545 /* Wait for last operation to be completed */
\r
546 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
548 if(status == FLASH_COMPLETE)
\r
550 /* Clear the FTDW bit */
\r
551 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
\r
553 if(Data != (uint8_t)0x00)
\r
555 /* If the previous operation is completed, proceed to write the new Data */
\r
556 *(__IO uint8_t *)Address = Data;
\r
558 /* Wait for last operation to be completed */
\r
559 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
563 tmpaddr = Address & 0xFFFFFFFC;
\r
564 tmp = * (__IO uint32_t *) tmpaddr;
\r
565 tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));
\r
567 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
\r
568 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
\r
571 /* Return the Write Status */
\r
576 * @brief Writes a half word at a specified address in data memory.
\r
577 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
578 * must be called before.
\r
579 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
580 * and Flash program erase control register access(recommended to protect
\r
581 * the DATA_EEPROM against possible unwanted operation)
\r
582 * @param Address: specifies the address to be written.
\r
583 * @param Data: specifies the data to be written.
\r
584 * @note This function assumes that the is data word is already erased.
\r
585 * @retval FLASH Status: The returned value can be:
\r
586 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
588 FLASH_Status DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data)
\r
590 FLASH_Status status = FLASH_COMPLETE;
\r
591 uint32_t tmp = 0, tmpaddr = 0;
\r
593 /* Check the parameters */
\r
594 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
596 /* Wait for last operation to be completed */
\r
597 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
599 if(status == FLASH_COMPLETE)
\r
601 /* Clear the FTDW bit */
\r
602 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
\r
604 if(Data != (uint16_t)0x0000)
\r
606 /* If the previous operation is completed, proceed to write the new data */
\r
607 *(__IO uint16_t *)Address = Data;
\r
609 /* Wait for last operation to be completed */
\r
610 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
614 if((Address & 0x3) != 0x3)
\r
616 tmpaddr = Address & 0xFFFFFFFC;
\r
617 tmp = * (__IO uint32_t *) tmpaddr;
\r
618 tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));
\r
620 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
\r
621 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
\r
625 DATA_EEPROM_FastProgramByte(Address, 0x00);
\r
626 DATA_EEPROM_FastProgramByte(Address + 1, 0x00);
\r
630 /* Return the Write Status */
\r
635 * @brief Programs a word at a specified address in data memory.
\r
636 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
637 * must be called before.
\r
638 * - Call the DATA_EEPROM_Lock() to the data EEPROM access
\r
639 * and Flash program erase control register access(recommended to protect
\r
640 * the DATA_EEPROM against possible unwanted operation)
\r
641 * @param Address: specifies the address to be written.
\r
642 * @param Data: specifies the data to be written.
\r
643 * @note This function assumes that the is data word is already erased.
\r
644 * @retval FLASH Status: The returned value can be:
\r
645 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
647 FLASH_Status DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data)
\r
649 FLASH_Status status = FLASH_COMPLETE;
\r
651 /* Check the parameters */
\r
652 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
654 /* Wait for last operation to be completed */
\r
655 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
657 if(status == FLASH_COMPLETE)
\r
659 /* Clear the FTDW bit */
\r
660 FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW));
\r
662 /* If the previous operation is completed, proceed to program the new data */
\r
663 *(__IO uint32_t *)Address = Data;
\r
665 /* Wait for last operation to be completed */
\r
666 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
668 /* Return the Write Status */
\r
673 * @brief Write a Byte at a specified address in data memory without erase.
\r
674 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
675 * must be called before.
\r
676 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
677 * and Flash program erase control register access(recommended to protect
\r
678 * the DATA_EEPROM against possible unwanted operation)
\r
679 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
\r
680 * this function to configure the Fixed Time Programming.
\r
681 * @param Address: specifies the address to be written.
\r
682 * @param Data: specifies the data to be written.
\r
683 * @retval FLASH Status: The returned value can be:
\r
684 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
686 FLASH_Status DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data)
\r
688 FLASH_Status status = FLASH_COMPLETE;
\r
689 uint32_t tmp = 0, tmpaddr = 0;
\r
691 /* Check the parameters */
\r
692 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
694 /* Wait for last operation to be completed */
\r
695 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
697 if(status == FLASH_COMPLETE)
\r
699 if(Data != (uint8_t) 0x00)
\r
701 *(__IO uint8_t *)Address = Data;
\r
703 /* Wait for last operation to be completed */
\r
704 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
709 tmpaddr = Address & 0xFFFFFFFC;
\r
710 tmp = * (__IO uint32_t *) tmpaddr;
\r
711 tmpaddr = 0xFF << ((uint32_t) (0x8 * (Address & 0x3)));
\r
713 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
\r
714 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
\r
717 /* Return the Write Status */
\r
722 * @brief Writes a half word at a specified address in data memory without erase.
\r
723 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
724 * must be called before.
\r
725 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
726 * and Flash program erase control register access(recommended to protect
\r
727 * the DATA_EEPROM against possible unwanted operation)
\r
728 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
\r
729 * this function to configure the Fixed Time Programming
\r
730 * @param Address: specifies the address to be written.
\r
731 * @param Data: specifies the data to be written.
\r
732 * @retval FLASH Status: The returned value can be:
\r
733 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
735 FLASH_Status DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data)
\r
737 FLASH_Status status = FLASH_COMPLETE;
\r
738 uint32_t tmp = 0, tmpaddr = 0;
\r
740 /* Check the parameters */
\r
741 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
743 /* Wait for last operation to be completed */
\r
744 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
746 if(status == FLASH_COMPLETE)
\r
748 if(Data != (uint16_t)0x0000)
\r
750 *(__IO uint16_t *)Address = Data;
\r
752 /* Wait for last operation to be completed */
\r
753 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
757 if((Address & 0x3) != 0x3)
\r
759 tmpaddr = Address & 0xFFFFFFFC;
\r
760 tmp = * (__IO uint32_t *) tmpaddr;
\r
761 tmpaddr = 0xFFFF << ((uint32_t) (0x8 * (Address & 0x3)));
\r
763 status = DATA_EEPROM_EraseWord(Address & 0xFFFFFFFC);
\r
764 status = DATA_EEPROM_FastProgramWord((Address & 0xFFFFFFFC), tmp);
\r
768 DATA_EEPROM_FastProgramByte(Address, 0x00);
\r
769 DATA_EEPROM_FastProgramByte(Address + 1, 0x00);
\r
773 /* Return the Write Status */
\r
778 * @brief Programs a word at a specified address in data memory without erase.
\r
779 * @note - To correctly run this function, the DATA_EEPROM_Unlock() function
\r
780 * must be called before.
\r
781 * - Call the DATA_EEPROM_Lock() to he data EEPROM access
\r
782 * and Flash program erase control register access(recommended to protect
\r
783 * the DATA_EEPROM against possible unwanted operation)
\r
784 * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before
\r
785 * this function to configure the Fixed Time Programming.
\r
786 * @param Address: specifies the address to be written.
\r
787 * @param Data: specifies the data to be written.
\r
788 * @retval FLASH Status: The returned value can be:
\r
789 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
791 FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)
\r
793 FLASH_Status status = FLASH_COMPLETE;
\r
795 /* Check the parameters */
\r
796 assert_param(IS_FLASH_DATA_ADDRESS(Address));
\r
798 /* Wait for last operation to be completed */
\r
799 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
801 if(status == FLASH_COMPLETE)
\r
803 *(__IO uint32_t *)Address = Data;
\r
805 /* Wait for last operation to be completed */
\r
806 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
808 /* Return the Write Status */
\r
816 /** @defgroup FLASH_Group4 Option Bytes Programming functions
\r
817 * @brief Option Bytes Programming functions
\r
820 ===============================================================================
\r
821 Option Bytes Programming functions
\r
822 ===============================================================================
\r
824 The FLASH_Option Bytes Programming_functions, includes the following functions:
\r
825 - void FLASH_OB_Unlock(void);
\r
826 - void FLASH_OB_Lock(void);
\r
827 - void FLASH_OB_Launch(void);
\r
828 - FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
\r
829 - FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
\r
830 - FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
\r
831 - FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR);
\r
832 - uint8_t FLASH_OB_GetUser(void);
\r
833 - uint32_t FLASH_OB_GetWRP(void);
\r
834 - FlagStatus FLASH_OB_GetRDP(void);
\r
835 - uint8_t FLASH_OB_GetBOR(void);
\r
837 Any operation of erase or program should follow these steps:
\r
839 1. Call the FLASH_OB_Unlock() function to enable the Flash option control register access
\r
841 2. Call one or several functions to program the desired option bytes
\r
842 - void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) => to Enable/Disable
\r
843 the desired sector write protection
\r
844 - void FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read Protection Level
\r
845 - void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) => to configure
\r
846 the user option Bytes: IWDG, STOP and the Standby.
\r
847 - void FLASH_OB_BORConfig(uint8_t OB_BOR) => to Set the BOR level
\r
848 - FLASH_Status FLASH_ProgramOTP(uint32_t Address, uint32_t Data) => to program the OTP bytes
\r
850 3. Once all needed option bytes to be programmed are correctly written, call the
\r
851 FLASH_OB_Launch(void) function to launch the Option Bytes programming process.
\r
853 4. Call the FLASH_OB_Lock() to disable the Flash option control register access (recommended
\r
854 to protect the option Bytes against possible unwanted operations)
\r
861 * @brief Unlocks the option bytes block access.
\r
865 void FLASH_OB_Unlock(void)
\r
867 if((FLASH->PECR & FLASH_PECR_OPTLOCK) != RESET)
\r
869 /* Unlocking the data memory and FLASH_PECR register access */
\r
870 DATA_EEPROM_Unlock();
\r
872 /* Unlocking the option bytes block access */
\r
873 FLASH->OPTKEYR = FLASH_OPTKEY1;
\r
874 FLASH->OPTKEYR = FLASH_OPTKEY2;
\r
879 * @brief Locks the option bytes block access.
\r
883 void FLASH_OB_Lock(void)
\r
885 /* Set the OPTLOCK Bit to lock the option bytes block access */
\r
886 FLASH->PECR |= FLASH_PECR_OPTLOCK;
\r
890 * @brief Launch the option byte loading.
\r
894 void FLASH_OB_Launch(void)
\r
896 /* Set the OBL_Launch bit to lauch the option byte loading */
\r
897 FLASH->PECR |= FLASH_PECR_OBL_LAUNCH;
\r
901 * @brief Write protects the desired pages
\r
902 * @note - To correctly run this function, the FLASH_OB_Unlock() function
\r
903 * must be called before.
\r
904 * - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes
\r
905 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
906 * @param OB_WRP: specifies the address of the pages to be write protected.
\r
907 * This parameter can be:
\r
908 * @arg value between OB_WRP_Pages0to15 and OB_WRP_Pages496to511
\r
909 * @arg OB_WRP_AllPages
\r
910 * @param NewState: new state of the specified FLASH Pages Wtite protection.
\r
911 * This parameter can be: ENABLE or DISABLE.
\r
912 * @retval FLASH Status: The returned value can be:
\r
913 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
915 FLASH_Status FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
\r
917 uint32_t WRP01_Data = 0, WRP23_Data = 0;
\r
919 FLASH_Status status = FLASH_COMPLETE;
\r
920 uint32_t tmp1 = 0, tmp2 = 0;
\r
922 /* Check the parameters */
\r
923 assert_param(IS_OB_WRP(OB_WRP));
\r
924 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
926 /* Wait for last operation to be completed */
\r
927 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
929 if(status == FLASH_COMPLETE)
\r
931 if (NewState != DISABLE)
\r
933 WRP01_Data = (uint16_t)(((OB_WRP & WRP01_MASK) | OB->WRP01));
\r
934 WRP23_Data = (uint16_t)((((OB_WRP & WRP23_MASK)>>16 | OB->WRP23)));
\r
935 tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data);
\r
938 tmp2 = (uint32_t)(~(WRP23_Data) << 16)|(WRP23_Data);
\r
944 WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01));
\r
945 WRP23_Data = (uint16_t)((((~OB_WRP & WRP23_MASK)>>16 & OB->WRP23)));
\r
947 tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data);
\r
950 tmp2 = (uint32_t)((~WRP23_Data) << 16)|(WRP23_Data);
\r
953 /* Wait for last operation to be completed */
\r
954 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
957 /* Return the write protection operation Status */
\r
962 * @brief Enables or disables the read out protection.
\r
963 * @note - To correctly run this function, the FLASH_OB_Unlock() function
\r
964 * must be called before.
\r
965 * - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes
\r
966 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
967 * @param FLASH_ReadProtection_Level: specifies the read protection level.
\r
968 * This parameter can be:
\r
969 * @arg OB_RDP_Level_0: No protection
\r
970 * @arg OB_RDP_Level_1: Read protection of the memory
\r
971 * @arg OB_RDP_Level_2: Chip protection
\r
972 * @retval FLASH Status: The returned value can be:
\r
973 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
975 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP)
\r
977 FLASH_Status status = FLASH_COMPLETE;
\r
981 /* Check the parameters */
\r
982 assert_param(IS_OB_RDP(OB_RDP));
\r
983 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
985 /* calculate the option byte to write */
\r
986 tmp1 = (uint8_t)(~(OB_RDP ));
\r
987 tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)OB_RDP));
\r
989 if(status == FLASH_COMPLETE)
\r
991 /* program read protection level */
\r
995 /* Wait for last operation to be completed */
\r
996 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
998 /* Return the Read protection operation Status */
\r
1003 * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
\r
1004 * @note - To correctly run this function, the FLASH_OB_Unlock() function
\r
1005 * must be called before.
\r
1006 * - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes
\r
1007 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
1008 * @param OB_IWDG: Selects the WDG mode
\r
1009 * This parameter can be one of the following values:
\r
1010 * @arg OB_IWDG_SW: Software WDG selected
\r
1011 * @arg OB_IWDG_HW: Hardware WDG selected
\r
1012 * @param OB_STOP: Reset event when entering STOP mode.
\r
1013 * This parameter can be one of the following values:
\r
1014 * @arg OB_STOP_NoRST: No reset generated when entering in STOP
\r
1015 * @arg OB_STOP_RST: Reset generated when entering in STOP
\r
1016 * @param OB_STDBY: Reset event when entering Standby mode.
\r
1017 * This parameter can be one of the following values:
\r
1018 * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
\r
1019 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
\r
1020 * @retval FLASH Status: The returned value can be:
\r
1021 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
1023 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
\r
1025 FLASH_Status status = FLASH_COMPLETE;
\r
1026 uint32_t tmp = 0, tmp1 = 0;
\r
1028 /* Check the parameters */
\r
1029 assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
\r
1030 assert_param(IS_OB_STOP_SOURCE(OB_STOP));
\r
1031 assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
\r
1033 /* Get the User Option byte register */
\r
1034 tmp1 = (FLASH->OBR & 0x000F0000) >> 16;
\r
1036 /* Calculate the user option byte to write */
\r
1037 tmp = (uint32_t)(((uint32_t)~((uint32_t)((uint32_t)(OB_IWDG) | (uint32_t)(OB_STOP) | (uint32_t)(OB_STDBY) | tmp1))) << ((uint32_t)0x10));
\r
1038 tmp |= ((uint32_t)(OB_IWDG) | ((uint32_t)OB_STOP) | (uint32_t)(OB_STDBY) | tmp1);
\r
1040 /* Wait for last operation to be completed */
\r
1041 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
1043 if(status == FLASH_COMPLETE)
\r
1045 /* Write the User Option Byte */
\r
1049 /* Wait for last operation to be completed */
\r
1050 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
1052 /* Return the Option Byte program Status */
\r
1057 * @brief Programs the FLASH brownout reset threshold level Option Byte.
\r
1058 * @note - To correctly run this function, the FLASH_OB_Unlock() function
\r
1059 * must be called before.
\r
1060 * - Call the FLASH_OB_Lock() to disable the flash control register access and the option bytes
\r
1061 * (recommended to protect the FLASH memory against possible unwanted operation)
\r
1062 * @param OB_BOR: Selects the brownout reset threshold level
\r
1063 * This parameter can be one of the following values:
\r
1064 * @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD
\r
1065 * power supply reaches the PDR(Power Down Reset) threshold (1.5V)
\r
1066 * @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply
\r
1067 * @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply
\r
1068 * @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply
\r
1069 * @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply
\r
1070 * @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply
\r
1071 * @retval FLASH Status: The returned value can be:
\r
1072 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
1074 FLASH_Status FLASH_OB_BORConfig(uint8_t OB_BOR)
\r
1076 FLASH_Status status = FLASH_COMPLETE;
\r
1077 uint32_t tmp = 0, tmp1 = 0;
\r
1079 /* Check the parameters */
\r
1080 assert_param(IS_OB_BOR_LEVEL(OB_BOR));
\r
1082 /* Get the User Option byte register */
\r
1083 tmp1 = (FLASH->OBR & 0x00700000) >> 16;
\r
1085 /* Calculate the option byte to write */
\r
1086 tmp = (uint32_t)~(OB_BOR | tmp1)<<16;
\r
1087 tmp |= (OB_BOR | tmp1);
\r
1089 /* Wait for last operation to be completed */
\r
1090 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
1092 if(status == FLASH_COMPLETE)
\r
1094 /* Write the BOR Option Byte */
\r
1098 /* Wait for last operation to be completed */
\r
1099 status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
\r
1101 /* Return the Option Byte program Status */
\r
1106 * @brief Returns the FLASH User Option Bytes values.
\r
1108 * @retval The FLASH User Option Bytes .
\r
1110 uint8_t FLASH_OB_GetUser(void)
\r
1112 /* Return the User Option Byte */
\r
1113 return (uint8_t)(FLASH->OBR >> 20);
\r
1117 * @brief Returns the FLASH Write Protection Option Bytes value.
\r
1119 * @retval The FLASH Write Protection Option Bytes value
\r
1121 uint32_t FLASH_OB_GetWRP(void)
\r
1123 /* Return the FLASH write protection Register value */
\r
1124 return (uint32_t)(FLASH->WRPR);
\r
1128 * @brief Checks whether the FLASH Read out Protection Status is set or not.
\r
1130 * @retval FLASH ReadOut Protection Status(SET or RESET)
\r
1132 FlagStatus FLASH_OB_GetRDP(void)
\r
1134 FlagStatus readstatus = RESET;
\r
1136 if ((uint8_t)(FLASH->OBR) != (uint8_t)OB_RDP_Level_0)
\r
1142 readstatus = RESET;
\r
1144 return readstatus;
\r
1148 * @brief Returns the FLASH BOR level.
\r
1150 * @retval The FLASH User Option Bytes .
\r
1152 uint8_t FLASH_OB_GetBOR(void)
\r
1154 /* Return the BOR level */
\r
1155 return (uint8_t)((FLASH->OBR & (uint32_t)0x000F0000) >> 16);
\r
1162 /** @defgroup FLASH_Group5 Interrupts and flags management functions
\r
1163 * @brief Interrupts and flags management functions
\r
1166 ===============================================================================
\r
1167 Interrupts and flags management functions
\r
1168 ===============================================================================
\r
1175 * @brief Enables or disables the specified FLASH interrupts.
\r
1176 * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or
\r
1178 * This parameter can be any combination of the following values:
\r
1179 * @arg FLASH_IT_EOP: FLASH end of programming Interrupt
\r
1180 * @arg FLASH_IT_ERR: FLASH Error Interrupt
\r
1183 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
\r
1185 /* Check the parameters */
\r
1186 assert_param(IS_FLASH_IT(FLASH_IT));
\r
1187 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1189 if(NewState != DISABLE)
\r
1191 /* Enable the interrupt sources */
\r
1192 FLASH->PECR |= FLASH_IT;
\r
1196 /* Disable the interrupt sources */
\r
1197 FLASH->PECR &= ~(uint32_t)FLASH_IT;
\r
1202 * @brief Checks whether the specified FLASH flag is set or not.
\r
1203 * @param FLASH_FLAG: specifies the FLASH flag to check.
\r
1204 * This parameter can be one of the following values:
\r
1205 * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag
\r
1206 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
\r
1207 * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode
\r
1208 * @arg FLASH_FLAG_ENDHV: FLASH End of high voltage flag
\r
1209 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
1210 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
1211 * @arg FLASH_FLAG_SIZERR: FLASH size error flag
\r
1212 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
\r
1213 * @retval The new state of FLASH_FLAG (SET or RESET).
\r
1215 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
\r
1217 FlagStatus bitstatus = RESET;
\r
1219 /* Check the parameters */
\r
1220 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));
\r
1222 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
\r
1228 bitstatus = RESET;
\r
1230 /* Return the new state of FLASH_FLAG (SET or RESET) */
\r
1231 return bitstatus;
\r
1235 * @brief Clears the FLASH
\92s pending flags.
\r
1236 * @param FLASH_FLAG: specifies the FLASH flags to clear.
\r
1237 * This parameter can be any combination of the following values:
\r
1238 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
\r
1239 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
\r
1240 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
\r
1241 * @arg FLASH_FLAG_SIZERR: FLASH size error flag
\r
1242 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
\r
1245 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
\r
1247 /* Check the parameters */
\r
1248 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));
\r
1250 /* Clear the flags */
\r
1251 FLASH->SR = FLASH_FLAG;
\r
1255 * @brief Returns the FLASH Status.
\r
1257 * @retval FLASH Status: The returned value can be:
\r
1258 * FLASH_BUSY, FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP or FLASH_COMPLETE.
\r
1260 FLASH_Status FLASH_GetStatus(void)
\r
1262 FLASH_Status FLASHstatus = FLASH_COMPLETE;
\r
1264 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
\r
1266 FLASHstatus = FLASH_BUSY;
\r
1270 if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)
\r
1272 FLASHstatus = FLASH_ERROR_WRP;
\r
1276 if((FLASH->SR & (uint32_t)0xFEF0) != (uint32_t)0x00)
\r
1278 FLASHstatus = FLASH_ERROR_PROGRAM;
\r
1282 FLASHstatus = FLASH_COMPLETE;
\r
1286 /* Return the FLASH Status */
\r
1287 return FLASHstatus;
\r
1292 * @brief Waits for a FLASH operation to complete or a TIMEOUT to occur.
\r
1293 * @param Timeout: FLASH programming Timeout
\r
1294 * @retval FLASH Status: The returned value can be: FLASH_BUSY,
\r
1295 * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
\r
1297 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
\r
1299 FLASH_Status status = FLASH_COMPLETE;
\r
1301 /* Check for the FLASH Status */
\r
1302 status = FLASH_GetStatus();
\r
1304 /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
\r
1305 while((status == FLASH_BUSY) && (Timeout != 0x00))
\r
1307 status = FLASH_GetStatus();
\r
1311 if(Timeout == 0x00 )
\r
1313 status = FLASH_TIMEOUT;
\r
1315 /* Return the operation status */
\r
1335 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r