30 #ifndef __STM32F4xx_FLASH_H
31 #define __STM32F4xx_FLASH_H
38 #include "stm32f4xx.h"
61 FLASH_ERROR_OPERATION,
74 #define FLASH_Latency_0 ((uint8_t)0x0000)
75 #define FLASH_Latency_1 ((uint8_t)0x0001)
76 #define FLASH_Latency_2 ((uint8_t)0x0002)
77 #define FLASH_Latency_3 ((uint8_t)0x0003)
78 #define FLASH_Latency_4 ((uint8_t)0x0004)
79 #define FLASH_Latency_5 ((uint8_t)0x0005)
80 #define FLASH_Latency_6 ((uint8_t)0x0006)
81 #define FLASH_Latency_7 ((uint8_t)0x0007)
82 #define FLASH_Latency_8 ((uint8_t)0x0008)
83 #define FLASH_Latency_9 ((uint8_t)0x0009)
84 #define FLASH_Latency_10 ((uint8_t)0x000A)
85 #define FLASH_Latency_11 ((uint8_t)0x000B)
86 #define FLASH_Latency_12 ((uint8_t)0x000C)
87 #define FLASH_Latency_13 ((uint8_t)0x000D)
88 #define FLASH_Latency_14 ((uint8_t)0x000E)
89 #define FLASH_Latency_15 ((uint8_t)0x000F)
92 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
93 ((LATENCY) == FLASH_Latency_1) || \
94 ((LATENCY) == FLASH_Latency_2) || \
95 ((LATENCY) == FLASH_Latency_3) || \
96 ((LATENCY) == FLASH_Latency_4) || \
97 ((LATENCY) == FLASH_Latency_5) || \
98 ((LATENCY) == FLASH_Latency_6) || \
99 ((LATENCY) == FLASH_Latency_7) || \
100 ((LATENCY) == FLASH_Latency_8) || \
101 ((LATENCY) == FLASH_Latency_9) || \
102 ((LATENCY) == FLASH_Latency_10) || \
103 ((LATENCY) == FLASH_Latency_11) || \
104 ((LATENCY) == FLASH_Latency_12) || \
105 ((LATENCY) == FLASH_Latency_13) || \
106 ((LATENCY) == FLASH_Latency_14) || \
107 ((LATENCY) == FLASH_Latency_15))
115 #define VoltageRange_1 ((uint8_t)0x00)
116 #define VoltageRange_2 ((uint8_t)0x01)
117 #define VoltageRange_3 ((uint8_t)0x02)
118 #define VoltageRange_4 ((uint8_t)0x03)
120 #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \
121 ((RANGE) == VoltageRange_2) || \
122 ((RANGE) == VoltageRange_3) || \
123 ((RANGE) == VoltageRange_4))
131 #define FLASH_Sector_0 ((uint16_t)0x0000)
132 #define FLASH_Sector_1 ((uint16_t)0x0008)
133 #define FLASH_Sector_2 ((uint16_t)0x0010)
134 #define FLASH_Sector_3 ((uint16_t)0x0018)
135 #define FLASH_Sector_4 ((uint16_t)0x0020)
136 #define FLASH_Sector_5 ((uint16_t)0x0028)
137 #define FLASH_Sector_6 ((uint16_t)0x0030)
138 #define FLASH_Sector_7 ((uint16_t)0x0038)
139 #define FLASH_Sector_8 ((uint16_t)0x0040)
140 #define FLASH_Sector_9 ((uint16_t)0x0048)
141 #define FLASH_Sector_10 ((uint16_t)0x0050)
142 #define FLASH_Sector_11 ((uint16_t)0x0058)
143 #define FLASH_Sector_12 ((uint16_t)0x0080)
144 #define FLASH_Sector_13 ((uint16_t)0x0088)
145 #define FLASH_Sector_14 ((uint16_t)0x0090)
146 #define FLASH_Sector_15 ((uint16_t)0x0098)
147 #define FLASH_Sector_16 ((uint16_t)0x00A0)
148 #define FLASH_Sector_17 ((uint16_t)0x00A8)
149 #define FLASH_Sector_18 ((uint16_t)0x00B0)
150 #define FLASH_Sector_19 ((uint16_t)0x00B8)
151 #define FLASH_Sector_20 ((uint16_t)0x00C0)
152 #define FLASH_Sector_21 ((uint16_t)0x00C8)
153 #define FLASH_Sector_22 ((uint16_t)0x00D0)
154 #define FLASH_Sector_23 ((uint16_t)0x00D8)
156 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0) || ((SECTOR) == FLASH_Sector_1) ||\
157 ((SECTOR) == FLASH_Sector_2) || ((SECTOR) == FLASH_Sector_3) ||\
158 ((SECTOR) == FLASH_Sector_4) || ((SECTOR) == FLASH_Sector_5) ||\
159 ((SECTOR) == FLASH_Sector_6) || ((SECTOR) == FLASH_Sector_7) ||\
160 ((SECTOR) == FLASH_Sector_8) || ((SECTOR) == FLASH_Sector_9) ||\
161 ((SECTOR) == FLASH_Sector_10) || ((SECTOR) == FLASH_Sector_11) ||\
162 ((SECTOR) == FLASH_Sector_12) || ((SECTOR) == FLASH_Sector_13) ||\
163 ((SECTOR) == FLASH_Sector_14) || ((SECTOR) == FLASH_Sector_15) ||\
164 ((SECTOR) == FLASH_Sector_16) || ((SECTOR) == FLASH_Sector_17) ||\
165 ((SECTOR) == FLASH_Sector_18) || ((SECTOR) == FLASH_Sector_19) ||\
166 ((SECTOR) == FLASH_Sector_20) || ((SECTOR) == FLASH_Sector_21) ||\
167 ((SECTOR) == FLASH_Sector_22) || ((SECTOR) == FLASH_Sector_23))
169 #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
170 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x081FFFFF)) ||\
171 (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
174 #if defined (STM32F40_41xxx)
175 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF)) ||\
176 (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
179 #if defined (STM32F401xx)
180 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x0803FFFF)) ||\
181 (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
190 #define OB_WRP_Sector_0 ((uint32_t)0x00000001)
191 #define OB_WRP_Sector_1 ((uint32_t)0x00000002)
192 #define OB_WRP_Sector_2 ((uint32_t)0x00000004)
193 #define OB_WRP_Sector_3 ((uint32_t)0x00000008)
194 #define OB_WRP_Sector_4 ((uint32_t)0x00000010)
195 #define OB_WRP_Sector_5 ((uint32_t)0x00000020)
196 #define OB_WRP_Sector_6 ((uint32_t)0x00000040)
197 #define OB_WRP_Sector_7 ((uint32_t)0x00000080)
198 #define OB_WRP_Sector_8 ((uint32_t)0x00000100)
199 #define OB_WRP_Sector_9 ((uint32_t)0x00000200)
200 #define OB_WRP_Sector_10 ((uint32_t)0x00000400)
201 #define OB_WRP_Sector_11 ((uint32_t)0x00000800)
202 #define OB_WRP_Sector_12 ((uint32_t)0x00000001)
203 #define OB_WRP_Sector_13 ((uint32_t)0x00000002)
204 #define OB_WRP_Sector_14 ((uint32_t)0x00000004)
205 #define OB_WRP_Sector_15 ((uint32_t)0x00000008)
206 #define OB_WRP_Sector_16 ((uint32_t)0x00000010)
207 #define OB_WRP_Sector_17 ((uint32_t)0x00000020)
208 #define OB_WRP_Sector_18 ((uint32_t)0x00000040)
209 #define OB_WRP_Sector_19 ((uint32_t)0x00000080)
210 #define OB_WRP_Sector_20 ((uint32_t)0x00000100)
211 #define OB_WRP_Sector_21 ((uint32_t)0x00000200)
212 #define OB_WRP_Sector_22 ((uint32_t)0x00000400)
213 #define OB_WRP_Sector_23 ((uint32_t)0x00000800)
214 #define OB_WRP_Sector_All ((uint32_t)0x00000FFF)
216 #define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
224 #define OB_PcROP_Disable ((uint8_t)0x00)
225 #define OB_PcROP_Enable ((uint8_t)0x80)
226 #define IS_OB_PCROP_SELECT(PCROP) (((PCROP) == OB_PcROP_Disable) || ((PCROP) == OB_PcROP_Enable))
234 #define OB_PCROP_Sector_0 ((uint32_t)0x00000001)
235 #define OB_PCROP_Sector_1 ((uint32_t)0x00000002)
236 #define OB_PCROP_Sector_2 ((uint32_t)0x00000004)
237 #define OB_PCROP_Sector_3 ((uint32_t)0x00000008)
238 #define OB_PCROP_Sector_4 ((uint32_t)0x00000010)
239 #define OB_PCROP_Sector_5 ((uint32_t)0x00000020)
240 #define OB_PCROP_Sector_6 ((uint32_t)0x00000040)
241 #define OB_PCROP_Sector_7 ((uint32_t)0x00000080)
242 #define OB_PCROP_Sector_8 ((uint32_t)0x00000100)
243 #define OB_PCROP_Sector_9 ((uint32_t)0x00000200)
244 #define OB_PCROP_Sector_10 ((uint32_t)0x00000400)
245 #define OB_PCROP_Sector_11 ((uint32_t)0x00000800)
246 #define OB_PCROP_Sector_12 ((uint32_t)0x00000001)
247 #define OB_PCROP_Sector_13 ((uint32_t)0x00000002)
248 #define OB_PCROP_Sector_14 ((uint32_t)0x00000004)
249 #define OB_PCROP_Sector_15 ((uint32_t)0x00000008)
250 #define OB_PCROP_Sector_16 ((uint32_t)0x00000010)
251 #define OB_PCROP_Sector_17 ((uint32_t)0x00000020)
252 #define OB_PCROP_Sector_18 ((uint32_t)0x00000040)
253 #define OB_PCROP_Sector_19 ((uint32_t)0x00000080)
254 #define OB_PCROP_Sector_20 ((uint32_t)0x00000100)
255 #define OB_PCROP_Sector_21 ((uint32_t)0x00000200)
256 #define OB_PCROP_Sector_22 ((uint32_t)0x00000400)
257 #define OB_PCROP_Sector_23 ((uint32_t)0x00000800)
258 #define OB_PCROP_Sector_All ((uint32_t)0x00000FFF)
260 #define IS_OB_PCROP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
268 #define OB_RDP_Level_0 ((uint8_t)0xAA)
269 #define OB_RDP_Level_1 ((uint8_t)0x55)
272 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
273 ((LEVEL) == OB_RDP_Level_1))
282 #define OB_IWDG_SW ((uint8_t)0x20)
283 #define OB_IWDG_HW ((uint8_t)0x00)
284 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
292 #define OB_STOP_NoRST ((uint8_t)0x40)
293 #define OB_STOP_RST ((uint8_t)0x00)
294 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
303 #define OB_STDBY_NoRST ((uint8_t)0x80)
304 #define OB_STDBY_RST ((uint8_t)0x00)
305 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
313 #define OB_BOR_LEVEL3 ((uint8_t)0x00)
314 #define OB_BOR_LEVEL2 ((uint8_t)0x04)
315 #define OB_BOR_LEVEL1 ((uint8_t)0x08)
316 #define OB_BOR_OFF ((uint8_t)0x0C)
317 #define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
318 ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
326 #define OB_Dual_BootEnabled ((uint8_t)0x10)
327 #define OB_Dual_BootDisabled ((uint8_t)0x00)
328 #define IS_OB_BOOT(BOOT) (((BOOT) == OB_Dual_BootEnabled) || ((BOOT) == OB_Dual_BootDisabled))
336 #define FLASH_IT_EOP ((uint32_t)0x01000000)
337 #define FLASH_IT_ERR ((uint32_t)0x02000000)
338 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))
346 #define FLASH_FLAG_EOP ((uint32_t)0x00000001)
347 #define FLASH_FLAG_OPERR ((uint32_t)0x00000002)
348 #define FLASH_FLAG_WRPERR ((uint32_t)0x00000010)
349 #define FLASH_FLAG_PGAERR ((uint32_t)0x00000020)
350 #define FLASH_FLAG_PGPERR ((uint32_t)0x00000040)
351 #define FLASH_FLAG_PGSERR ((uint32_t)0x00000080)
352 #define FLASH_FLAG_RDERR ((uint32_t)0x00000100)
353 #define FLASH_FLAG_BSY ((uint32_t)0x00010000)
354 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFE0C) == 0x00000000) && ((FLAG) != 0x00000000))
355 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_EOP) || ((FLAG) == FLASH_FLAG_OPERR) || \
356 ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \
357 ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \
358 ((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_RDERR))
366 #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
367 #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
368 #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
369 #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
370 #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
378 #define RDP_KEY ((uint16_t)0x00A5)
379 #define FLASH_KEY1 ((uint32_t)0x45670123)
380 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
381 #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
382 #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
390 #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
394 #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
398 #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
402 #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
406 #define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
411 #define OPTCR1_BYTE2_ADDRESS ((uint32_t)0x40023C1A)
void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState)
Enables or disables the write protection of the desired sectors, for the second 1 Mb of the Flash...
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
Programs a half word (16-bit) at a specified address.
void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
Enables or disables the specified FLASH interrupts.
FLASH_Status FLASH_EraseAllBank1Sectors(uint8_t VoltageRange)
Erases all FLASH Sectors in Bank 1.
void FLASH_OB_RDPConfig(uint8_t OB_RDP)
Sets the read protection level.
FLASH_Status FLASH_EraseAllBank2Sectors(uint8_t VoltageRange)
Erases all FLASH Sectors in Bank 2.
FLASH_Status FLASH_WaitForLastOperation(void)
Waits for a FLASH operation to complete.
FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
Erases a specified FLASH Sector.
uint16_t FLASH_OB_GetWRP1(void)
Returns the FLASH Write Protection Option Bytes value.
uint16_t FLASH_OB_GetWRP(void)
Returns the FLASH Write Protection Option Bytes value.
void FLASH_ClearFlag(uint32_t FLASH_FLAG)
Clears the FLASH's pending flags.
void FLASH_OB_Lock(void)
Locks the FLASH Option Control Registers access.
FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange)
Erases all FLASH Sectors.
void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState)
Enables or disables the read/write protection (PCROP) of the desired sectors, for the first 1 MB of t...
void FLASH_OB_BORConfig(uint8_t OB_BOR)
Sets the BOR Level.
void FLASH_DataCacheCmd(FunctionalState NewState)
Enables or disables the Data Cache feature.
void FLASH_InstructionCacheReset(void)
Resets the Instruction Cache.
void FLASH_InstructionCacheCmd(FunctionalState NewState)
Enables or disables the Instruction Cache feature.
FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data)
Programs a double word (64-bit) at a specified address.
void FLASH_Unlock(void)
Unlocks the FLASH control register access.
void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
Enables or disables the write protection of the desired sectors, for the first 1 Mb of the Flash...
FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
Checks whether the specified FLASH flag is set or not.
void FLASH_OB_Unlock(void)
Unlocks the FLASH Option Control Registers access.
void FLASH_DataCacheReset(void)
Resets the Data Cache.
uint16_t FLASH_OB_GetPCROP1(void)
Returns the FLASH PC Read/Write Protection Option Bytes value.
void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PcROP)
Select the Protection Mode (SPRMOD).
FlagStatus FLASH_OB_GetRDP(void)
Returns the FLASH Read Protection level.
uint8_t FLASH_OB_GetUser(void)
Returns the FLASH User Option Bytes values.
void FLASH_PrefetchBufferCmd(FunctionalState NewState)
Enables or disables the Prefetch Buffer.
uint8_t FLASH_OB_GetBOR(void)
Returns the FLASH BOR level.
FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
Programs a byte (8-bit) at a specified address.
void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState)
Enables or disables the read/write protection (PCROP) of the desired sectors.
void FLASH_SetLatency(uint32_t FLASH_Latency)
Sets the code latency value.
FLASH_Status FLASH_OB_Launch(void)
Launch the option byte loading.
FLASH_Status FLASH_GetStatus(void)
Returns the FLASH Status.
void FLASH_OB_BootConfig(uint8_t OB_BOOT)
Configure the Dual Bank Boot.
void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
void FLASH_Lock(void)
Locks the FLASH control register access.
FLASH_Status
FLASH Status.
uint16_t FLASH_OB_GetPCROP(void)
Returns the FLASH PC Read/Write Protection Option Bytes value.
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Programs a word (32-bit) at a specified address.