]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_flash.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_M4F_STM32F407ZG-SK / Libraries / STM32F4xx_StdPeriph_Driver / inc / stm32f4xx_flash.h
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f4xx_flash.h\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    30-September-2011\r
7   * @brief   This file contains all the functions prototypes for the FLASH \r
8   *          firmware library.\r
9   ******************************************************************************\r
10   * @attention\r
11   *\r
12   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
13   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
14   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
15   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
16   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
17   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
18   *\r
19   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>\r
20   ******************************************************************************\r
21   */\r
22 \r
23 /* Define to prevent recursive inclusion -------------------------------------*/\r
24 #ifndef __STM32F4xx_FLASH_H\r
25 #define __STM32F4xx_FLASH_H\r
26 \r
27 #ifdef __cplusplus\r
28  extern "C" {\r
29 #endif\r
30 \r
31 /* Includes ------------------------------------------------------------------*/\r
32 #include "stm32f4xx.h"\r
33 \r
34 /** @addtogroup STM32F4xx_StdPeriph_Driver\r
35   * @{\r
36   */\r
37 \r
38 /** @addtogroup FLASH\r
39   * @{\r
40   */ \r
41 \r
42 /* Exported types ------------------------------------------------------------*/\r
43 /** \r
44   * @brief FLASH Status  \r
45   */ \r
46 typedef enum\r
47\r
48   FLASH_BUSY = 1,\r
49   FLASH_ERROR_PGS,\r
50   FLASH_ERROR_PGP,\r
51   FLASH_ERROR_PGA,\r
52   FLASH_ERROR_WRP,\r
53   FLASH_ERROR_PROGRAM,\r
54   FLASH_ERROR_OPERATION,\r
55   FLASH_COMPLETE\r
56 }FLASH_Status;\r
57 \r
58 /* Exported constants --------------------------------------------------------*/\r
59 \r
60 /** @defgroup FLASH_Exported_Constants\r
61   * @{\r
62   */  \r
63 \r
64 /** @defgroup Flash_Latency \r
65   * @{\r
66   */ \r
67 #define FLASH_Latency_0                ((uint8_t)0x0000)  /*!< FLASH Zero Latency cycle */\r
68 #define FLASH_Latency_1                ((uint8_t)0x0001)  /*!< FLASH One Latency cycle */\r
69 #define FLASH_Latency_2                ((uint8_t)0x0002)  /*!< FLASH Two Latency cycles */\r
70 #define FLASH_Latency_3                ((uint8_t)0x0003)  /*!< FLASH Three Latency cycles */\r
71 #define FLASH_Latency_4                ((uint8_t)0x0004)  /*!< FLASH Four Latency cycles */\r
72 #define FLASH_Latency_5                ((uint8_t)0x0005)  /*!< FLASH Five Latency cycles */\r
73 #define FLASH_Latency_6                ((uint8_t)0x0006)  /*!< FLASH Six Latency cycles */\r
74 #define FLASH_Latency_7                ((uint8_t)0x0007)  /*!< FLASH Seven Latency cycles */\r
75 \r
76 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \\r
77                                    ((LATENCY) == FLASH_Latency_1) || \\r
78                                    ((LATENCY) == FLASH_Latency_2) || \\r
79                                    ((LATENCY) == FLASH_Latency_3) || \\r
80                                    ((LATENCY) == FLASH_Latency_4) || \\r
81                                    ((LATENCY) == FLASH_Latency_5) || \\r
82                                    ((LATENCY) == FLASH_Latency_6) || \\r
83                                    ((LATENCY) == FLASH_Latency_7))\r
84 /**\r
85   * @}\r
86   */ \r
87 \r
88 /** @defgroup FLASH_Voltage_Range \r
89   * @{\r
90   */ \r
91 #define VoltageRange_1        ((uint8_t)0x00)  /*!< Device operating range: 1.8V to 2.1V */\r
92 #define VoltageRange_2        ((uint8_t)0x01)  /*!<Device operating range: 2.1V to 2.7V */\r
93 #define VoltageRange_3        ((uint8_t)0x02)  /*!<Device operating range: 2.7V to 3.6V */\r
94 #define VoltageRange_4        ((uint8_t)0x03)  /*!<Device operating range: 2.7V to 3.6V + External Vpp */\r
95 \r
96 #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \\r
97                                ((RANGE) == VoltageRange_2) || \\r
98                                ((RANGE) == VoltageRange_3) || \\r
99                                ((RANGE) == VoltageRange_4))                                                                                                               \r
100 /**\r
101   * @}\r
102   */ \r
103 \r
104 /** @defgroup FLASH_Sectors\r
105   * @{\r
106   */ \r
107 #define FLASH_Sector_0     ((uint16_t)0x0000) /*!< Sector Number 0 */\r
108 #define FLASH_Sector_1     ((uint16_t)0x0008) /*!< Sector Number 1 */\r
109 #define FLASH_Sector_2     ((uint16_t)0x0010) /*!< Sector Number 2 */\r
110 #define FLASH_Sector_3     ((uint16_t)0x0018) /*!< Sector Number 3 */\r
111 #define FLASH_Sector_4     ((uint16_t)0x0020) /*!< Sector Number 4 */\r
112 #define FLASH_Sector_5     ((uint16_t)0x0028) /*!< Sector Number 5 */\r
113 #define FLASH_Sector_6     ((uint16_t)0x0030) /*!< Sector Number 6 */\r
114 #define FLASH_Sector_7     ((uint16_t)0x0038) /*!< Sector Number 7 */\r
115 #define FLASH_Sector_8     ((uint16_t)0x0040) /*!< Sector Number 8 */\r
116 #define FLASH_Sector_9     ((uint16_t)0x0048) /*!< Sector Number 9 */\r
117 #define FLASH_Sector_10    ((uint16_t)0x0050) /*!< Sector Number 10 */\r
118 #define FLASH_Sector_11    ((uint16_t)0x0058) /*!< Sector Number 11 */\r
119 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0) || ((SECTOR) == FLASH_Sector_1) ||\\r
120                                  ((SECTOR) == FLASH_Sector_2) || ((SECTOR) == FLASH_Sector_3) ||\\r
121                                  ((SECTOR) == FLASH_Sector_4) || ((SECTOR) == FLASH_Sector_5) ||\\r
122                                  ((SECTOR) == FLASH_Sector_6) || ((SECTOR) == FLASH_Sector_7) ||\\r
123                                  ((SECTOR) == FLASH_Sector_8) || ((SECTOR) == FLASH_Sector_9) ||\\r
124                                  ((SECTOR) == FLASH_Sector_10) || ((SECTOR) == FLASH_Sector_11))\r
125 #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF)) ||\\r
126                                    (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))  \r
127 /**\r
128   * @}\r
129   */ \r
130 \r
131 /** @defgroup Option_Bytes_Write_Protection \r
132   * @{\r
133   */ \r
134 #define OB_WRP_Sector_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0 */\r
135 #define OB_WRP_Sector_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1 */\r
136 #define OB_WRP_Sector_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2 */\r
137 #define OB_WRP_Sector_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3 */\r
138 #define OB_WRP_Sector_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4 */\r
139 #define OB_WRP_Sector_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5 */\r
140 #define OB_WRP_Sector_6       ((uint32_t)0x00000040) /*!< Write protection of Sector6 */\r
141 #define OB_WRP_Sector_7       ((uint32_t)0x00000080) /*!< Write protection of Sector7 */\r
142 #define OB_WRP_Sector_8       ((uint32_t)0x00000100) /*!< Write protection of Sector8 */\r
143 #define OB_WRP_Sector_9       ((uint32_t)0x00000200) /*!< Write protection of Sector9 */\r
144 #define OB_WRP_Sector_10      ((uint32_t)0x00000400) /*!< Write protection of Sector10 */\r
145 #define OB_WRP_Sector_11      ((uint32_t)0x00000800) /*!< Write protection of Sector11 */\r
146 #define OB_WRP_Sector_All     ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */\r
147 \r
148 #define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))\r
149 /**\r
150   * @}\r
151   */\r
152 \r
153 /** @defgroup FLASH_Option_Bytes_Read_Protection \r
154   * @{\r
155   */\r
156 #define OB_RDP_Level_0   ((uint8_t)0xAA)\r
157 #define OB_RDP_Level_1   ((uint8_t)0x55)\r
158 /*#define OB_RDP_Level_2   ((uint8_t)0xCC)*/ /*!< Warning: When enabling read protection level 2 \r
159                                                   it's no more possible to go back to level 1 or 0 */\r
160 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\\r
161                           ((LEVEL) == OB_RDP_Level_1))/*||\\r
162                           ((LEVEL) == OB_RDP_Level_2))*/\r
163 /**\r
164   * @}\r
165   */ \r
166 \r
167 /** @defgroup FLASH_Option_Bytes_IWatchdog \r
168   * @{\r
169   */ \r
170 #define OB_IWDG_SW                     ((uint8_t)0x20)  /*!< Software IWDG selected */\r
171 #define OB_IWDG_HW                     ((uint8_t)0x00)  /*!< Hardware IWDG selected */\r
172 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))\r
173 /**\r
174   * @}\r
175   */ \r
176 \r
177 /** @defgroup FLASH_Option_Bytes_nRST_STOP \r
178   * @{\r
179   */ \r
180 #define OB_STOP_NoRST                  ((uint8_t)0x40) /*!< No reset generated when entering in STOP */\r
181 #define OB_STOP_RST                    ((uint8_t)0x00) /*!< Reset generated when entering in STOP */\r
182 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))\r
183 /**\r
184   * @}\r
185   */ \r
186 \r
187 \r
188 /** @defgroup FLASH_Option_Bytes_nRST_STDBY \r
189   * @{\r
190   */ \r
191 #define OB_STDBY_NoRST                 ((uint8_t)0x80) /*!< No reset generated when entering in STANDBY */\r
192 #define OB_STDBY_RST                   ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */\r
193 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))\r
194 /**\r
195   * @}\r
196   */\r
197   \r
198 /** @defgroup FLASH_BOR_Reset_Level \r
199   * @{\r
200   */  \r
201 #define OB_BOR_LEVEL3          ((uint8_t)0x00)  /*!< Supply voltage ranges from 2.70 to 3.60 V */\r
202 #define OB_BOR_LEVEL2          ((uint8_t)0x04)  /*!< Supply voltage ranges from 2.40 to 2.70 V */\r
203 #define OB_BOR_LEVEL1          ((uint8_t)0x08)  /*!< Supply voltage ranges from 2.10 to 2.40 V */\r
204 #define OB_BOR_OFF             ((uint8_t)0x0C)  /*!< Supply voltage ranges from 1.62 to 2.10 V */\r
205 #define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\\r
206                           ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))\r
207 /**\r
208   * @}\r
209   */\r
210 \r
211 /** @defgroup FLASH_Interrupts \r
212   * @{\r
213   */ \r
214 #define FLASH_IT_EOP                   ((uint32_t)0x01000000)  /*!< End of FLASH Operation Interrupt source */\r
215 #define FLASH_IT_ERR                   ((uint32_t)0x02000000)  /*!< Error Interrupt source */\r
216 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))\r
217 /**\r
218   * @}\r
219   */ \r
220 \r
221 /** @defgroup FLASH_Flags \r
222   * @{\r
223   */ \r
224 #define FLASH_FLAG_EOP                 ((uint32_t)0x00000001)  /*!< FLASH End of Operation flag */\r
225 #define FLASH_FLAG_OPERR               ((uint32_t)0x00000002)  /*!< FLASH operation Error flag */\r
226 #define FLASH_FLAG_WRPERR              ((uint32_t)0x00000010)  /*!< FLASH Write protected error flag */\r
227 #define FLASH_FLAG_PGAERR              ((uint32_t)0x00000020)  /*!< FLASH Programming Alignment error flag */\r
228 #define FLASH_FLAG_PGPERR              ((uint32_t)0x00000040)  /*!< FLASH Programming Parallelism error flag  */\r
229 #define FLASH_FLAG_PGSERR              ((uint32_t)0x00000080)  /*!< FLASH Programming Sequence error flag  */\r
230 #define FLASH_FLAG_BSY                 ((uint32_t)0x00010000)  /*!< FLASH Busy flag */ \r
231 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF0C) == 0x00000000) && ((FLAG) != 0x00000000))\r
232 #define IS_FLASH_GET_FLAG(FLAG)  (((FLAG) == FLASH_FLAG_EOP) || ((FLAG) == FLASH_FLAG_OPERR) || \\r
233                                   ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \\r
234                                   ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \\r
235                                   ((FLAG) == FLASH_FLAG_BSY))\r
236 /**\r
237   * @}\r
238   */\r
239 \r
240 /** @defgroup FLASH_Program_Parallelism   \r
241   * @{\r
242   */\r
243 #define FLASH_PSIZE_BYTE           ((uint32_t)0x00000000)\r
244 #define FLASH_PSIZE_HALF_WORD      ((uint32_t)0x00000100)\r
245 #define FLASH_PSIZE_WORD           ((uint32_t)0x00000200)\r
246 #define FLASH_PSIZE_DOUBLE_WORD    ((uint32_t)0x00000300)\r
247 #define CR_PSIZE_MASK              ((uint32_t)0xFFFFFCFF)\r
248 /**\r
249   * @}\r
250   */ \r
251 \r
252 /** @defgroup FLASH_Keys \r
253   * @{\r
254   */ \r
255 #define RDP_KEY                  ((uint16_t)0x00A5)\r
256 #define FLASH_KEY1               ((uint32_t)0x45670123)\r
257 #define FLASH_KEY2               ((uint32_t)0xCDEF89AB)\r
258 #define FLASH_OPT_KEY1           ((uint32_t)0x08192A3B)\r
259 #define FLASH_OPT_KEY2           ((uint32_t)0x4C5D6E7F)\r
260 /**\r
261   * @}\r
262   */ \r
263 \r
264 /** \r
265   * @brief   ACR register byte 0 (Bits[8:0]) base address  \r
266   */ \r
267 #define ACR_BYTE0_ADDRESS           ((uint32_t)0x40023C00) \r
268 /** \r
269   * @brief   OPTCR register byte 3 (Bits[24:16]) base address  \r
270   */ \r
271 #define OPTCR_BYTE0_ADDRESS         ((uint32_t)0x40023C14)\r
272 #define OPTCR_BYTE1_ADDRESS         ((uint32_t)0x40023C15)\r
273 #define OPTCR_BYTE2_ADDRESS         ((uint32_t)0x40023C16)\r
274 \r
275 /**\r
276   * @}\r
277   */ \r
278 \r
279 /* Exported macro ------------------------------------------------------------*/\r
280 /* Exported functions --------------------------------------------------------*/ \r
281  \r
282 /* FLASH Interface configuration functions ************************************/\r
283 void FLASH_SetLatency(uint32_t FLASH_Latency);\r
284 void FLASH_PrefetchBufferCmd(FunctionalState NewState);\r
285 void FLASH_InstructionCacheCmd(FunctionalState NewState);\r
286 void FLASH_DataCacheCmd(FunctionalState NewState);\r
287 void FLASH_InstructionCacheReset(void);\r
288 void FLASH_DataCacheReset(void);\r
289 \r
290 /* FLASH Memory Programming functions *****************************************/   \r
291 void FLASH_Unlock(void);\r
292 void FLASH_Lock(void);\r
293 FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);\r
294 FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange);\r
295 FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data);\r
296 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);\r
297 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);\r
298 FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);\r
299 \r
300 /* Option Bytes Programming functions *****************************************/ \r
301 void FLASH_OB_Unlock(void);\r
302 void FLASH_OB_Lock(void);\r
303 void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);\r
304 void FLASH_OB_RDPConfig(uint8_t OB_RDP);\r
305 void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);\r
306 void FLASH_OB_BORConfig(uint8_t OB_BOR);\r
307 FLASH_Status FLASH_OB_Launch(void);\r
308 uint8_t FLASH_OB_GetUser(void);\r
309 uint16_t FLASH_OB_GetWRP(void);\r
310 FlagStatus FLASH_OB_GetRDP(void);\r
311 uint8_t FLASH_OB_GetBOR(void);\r
312 \r
313 /* Interrupts and flags management functions **********************************/\r
314 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);\r
315 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);\r
316 void FLASH_ClearFlag(uint32_t FLASH_FLAG);\r
317 FLASH_Status FLASH_GetStatus(void);\r
318 FLASH_Status FLASH_WaitForLastOperation(void);\r
319 \r
320 #ifdef __cplusplus\r
321 }\r
322 #endif\r
323 \r
324 #endif /* __STM32F4xx_FLASH_H */\r
325 \r
326 /**\r
327   * @}\r
328   */ \r
329 \r
330 /**\r
331   * @}\r
332   */ \r
333 \r
334 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/\r