STM32F4 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F4 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f4xx_flash.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4xx_FLASH_H
31 #define __STM32F4xx_FLASH_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
39 
48 /* Exported types ------------------------------------------------------------*/
52 typedef enum
53 {
54  FLASH_BUSY = 1,
55  FLASH_ERROR_PGS,
56  FLASH_ERROR_PGP,
57  FLASH_ERROR_PGA,
58  FLASH_ERROR_WRP,
59  FLASH_ERROR_PROGRAM,
60  FLASH_ERROR_OPERATION,
61  FLASH_COMPLETE
63 
64 /* Exported constants --------------------------------------------------------*/
65 
73 #define FLASH_Latency_0 ((uint8_t)0x0000)
74 #define FLASH_Latency_1 ((uint8_t)0x0001)
75 #define FLASH_Latency_2 ((uint8_t)0x0002)
76 #define FLASH_Latency_3 ((uint8_t)0x0003)
77 #define FLASH_Latency_4 ((uint8_t)0x0004)
78 #define FLASH_Latency_5 ((uint8_t)0x0005)
79 #define FLASH_Latency_6 ((uint8_t)0x0006)
80 #define FLASH_Latency_7 ((uint8_t)0x0007)
82 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
83  ((LATENCY) == FLASH_Latency_1) || \
84  ((LATENCY) == FLASH_Latency_2) || \
85  ((LATENCY) == FLASH_Latency_3) || \
86  ((LATENCY) == FLASH_Latency_4) || \
87  ((LATENCY) == FLASH_Latency_5) || \
88  ((LATENCY) == FLASH_Latency_6) || \
89  ((LATENCY) == FLASH_Latency_7))
90 
97 #define VoltageRange_1 ((uint8_t)0x00)
98 #define VoltageRange_2 ((uint8_t)0x01)
99 #define VoltageRange_3 ((uint8_t)0x02)
100 #define VoltageRange_4 ((uint8_t)0x03)
102 #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \
103  ((RANGE) == VoltageRange_2) || \
104  ((RANGE) == VoltageRange_3) || \
105  ((RANGE) == VoltageRange_4))
106 
113 #define FLASH_Sector_0 ((uint16_t)0x0000)
114 #define FLASH_Sector_1 ((uint16_t)0x0008)
115 #define FLASH_Sector_2 ((uint16_t)0x0010)
116 #define FLASH_Sector_3 ((uint16_t)0x0018)
117 #define FLASH_Sector_4 ((uint16_t)0x0020)
118 #define FLASH_Sector_5 ((uint16_t)0x0028)
119 #define FLASH_Sector_6 ((uint16_t)0x0030)
120 #define FLASH_Sector_7 ((uint16_t)0x0038)
121 #define FLASH_Sector_8 ((uint16_t)0x0040)
122 #define FLASH_Sector_9 ((uint16_t)0x0048)
123 #define FLASH_Sector_10 ((uint16_t)0x0050)
124 #define FLASH_Sector_11 ((uint16_t)0x0058)
125 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0) || ((SECTOR) == FLASH_Sector_1) ||\
126  ((SECTOR) == FLASH_Sector_2) || ((SECTOR) == FLASH_Sector_3) ||\
127  ((SECTOR) == FLASH_Sector_4) || ((SECTOR) == FLASH_Sector_5) ||\
128  ((SECTOR) == FLASH_Sector_6) || ((SECTOR) == FLASH_Sector_7) ||\
129  ((SECTOR) == FLASH_Sector_8) || ((SECTOR) == FLASH_Sector_9) ||\
130  ((SECTOR) == FLASH_Sector_10) || ((SECTOR) == FLASH_Sector_11))
131 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF)) ||\
132  (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
133 
140 #define OB_WRP_Sector_0 ((uint32_t)0x00000001)
141 #define OB_WRP_Sector_1 ((uint32_t)0x00000002)
142 #define OB_WRP_Sector_2 ((uint32_t)0x00000004)
143 #define OB_WRP_Sector_3 ((uint32_t)0x00000008)
144 #define OB_WRP_Sector_4 ((uint32_t)0x00000010)
145 #define OB_WRP_Sector_5 ((uint32_t)0x00000020)
146 #define OB_WRP_Sector_6 ((uint32_t)0x00000040)
147 #define OB_WRP_Sector_7 ((uint32_t)0x00000080)
148 #define OB_WRP_Sector_8 ((uint32_t)0x00000100)
149 #define OB_WRP_Sector_9 ((uint32_t)0x00000200)
150 #define OB_WRP_Sector_10 ((uint32_t)0x00000400)
151 #define OB_WRP_Sector_11 ((uint32_t)0x00000800)
152 #define OB_WRP_Sector_All ((uint32_t)0x00000FFF)
154 #define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
155 
162 #define OB_RDP_Level_0 ((uint8_t)0xAA)
163 #define OB_RDP_Level_1 ((uint8_t)0x55)
164 /*#define OB_RDP_Level_2 ((uint8_t)0xCC)*/
166 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
167  ((LEVEL) == OB_RDP_Level_1))/*||\
168  ((LEVEL) == OB_RDP_Level_2))*/
169 
176 #define OB_IWDG_SW ((uint8_t)0x20)
177 #define OB_IWDG_HW ((uint8_t)0x00)
178 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
179 
186 #define OB_STOP_NoRST ((uint8_t)0x40)
187 #define OB_STOP_RST ((uint8_t)0x00)
188 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
189 
197 #define OB_STDBY_NoRST ((uint8_t)0x80)
198 #define OB_STDBY_RST ((uint8_t)0x00)
199 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
200 
207 #define OB_BOR_LEVEL3 ((uint8_t)0x00)
208 #define OB_BOR_LEVEL2 ((uint8_t)0x04)
209 #define OB_BOR_LEVEL1 ((uint8_t)0x08)
210 #define OB_BOR_OFF ((uint8_t)0x0C)
211 #define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
212  ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
213 
220 #define FLASH_IT_EOP ((uint32_t)0x01000000)
221 #define FLASH_IT_ERR ((uint32_t)0x02000000)
222 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))
223 
230 #define FLASH_FLAG_EOP ((uint32_t)0x00000001)
231 #define FLASH_FLAG_OPERR ((uint32_t)0x00000002)
232 #define FLASH_FLAG_WRPERR ((uint32_t)0x00000010)
233 #define FLASH_FLAG_PGAERR ((uint32_t)0x00000020)
234 #define FLASH_FLAG_PGPERR ((uint32_t)0x00000040)
235 #define FLASH_FLAG_PGSERR ((uint32_t)0x00000080)
236 #define FLASH_FLAG_BSY ((uint32_t)0x00010000)
237 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF0C) == 0x00000000) && ((FLAG) != 0x00000000))
238 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_EOP) || ((FLAG) == FLASH_FLAG_OPERR) || \
239  ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \
240  ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \
241  ((FLAG) == FLASH_FLAG_BSY))
242 
249 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
250 #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
251 #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
252 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
253 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
254 
261 #define RDP_KEY ((uint16_t)0x00A5)
262 #define FLASH_KEY1 ((uint32_t)0x45670123)
263 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
264 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
265 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
266 
273 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
274 
277 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
278 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
279 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
280 
285 /* Exported macro ------------------------------------------------------------*/
286 /* Exported functions --------------------------------------------------------*/
287 
288 /* FLASH Interface configuration functions ************************************/
289 void FLASH_SetLatency(uint32_t FLASH_Latency);
290 void FLASH_PrefetchBufferCmd(FunctionalState NewState);
291 void FLASH_InstructionCacheCmd(FunctionalState NewState);
292 void FLASH_DataCacheCmd(FunctionalState NewState);
293 void FLASH_InstructionCacheReset(void);
294 void FLASH_DataCacheReset(void);
295 
296 /* FLASH Memory Programming functions *****************************************/
297 void FLASH_Unlock(void);
298 void FLASH_Lock(void);
299 FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);
300 FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange);
301 FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data);
302 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
303 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
304 FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);
305 
306 /* Option Bytes Programming functions *****************************************/
307 void FLASH_OB_Unlock(void);
308 void FLASH_OB_Lock(void);
309 void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
310 void FLASH_OB_RDPConfig(uint8_t OB_RDP);
311 void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
312 void FLASH_OB_BORConfig(uint8_t OB_BOR);
314 uint8_t FLASH_OB_GetUser(void);
315 uint16_t FLASH_OB_GetWRP(void);
316 FlagStatus FLASH_OB_GetRDP(void);
317 uint8_t FLASH_OB_GetBOR(void);
318 
319 /* Interrupts and flags management functions **********************************/
320 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
321 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
322 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 #endif /* __STM32F4xx_FLASH_H */
331 
340 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/