STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_flash.h
Go to the documentation of this file.
00001 
00023 /* Define to prevent recursive inclusion -------------------------------------*/
00024 #ifndef __STM32F10x_FLASH_H
00025 #define __STM32F10x_FLASH_H
00026 
00027 #ifdef __cplusplus
00028  extern "C" {
00029 #endif
00030 
00031 /* Includes ------------------------------------------------------------------*/
00032 #include "stm32f10x.h"
00033 
00050 typedef enum
00051 { 
00052   FLASH_BUSY = 1,
00053   FLASH_ERROR_PG,
00054   FLASH_ERROR_WRP,
00055   FLASH_COMPLETE,
00056   FLASH_TIMEOUT
00057 }FLASH_Status;
00058 
00071 #define FLASH_Latency_0                ((uint32_t)0x00000000)  
00072 #define FLASH_Latency_1                ((uint32_t)0x00000001)  
00073 #define FLASH_Latency_2                ((uint32_t)0x00000002)  
00074 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
00075                                    ((LATENCY) == FLASH_Latency_1) || \
00076                                    ((LATENCY) == FLASH_Latency_2))
00077 
00085 #define FLASH_HalfCycleAccess_Enable   ((uint32_t)0x00000008)  
00086 #define FLASH_HalfCycleAccess_Disable  ((uint32_t)0x00000000)  
00087 #define IS_FLASH_HALFCYCLEACCESS_STATE(STATE) (((STATE) == FLASH_HalfCycleAccess_Enable) || \
00088                                                ((STATE) == FLASH_HalfCycleAccess_Disable)) 
00089 
00097 #define FLASH_PrefetchBuffer_Enable    ((uint32_t)0x00000010)  
00098 #define FLASH_PrefetchBuffer_Disable   ((uint32_t)0x00000000)  
00099 #define IS_FLASH_PREFETCHBUFFER_STATE(STATE) (((STATE) == FLASH_PrefetchBuffer_Enable) || \
00100                                               ((STATE) == FLASH_PrefetchBuffer_Disable)) 
00101 
00109 /* Values to be used with STM32 Low and Medium density devices */
00110 #define FLASH_WRProt_Pages0to3         ((uint32_t)0x00000001) 
00111 #define FLASH_WRProt_Pages4to7         ((uint32_t)0x00000002) 
00112 #define FLASH_WRProt_Pages8to11        ((uint32_t)0x00000004) 
00113 #define FLASH_WRProt_Pages12to15       ((uint32_t)0x00000008) 
00114 #define FLASH_WRProt_Pages16to19       ((uint32_t)0x00000010) 
00115 #define FLASH_WRProt_Pages20to23       ((uint32_t)0x00000020) 
00116 #define FLASH_WRProt_Pages24to27       ((uint32_t)0x00000040) 
00117 #define FLASH_WRProt_Pages28to31       ((uint32_t)0x00000080) 
00119 /* Values to be used with STM32 Medium-density devices */
00120 #define FLASH_WRProt_Pages32to35       ((uint32_t)0x00000100) 
00121 #define FLASH_WRProt_Pages36to39       ((uint32_t)0x00000200) 
00122 #define FLASH_WRProt_Pages40to43       ((uint32_t)0x00000400) 
00123 #define FLASH_WRProt_Pages44to47       ((uint32_t)0x00000800) 
00124 #define FLASH_WRProt_Pages48to51       ((uint32_t)0x00001000) 
00125 #define FLASH_WRProt_Pages52to55       ((uint32_t)0x00002000) 
00126 #define FLASH_WRProt_Pages56to59       ((uint32_t)0x00004000) 
00127 #define FLASH_WRProt_Pages60to63       ((uint32_t)0x00008000) 
00128 #define FLASH_WRProt_Pages64to67       ((uint32_t)0x00010000) 
00129 #define FLASH_WRProt_Pages68to71       ((uint32_t)0x00020000) 
00130 #define FLASH_WRProt_Pages72to75       ((uint32_t)0x00040000) 
00131 #define FLASH_WRProt_Pages76to79       ((uint32_t)0x00080000) 
00132 #define FLASH_WRProt_Pages80to83       ((uint32_t)0x00100000) 
00133 #define FLASH_WRProt_Pages84to87       ((uint32_t)0x00200000) 
00134 #define FLASH_WRProt_Pages88to91       ((uint32_t)0x00400000) 
00135 #define FLASH_WRProt_Pages92to95       ((uint32_t)0x00800000) 
00136 #define FLASH_WRProt_Pages96to99       ((uint32_t)0x01000000) 
00137 #define FLASH_WRProt_Pages100to103     ((uint32_t)0x02000000) 
00138 #define FLASH_WRProt_Pages104to107     ((uint32_t)0x04000000) 
00139 #define FLASH_WRProt_Pages108to111     ((uint32_t)0x08000000) 
00140 #define FLASH_WRProt_Pages112to115     ((uint32_t)0x10000000) 
00141 #define FLASH_WRProt_Pages116to119     ((uint32_t)0x20000000) 
00142 #define FLASH_WRProt_Pages120to123     ((uint32_t)0x40000000) 
00143 #define FLASH_WRProt_Pages124to127     ((uint32_t)0x80000000) 
00145 /* Values to be used with STM32 High-density and STM32F10X Connectivity line devices */
00146 #define FLASH_WRProt_Pages0to1         ((uint32_t)0x00000001) 
00148 #define FLASH_WRProt_Pages2to3         ((uint32_t)0x00000002) 
00150 #define FLASH_WRProt_Pages4to5         ((uint32_t)0x00000004) 
00152 #define FLASH_WRProt_Pages6to7         ((uint32_t)0x00000008) 
00154 #define FLASH_WRProt_Pages8to9         ((uint32_t)0x00000010) 
00156 #define FLASH_WRProt_Pages10to11       ((uint32_t)0x00000020) 
00158 #define FLASH_WRProt_Pages12to13       ((uint32_t)0x00000040) 
00160 #define FLASH_WRProt_Pages14to15       ((uint32_t)0x00000080) 
00162 #define FLASH_WRProt_Pages16to17       ((uint32_t)0x00000100) 
00164 #define FLASH_WRProt_Pages18to19       ((uint32_t)0x00000200) 
00166 #define FLASH_WRProt_Pages20to21       ((uint32_t)0x00000400) 
00168 #define FLASH_WRProt_Pages22to23       ((uint32_t)0x00000800) 
00170 #define FLASH_WRProt_Pages24to25       ((uint32_t)0x00001000) 
00172 #define FLASH_WRProt_Pages26to27       ((uint32_t)0x00002000) 
00174 #define FLASH_WRProt_Pages28to29       ((uint32_t)0x00004000) 
00176 #define FLASH_WRProt_Pages30to31       ((uint32_t)0x00008000) 
00178 #define FLASH_WRProt_Pages32to33       ((uint32_t)0x00010000) 
00180 #define FLASH_WRProt_Pages34to35       ((uint32_t)0x00020000) 
00182 #define FLASH_WRProt_Pages36to37       ((uint32_t)0x00040000) 
00184 #define FLASH_WRProt_Pages38to39       ((uint32_t)0x00080000) 
00186 #define FLASH_WRProt_Pages40to41       ((uint32_t)0x00100000) 
00188 #define FLASH_WRProt_Pages42to43       ((uint32_t)0x00200000) 
00190 #define FLASH_WRProt_Pages44to45       ((uint32_t)0x00400000) 
00192 #define FLASH_WRProt_Pages46to47       ((uint32_t)0x00800000) 
00194 #define FLASH_WRProt_Pages48to49       ((uint32_t)0x01000000) 
00196 #define FLASH_WRProt_Pages50to51       ((uint32_t)0x02000000) 
00198 #define FLASH_WRProt_Pages52to53       ((uint32_t)0x04000000) 
00200 #define FLASH_WRProt_Pages54to55       ((uint32_t)0x08000000) 
00202 #define FLASH_WRProt_Pages56to57       ((uint32_t)0x10000000) 
00204 #define FLASH_WRProt_Pages58to59       ((uint32_t)0x20000000) 
00206 #define FLASH_WRProt_Pages60to61       ((uint32_t)0x40000000) 
00208 #define FLASH_WRProt_Pages62to127      ((uint32_t)0x80000000) 
00209 #define FLASH_WRProt_Pages62to255      ((uint32_t)0x80000000) 
00210 #define FLASH_WRProt_Pages62to511      ((uint32_t)0x80000000) 
00212 #define FLASH_WRProt_AllPages          ((uint32_t)0xFFFFFFFF) 
00214 #define IS_FLASH_WRPROT_PAGE(PAGE) (((PAGE) != 0x00000000))
00215 
00216 #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF))
00217 
00218 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
00219 
00228 #define OB_IWDG_SW                     ((uint16_t)0x0001)  
00229 #define OB_IWDG_HW                     ((uint16_t)0x0000)  
00230 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
00231 
00240 #define OB_STOP_NoRST                  ((uint16_t)0x0002) 
00241 #define OB_STOP_RST                    ((uint16_t)0x0000) 
00242 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
00243 
00252 #define OB_STDBY_NoRST                 ((uint16_t)0x0004) 
00253 #define OB_STDBY_RST                   ((uint16_t)0x0000) 
00254 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
00255 
00256 #ifdef STM32F10X_XL
00257 
00263 #define FLASH_BOOT_Bank1  ((uint16_t)0x0000) 
00265 #define FLASH_BOOT_Bank2  ((uint16_t)0x0001) 
00268 #define IS_FLASH_BOOT(BOOT) (((BOOT) == FLASH_BOOT_Bank1) || ((BOOT) == FLASH_BOOT_Bank2))
00269 #endif
00270 
00276 #ifdef STM32F10X_XL
00277 #define FLASH_IT_BANK2_ERROR                 ((uint32_t)0x80000400)  
00278 #define FLASH_IT_BANK2_EOP                   ((uint32_t)0x80001000)  
00280 #define FLASH_IT_BANK1_ERROR                 FLASH_IT_ERROR          
00281 #define FLASH_IT_BANK1_EOP                   FLASH_IT_EOP            
00283 #define FLASH_IT_ERROR                 ((uint32_t)0x00000400)  
00284 #define FLASH_IT_EOP                   ((uint32_t)0x00001000)  
00285 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0x7FFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
00286 #else
00287 #define FLASH_IT_ERROR                 ((uint32_t)0x00000400)  
00288 #define FLASH_IT_EOP                   ((uint32_t)0x00001000)  
00289 #define FLASH_IT_BANK1_ERROR           FLASH_IT_ERROR          
00290 #define FLASH_IT_BANK1_EOP             FLASH_IT_EOP            
00292 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
00293 #endif
00294 
00302 #ifdef STM32F10X_XL
00303 #define FLASH_FLAG_BANK2_BSY                 ((uint32_t)0x80000001)  
00304 #define FLASH_FLAG_BANK2_EOP                 ((uint32_t)0x80000020)  
00305 #define FLASH_FLAG_BANK2_PGERR               ((uint32_t)0x80000004)  
00306 #define FLASH_FLAG_BANK2_WRPRTERR            ((uint32_t)0x80000010)  
00308 #define FLASH_FLAG_BANK1_BSY                 FLASH_FLAG_BSY       
00309 #define FLASH_FLAG_BANK1_EOP                 FLASH_FLAG_EOP       
00310 #define FLASH_FLAG_BANK1_PGERR               FLASH_FLAG_PGERR     
00311 #define FLASH_FLAG_BANK1_WRPRTERR            FLASH_FLAG_WRPRTERR  
00313 #define FLASH_FLAG_BSY                 ((uint32_t)0x00000001)  
00314 #define FLASH_FLAG_EOP                 ((uint32_t)0x00000020)  
00315 #define FLASH_FLAG_PGERR               ((uint32_t)0x00000004)  
00316 #define FLASH_FLAG_WRPRTERR            ((uint32_t)0x00000010)  
00317 #define FLASH_FLAG_OPTERR              ((uint32_t)0x00000001)  
00319 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0x7FFFFFCA) == 0x00000000) && ((FLAG) != 0x00000000))
00320 #define IS_FLASH_GET_FLAG(FLAG)  (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_EOP) || \
00321                                   ((FLAG) == FLASH_FLAG_PGERR) || ((FLAG) == FLASH_FLAG_WRPRTERR) || \
00322                                   ((FLAG) == FLASH_FLAG_OPTERR)|| \
00323                                   ((FLAG) == FLASH_FLAG_BANK1_BSY) || ((FLAG) == FLASH_FLAG_BANK1_EOP) || \
00324                                   ((FLAG) == FLASH_FLAG_BANK1_PGERR) || ((FLAG) == FLASH_FLAG_BANK1_WRPRTERR) || \
00325                                   ((FLAG) == FLASH_FLAG_BANK2_BSY) || ((FLAG) == FLASH_FLAG_BANK2_EOP) || \
00326                                   ((FLAG) == FLASH_FLAG_BANK2_PGERR) || ((FLAG) == FLASH_FLAG_BANK2_WRPRTERR))
00327 #else
00328 #define FLASH_FLAG_BSY                 ((uint32_t)0x00000001)  
00329 #define FLASH_FLAG_EOP                 ((uint32_t)0x00000020)  
00330 #define FLASH_FLAG_PGERR               ((uint32_t)0x00000004)  
00331 #define FLASH_FLAG_WRPRTERR            ((uint32_t)0x00000010)  
00332 #define FLASH_FLAG_OPTERR              ((uint32_t)0x00000001)  
00334 #define FLASH_FLAG_BANK1_BSY                 FLASH_FLAG_BSY       
00335 #define FLASH_FLAG_BANK1_EOP                 FLASH_FLAG_EOP       
00336 #define FLASH_FLAG_BANK1_PGERR               FLASH_FLAG_PGERR     
00337 #define FLASH_FLAG_BANK1_WRPRTERR            FLASH_FLAG_WRPRTERR  
00339 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFCA) == 0x00000000) && ((FLAG) != 0x00000000))
00340 #define IS_FLASH_GET_FLAG(FLAG)  (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_EOP) || \
00341                                   ((FLAG) == FLASH_FLAG_PGERR) || ((FLAG) == FLASH_FLAG_WRPRTERR) || \
00342                                                                   ((FLAG) == FLASH_FLAG_BANK1_BSY) || ((FLAG) == FLASH_FLAG_BANK1_EOP) || \
00343                                   ((FLAG) == FLASH_FLAG_BANK1_PGERR) || ((FLAG) == FLASH_FLAG_BANK1_WRPRTERR) || \
00344                                   ((FLAG) == FLASH_FLAG_OPTERR))
00345 #endif
00346 
00367 /*------------ Functions used for all STM32F10x devices -----*/
00368 void FLASH_SetLatency(uint32_t FLASH_Latency);
00369 void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess);
00370 void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer);
00371 void FLASH_Unlock(void);
00372 void FLASH_Lock(void);
00373 FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
00374 FLASH_Status FLASH_EraseAllPages(void);
00375 FLASH_Status FLASH_EraseOptionBytes(void);
00376 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
00377 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
00378 FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
00379 FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);
00380 FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);
00381 FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY);
00382 uint32_t FLASH_GetUserOptionByte(void);
00383 uint32_t FLASH_GetWriteProtectionOptionByte(void);
00384 FlagStatus FLASH_GetReadOutProtectionStatus(void);
00385 FlagStatus FLASH_GetPrefetchBufferStatus(void);
00386 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
00387 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
00388 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
00389 FLASH_Status FLASH_GetStatus(void);
00390 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
00391 
00392 /*------------ New function used for all STM32F10x devices -----*/
00393 void FLASH_UnlockBank1(void);
00394 void FLASH_LockBank1(void);
00395 FLASH_Status FLASH_EraseAllBank1Pages(void);
00396 FLASH_Status FLASH_GetBank1Status(void);
00397 FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout);
00398 
00399 #ifdef STM32F10X_XL
00400 /*---- New Functions used only with STM32F10x_XL density devices -----*/
00401 void FLASH_UnlockBank2(void);
00402 void FLASH_LockBank2(void);
00403 FLASH_Status FLASH_EraseAllBank2Pages(void);
00404 FLASH_Status FLASH_GetBank2Status(void);
00405 FLASH_Status FLASH_WaitForLastBank2Operation(uint32_t Timeout);
00406 FLASH_Status FLASH_BootConfig(uint16_t FLASH_BOOT);
00407 #endif
00408 
00409 #ifdef __cplusplus
00410 }
00411 #endif
00412 
00413 #endif /* __STM32F10x_FLASH_H */
00414 
00426 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/