00001
00029
00030 #ifndef __STM32F4xx_FLASH_H
00031 #define __STM32F4xx_FLASH_H
00032
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036
00037
00038 #include "stm32f4xx.h"
00039
00048
00052 typedef enum
00053 {
00054 FLASH_BUSY = 1,
00055 FLASH_ERROR_PGS,
00056 FLASH_ERROR_PGP,
00057 FLASH_ERROR_PGA,
00058 FLASH_ERROR_WRP,
00059 FLASH_ERROR_PROGRAM,
00060 FLASH_ERROR_OPERATION,
00061 FLASH_COMPLETE
00062 }FLASH_Status;
00063
00064
00065
00073 #define FLASH_Latency_0 ((uint8_t)0x0000)
00074 #define FLASH_Latency_1 ((uint8_t)0x0001)
00075 #define FLASH_Latency_2 ((uint8_t)0x0002)
00076 #define FLASH_Latency_3 ((uint8_t)0x0003)
00077 #define FLASH_Latency_4 ((uint8_t)0x0004)
00078 #define FLASH_Latency_5 ((uint8_t)0x0005)
00079 #define FLASH_Latency_6 ((uint8_t)0x0006)
00080 #define FLASH_Latency_7 ((uint8_t)0x0007)
00082 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
00083 ((LATENCY) == FLASH_Latency_1) || \
00084 ((LATENCY) == FLASH_Latency_2) || \
00085 ((LATENCY) == FLASH_Latency_3) || \
00086 ((LATENCY) == FLASH_Latency_4) || \
00087 ((LATENCY) == FLASH_Latency_5) || \
00088 ((LATENCY) == FLASH_Latency_6) || \
00089 ((LATENCY) == FLASH_Latency_7))
00090
00097 #define VoltageRange_1 ((uint8_t)0x00)
00098 #define VoltageRange_2 ((uint8_t)0x01)
00099 #define VoltageRange_3 ((uint8_t)0x02)
00100 #define VoltageRange_4 ((uint8_t)0x03)
00102 #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \
00103 ((RANGE) == VoltageRange_2) || \
00104 ((RANGE) == VoltageRange_3) || \
00105 ((RANGE) == VoltageRange_4))
00106
00113 #define FLASH_Sector_0 ((uint16_t)0x0000)
00114 #define FLASH_Sector_1 ((uint16_t)0x0008)
00115 #define FLASH_Sector_2 ((uint16_t)0x0010)
00116 #define FLASH_Sector_3 ((uint16_t)0x0018)
00117 #define FLASH_Sector_4 ((uint16_t)0x0020)
00118 #define FLASH_Sector_5 ((uint16_t)0x0028)
00119 #define FLASH_Sector_6 ((uint16_t)0x0030)
00120 #define FLASH_Sector_7 ((uint16_t)0x0038)
00121 #define FLASH_Sector_8 ((uint16_t)0x0040)
00122 #define FLASH_Sector_9 ((uint16_t)0x0048)
00123 #define FLASH_Sector_10 ((uint16_t)0x0050)
00124 #define FLASH_Sector_11 ((uint16_t)0x0058)
00125 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0) || ((SECTOR) == FLASH_Sector_1) ||\
00126 ((SECTOR) == FLASH_Sector_2) || ((SECTOR) == FLASH_Sector_3) ||\
00127 ((SECTOR) == FLASH_Sector_4) || ((SECTOR) == FLASH_Sector_5) ||\
00128 ((SECTOR) == FLASH_Sector_6) || ((SECTOR) == FLASH_Sector_7) ||\
00129 ((SECTOR) == FLASH_Sector_8) || ((SECTOR) == FLASH_Sector_9) ||\
00130 ((SECTOR) == FLASH_Sector_10) || ((SECTOR) == FLASH_Sector_11))
00131 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF)) ||\
00132 (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
00133
00140 #define OB_WRP_Sector_0 ((uint32_t)0x00000001)
00141 #define OB_WRP_Sector_1 ((uint32_t)0x00000002)
00142 #define OB_WRP_Sector_2 ((uint32_t)0x00000004)
00143 #define OB_WRP_Sector_3 ((uint32_t)0x00000008)
00144 #define OB_WRP_Sector_4 ((uint32_t)0x00000010)
00145 #define OB_WRP_Sector_5 ((uint32_t)0x00000020)
00146 #define OB_WRP_Sector_6 ((uint32_t)0x00000040)
00147 #define OB_WRP_Sector_7 ((uint32_t)0x00000080)
00148 #define OB_WRP_Sector_8 ((uint32_t)0x00000100)
00149 #define OB_WRP_Sector_9 ((uint32_t)0x00000200)
00150 #define OB_WRP_Sector_10 ((uint32_t)0x00000400)
00151 #define OB_WRP_Sector_11 ((uint32_t)0x00000800)
00152 #define OB_WRP_Sector_All ((uint32_t)0x00000FFF)
00154 #define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
00155
00162 #define OB_RDP_Level_0 ((uint8_t)0xAA)
00163 #define OB_RDP_Level_1 ((uint8_t)0x55)
00164
00166 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
00167 ((LEVEL) == OB_RDP_Level_1))
00168
00169
00176 #define OB_IWDG_SW ((uint8_t)0x20)
00177 #define OB_IWDG_HW ((uint8_t)0x00)
00178 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
00179
00186 #define OB_STOP_NoRST ((uint8_t)0x40)
00187 #define OB_STOP_RST ((uint8_t)0x00)
00188 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
00189
00197 #define OB_STDBY_NoRST ((uint8_t)0x80)
00198 #define OB_STDBY_RST ((uint8_t)0x00)
00199 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
00200
00207 #define OB_BOR_LEVEL3 ((uint8_t)0x00)
00208 #define OB_BOR_LEVEL2 ((uint8_t)0x04)
00209 #define OB_BOR_LEVEL1 ((uint8_t)0x08)
00210 #define OB_BOR_OFF ((uint8_t)0x0C)
00211 #define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
00212 ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
00213
00220 #define FLASH_IT_EOP ((uint32_t)0x01000000)
00221 #define FLASH_IT_ERR ((uint32_t)0x02000000)
00222 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))
00223
00230 #define FLASH_FLAG_EOP ((uint32_t)0x00000001)
00231 #define FLASH_FLAG_OPERR ((uint32_t)0x00000002)
00232 #define FLASH_FLAG_WRPERR ((uint32_t)0x00000010)
00233 #define FLASH_FLAG_PGAERR ((uint32_t)0x00000020)
00234 #define FLASH_FLAG_PGPERR ((uint32_t)0x00000040)
00235 #define FLASH_FLAG_PGSERR ((uint32_t)0x00000080)
00236 #define FLASH_FLAG_BSY ((uint32_t)0x00010000)
00237 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF0C) == 0x00000000) && ((FLAG) != 0x00000000))
00238 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_EOP) || ((FLAG) == FLASH_FLAG_OPERR) || \
00239 ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \
00240 ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \
00241 ((FLAG) == FLASH_FLAG_BSY))
00242
00249 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
00250 #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
00251 #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
00252 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
00253 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
00254
00261 #define RDP_KEY ((uint16_t)0x00A5)
00262 #define FLASH_KEY1 ((uint32_t)0x45670123)
00263 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
00264 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
00265 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
00266
00273 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
00274
00277 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
00278 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
00279 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
00280
00285
00286
00287
00288
00289 void FLASH_SetLatency(uint32_t FLASH_Latency);
00290 void FLASH_PrefetchBufferCmd(FunctionalState NewState);
00291 void FLASH_InstructionCacheCmd(FunctionalState NewState);
00292 void FLASH_DataCacheCmd(FunctionalState NewState);
00293 void FLASH_InstructionCacheReset(void);
00294 void FLASH_DataCacheReset(void);
00295
00296
00297 void FLASH_Unlock(void);
00298 void FLASH_Lock(void);
00299 FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);
00300 FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange);
00301 FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data);
00302 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
00303 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
00304 FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);
00305
00306
00307 void FLASH_OB_Unlock(void);
00308 void FLASH_OB_Lock(void);
00309 void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
00310 void FLASH_OB_RDPConfig(uint8_t OB_RDP);
00311 void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
00312 void FLASH_OB_BORConfig(uint8_t OB_BOR);
00313 FLASH_Status FLASH_OB_Launch(void);
00314 uint8_t FLASH_OB_GetUser(void);
00315 uint16_t FLASH_OB_GetWRP(void);
00316 FlagStatus FLASH_OB_GetRDP(void);
00317 uint8_t FLASH_OB_GetBOR(void);
00318
00319
00320 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
00321 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
00322 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
00323 FLASH_Status FLASH_GetStatus(void);
00324 FLASH_Status FLASH_WaitForLastOperation(void);
00325
00326 #ifdef __cplusplus
00327 }
00328 #endif
00329
00330 #endif
00331
00340