Statistics
| Branch: | Tag: | Revision:

amiro-blt / Target / Modules / PowerManagement_1-1 / Boot / lib / stdperiphlib / STM32F4xx_StdPeriph_Driver / inc / stm32f4xx_flash.h @ 367c0652

History | View | Annotate | Download (17.65 KB)

1
/**
2
  ******************************************************************************
3
  * @file    stm32f4xx_flash.h
4
  * @author  MCD Application Team
5
  * @version V1.1.0
6
  * @date    11-January-2013
7
  * @brief   This file contains all the functions prototypes for the FLASH 
8
  *          firmware library.
9
  ******************************************************************************
10
  * @attention
11
  *
12
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
13
  *
14
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15
  * You may not use this file except in compliance with the License.
16
  * You may obtain a copy of the License at:
17
  *
18
  *        http://www.st.com/software_license_agreement_liberty_v2
19
  *
20
  * Unless required by applicable law or agreed to in writing, software 
21
  * distributed under the License is distributed on an "AS IS" BASIS, 
22
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
  * See the License for the specific language governing permissions and
24
  * limitations under the License.
25
  *
26
  ******************************************************************************
27
  */
28

    
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

    
40
/** @addtogroup STM32F4xx_StdPeriph_Driver
41
  * @{
42
  */
43

    
44
/** @addtogroup FLASH
45
  * @{
46
  */ 
47

    
48
/* Exported types ------------------------------------------------------------*/
49
/** 
50
  * @brief FLASH Status  
51
  */ 
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
62
}FLASH_Status;
63

    
64
/* Exported constants --------------------------------------------------------*/
65

    
66
/** @defgroup FLASH_Exported_Constants
67
  * @{
68
  */  
69

    
70
/** @defgroup Flash_Latency 
71
  * @{
72
  */ 
73
#define FLASH_Latency_0                ((uint8_t)0x0000)  /*!< FLASH Zero Latency cycle      */
74
#define FLASH_Latency_1                ((uint8_t)0x0001)  /*!< FLASH One Latency cycle       */
75
#define FLASH_Latency_2                ((uint8_t)0x0002)  /*!< FLASH Two Latency cycles      */
76
#define FLASH_Latency_3                ((uint8_t)0x0003)  /*!< FLASH Three Latency cycles    */
77
#define FLASH_Latency_4                ((uint8_t)0x0004)  /*!< FLASH Four Latency cycles     */
78
#define FLASH_Latency_5                ((uint8_t)0x0005)  /*!< FLASH Five Latency cycles     */
79
#define FLASH_Latency_6                ((uint8_t)0x0006)  /*!< FLASH Six Latency cycles      */
80
#define FLASH_Latency_7                ((uint8_t)0x0007)  /*!< FLASH Seven Latency cycles    */
81

    
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

    
91
/**
92
  * @}
93
  */ 
94

    
95
/** @defgroup FLASH_Voltage_Range 
96
  * @{
97
  */ 
98
#define VoltageRange_1        ((uint8_t)0x00)  /*!< Device operating range: 1.8V to 2.1V */
99
#define VoltageRange_2        ((uint8_t)0x01)  /*!<Device operating range: 2.1V to 2.7V */
100
#define VoltageRange_3        ((uint8_t)0x02)  /*!<Device operating range: 2.7V to 3.6V */
101
#define VoltageRange_4        ((uint8_t)0x03)  /*!<Device operating range: 2.7V to 3.6V + External Vpp */
102

    
103
#define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \
104
                               ((RANGE) == VoltageRange_2) || \
105
                               ((RANGE) == VoltageRange_3) || \
106
                               ((RANGE) == VoltageRange_4))                                                                                                               
107
/**
108
  * @}
109
  */ 
110

    
111
/** @defgroup FLASH_Sectors
112
  * @{
113
  */
114
#define FLASH_Sector_0     ((uint16_t)0x0000) /*!< Sector Number 0   */
115
#define FLASH_Sector_1     ((uint16_t)0x0008) /*!< Sector Number 1   */
116
#define FLASH_Sector_2     ((uint16_t)0x0010) /*!< Sector Number 2   */
117
#define FLASH_Sector_3     ((uint16_t)0x0018) /*!< Sector Number 3   */
118
#define FLASH_Sector_4     ((uint16_t)0x0020) /*!< Sector Number 4   */
119
#define FLASH_Sector_5     ((uint16_t)0x0028) /*!< Sector Number 5   */
120
#define FLASH_Sector_6     ((uint16_t)0x0030) /*!< Sector Number 6   */
121
#define FLASH_Sector_7     ((uint16_t)0x0038) /*!< Sector Number 7   */
122
#define FLASH_Sector_8     ((uint16_t)0x0040) /*!< Sector Number 8   */
123
#define FLASH_Sector_9     ((uint16_t)0x0048) /*!< Sector Number 9   */
124
#define FLASH_Sector_10    ((uint16_t)0x0050) /*!< Sector Number 10  */
125
#define FLASH_Sector_11    ((uint16_t)0x0058) /*!< Sector Number 11  */
126
#define FLASH_Sector_12    ((uint16_t)0x0080) /*!< Sector Number 12  */
127
#define FLASH_Sector_13    ((uint16_t)0x0088) /*!< Sector Number 13  */
128
#define FLASH_Sector_14    ((uint16_t)0x0090) /*!< Sector Number 14  */
129
#define FLASH_Sector_15    ((uint16_t)0x0098) /*!< Sector Number 15  */
130
#define FLASH_Sector_16    ((uint16_t)0x00A0) /*!< Sector Number 16  */
131
#define FLASH_Sector_17    ((uint16_t)0x00A8) /*!< Sector Number 17  */
132
#define FLASH_Sector_18    ((uint16_t)0x00B0) /*!< Sector Number 18  */
133
#define FLASH_Sector_19    ((uint16_t)0x00B8) /*!< Sector Number 19  */
134
#define FLASH_Sector_20    ((uint16_t)0x00C0) /*!< Sector Number 20  */
135
#define FLASH_Sector_21    ((uint16_t)0x00C8) /*!< Sector Number 21  */
136
#define FLASH_Sector_22    ((uint16_t)0x00D0) /*!< Sector Number 22  */
137
#define FLASH_Sector_23    ((uint16_t)0x00D8) /*!< Sector Number 23  */
138

    
139
#define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0)   || ((SECTOR) == FLASH_Sector_1)   ||\
140
                                 ((SECTOR) == FLASH_Sector_2)   || ((SECTOR) == FLASH_Sector_3)   ||\
141
                                 ((SECTOR) == FLASH_Sector_4)   || ((SECTOR) == FLASH_Sector_5)   ||\
142
                                 ((SECTOR) == FLASH_Sector_6)   || ((SECTOR) == FLASH_Sector_7)   ||\
143
                                 ((SECTOR) == FLASH_Sector_8)   || ((SECTOR) == FLASH_Sector_9)   ||\
144
                                 ((SECTOR) == FLASH_Sector_10)  || ((SECTOR) == FLASH_Sector_11)  ||\
145
                                 ((SECTOR) == FLASH_Sector_12)  || ((SECTOR) == FLASH_Sector_13)  ||\
146
                                 ((SECTOR) == FLASH_Sector_14)  || ((SECTOR) == FLASH_Sector_15)  ||\
147
                                 ((SECTOR) == FLASH_Sector_16)  || ((SECTOR) == FLASH_Sector_17)  ||\
148
                                 ((SECTOR) == FLASH_Sector_18)  || ((SECTOR) == FLASH_Sector_19)  ||\
149
                                 ((SECTOR) == FLASH_Sector_20)  || ((SECTOR) == FLASH_Sector_21)  ||\
150
                                 ((SECTOR) == FLASH_Sector_22)  || ((SECTOR) == FLASH_Sector_23))
151

    
152
#define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x081FFFFF)) ||\
153
                                   (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))  
154
/**
155
  * @}
156
  */ 
157

    
158
/** @defgroup Option_Bytes_Write_Protection 
159
  * @{
160
  */ 
161
#define OB_WRP_Sector_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0     */
162
#define OB_WRP_Sector_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1     */
163
#define OB_WRP_Sector_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2     */
164
#define OB_WRP_Sector_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3     */
165
#define OB_WRP_Sector_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4     */
166
#define OB_WRP_Sector_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5     */
167
#define OB_WRP_Sector_6       ((uint32_t)0x00000040) /*!< Write protection of Sector6     */
168
#define OB_WRP_Sector_7       ((uint32_t)0x00000080) /*!< Write protection of Sector7     */
169
#define OB_WRP_Sector_8       ((uint32_t)0x00000100) /*!< Write protection of Sector8     */
170
#define OB_WRP_Sector_9       ((uint32_t)0x00000200) /*!< Write protection of Sector9     */
171
#define OB_WRP_Sector_10      ((uint32_t)0x00000400) /*!< Write protection of Sector10    */
172
#define OB_WRP_Sector_11      ((uint32_t)0x00000800) /*!< Write protection of Sector11    */
173
#define OB_WRP_Sector_12      ((uint32_t)0x00000001) /*!< Write protection of Sector12    */
174
#define OB_WRP_Sector_13      ((uint32_t)0x00000002) /*!< Write protection of Sector13    */
175
#define OB_WRP_Sector_14      ((uint32_t)0x00000004) /*!< Write protection of Sector14    */
176
#define OB_WRP_Sector_15      ((uint32_t)0x00000008) /*!< Write protection of Sector15    */
177
#define OB_WRP_Sector_16      ((uint32_t)0x00000010) /*!< Write protection of Sector16    */
178
#define OB_WRP_Sector_17      ((uint32_t)0x00000020) /*!< Write protection of Sector17    */
179
#define OB_WRP_Sector_18      ((uint32_t)0x00000040) /*!< Write protection of Sector18    */
180
#define OB_WRP_Sector_19      ((uint32_t)0x00000080) /*!< Write protection of Sector19    */
181
#define OB_WRP_Sector_20      ((uint32_t)0x00000100) /*!< Write protection of Sector20    */
182
#define OB_WRP_Sector_21      ((uint32_t)0x00000200) /*!< Write protection of Sector21    */
183
#define OB_WRP_Sector_22      ((uint32_t)0x00000400) /*!< Write protection of Sector22    */
184
#define OB_WRP_Sector_23      ((uint32_t)0x00000800) /*!< Write protection of Sector23    */
185
#define OB_WRP_Sector_All     ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */
186

    
187
#define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
188
/**
189
  * @}
190
  */
191

    
192
/** @defgroup FLASH_Option_Bytes_Read_Protection 
193
  * @{
194
  */
195
#define OB_RDP_Level_0   ((uint8_t)0xAA)
196
#define OB_RDP_Level_1   ((uint8_t)0x55)
197
/*#define OB_RDP_Level_2   ((uint8_t)0xCC)*/ /*!< Warning: When enabling read protection level 2 
198
                                                  it's no more possible to go back to level 1 or 0 */
199
#define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
200
                          ((LEVEL) == OB_RDP_Level_1))/*||\
201
                          ((LEVEL) == OB_RDP_Level_2))*/
202
/**
203
  * @}
204
  */ 
205

    
206
/** @defgroup FLASH_Option_Bytes_IWatchdog 
207
  * @{
208
  */ 
209
#define OB_IWDG_SW                     ((uint8_t)0x20)  /*!< Software IWDG selected */
210
#define OB_IWDG_HW                     ((uint8_t)0x00)  /*!< Hardware IWDG selected */
211
#define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
212
/**
213
  * @}
214
  */ 
215

    
216
/** @defgroup FLASH_Option_Bytes_nRST_STOP 
217
  * @{
218
  */ 
219
#define OB_STOP_NoRST                  ((uint8_t)0x40) /*!< No reset generated when entering in STOP */
220
#define OB_STOP_RST                    ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
221
#define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
222
/**
223
  * @}
224
  */ 
225

    
226

    
227
/** @defgroup FLASH_Option_Bytes_nRST_STDBY 
228
  * @{
229
  */ 
230
#define OB_STDBY_NoRST                 ((uint8_t)0x80) /*!< No reset generated when entering in STANDBY */
231
#define OB_STDBY_RST                   ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
232
#define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
233
/**
234
  * @}
235
  */
236
  
237
/** @defgroup FLASH_BOR_Reset_Level 
238
  * @{
239
  */  
240
#define OB_BOR_LEVEL3          ((uint8_t)0x00)  /*!< Supply voltage ranges from 2.70 to 3.60 V */
241
#define OB_BOR_LEVEL2          ((uint8_t)0x04)  /*!< Supply voltage ranges from 2.40 to 2.70 V */
242
#define OB_BOR_LEVEL1          ((uint8_t)0x08)  /*!< Supply voltage ranges from 2.10 to 2.40 V */
243
#define OB_BOR_OFF             ((uint8_t)0x0C)  /*!< Supply voltage ranges from 1.62 to 2.10 V */
244
#define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
245
                          ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
246
/**
247
  * @}
248
  */
249

    
250
/** @defgroup FLASH_Interrupts 
251
  * @{
252
  */ 
253
#define FLASH_IT_EOP                   ((uint32_t)0x01000000)  /*!< End of FLASH Operation Interrupt source */
254
#define FLASH_IT_ERR                   ((uint32_t)0x02000000)  /*!< Error Interrupt source */
255
#define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))
256
/**
257
  * @}
258
  */ 
259

    
260
/** @defgroup FLASH_Flags 
261
  * @{
262
  */ 
263
#define FLASH_FLAG_EOP                 ((uint32_t)0x00000001)  /*!< FLASH End of Operation flag               */
264
#define FLASH_FLAG_OPERR               ((uint32_t)0x00000002)  /*!< FLASH operation Error flag                */
265
#define FLASH_FLAG_WRPERR              ((uint32_t)0x00000010)  /*!< FLASH Write protected error flag          */
266
#define FLASH_FLAG_PGAERR              ((uint32_t)0x00000020)  /*!< FLASH Programming Alignment error flag    */
267
#define FLASH_FLAG_PGPERR              ((uint32_t)0x00000040)  /*!< FLASH Programming Parallelism error flag  */
268
#define FLASH_FLAG_PGSERR              ((uint32_t)0x00000080)  /*!< FLASH Programming Sequence error flag     */
269
#define FLASH_FLAG_BSY                 ((uint32_t)0x00010000)  /*!< FLASH Busy flag                           */ 
270
#define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFE0C) == 0x00000000) && ((FLAG) != 0x00000000))
271
#define IS_FLASH_GET_FLAG(FLAG)  (((FLAG) == FLASH_FLAG_EOP)    || ((FLAG) == FLASH_FLAG_OPERR)  || \
272
                                  ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \
273
                                  ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \
274
                                  ((FLAG) == FLASH_FLAG_BSY))
275
/**
276
  * @}
277
  */
278

    
279
/** @defgroup FLASH_Program_Parallelism   
280
  * @{
281
  */
282
#define FLASH_PSIZE_BYTE           ((uint32_t)0x00000000)
283
#define FLASH_PSIZE_HALF_WORD      ((uint32_t)0x00000100)
284
#define FLASH_PSIZE_WORD           ((uint32_t)0x00000200)
285
#define FLASH_PSIZE_DOUBLE_WORD    ((uint32_t)0x00000300)
286
#define CR_PSIZE_MASK              ((uint32_t)0xFFFFFCFF)
287
/**
288
  * @}
289
  */ 
290

    
291
/** @defgroup FLASH_Keys 
292
  * @{
293
  */ 
294
#define RDP_KEY                  ((uint16_t)0x00A5)
295
#define FLASH_KEY1               ((uint32_t)0x45670123)
296
#define FLASH_KEY2               ((uint32_t)0xCDEF89AB)
297
#define FLASH_OPT_KEY1           ((uint32_t)0x08192A3B)
298
#define FLASH_OPT_KEY2           ((uint32_t)0x4C5D6E7F)
299
/**
300
  * @}
301
  */ 
302

    
303
/** 
304
  * @brief   ACR register byte 0 (Bits[7:0]) base address  
305
  */ 
306
#define ACR_BYTE0_ADDRESS           ((uint32_t)0x40023C00) 
307
/** 
308
  * @brief   OPTCR register byte 0 (Bits[7:0]) base address  
309
  */ 
310
#define OPTCR_BYTE0_ADDRESS         ((uint32_t)0x40023C14)
311
/** 
312
  * @brief   OPTCR register byte 1 (Bits[15:8]) base address  
313
  */ 
314
#define OPTCR_BYTE1_ADDRESS         ((uint32_t)0x40023C15)
315
/** 
316
  * @brief   OPTCR register byte 2 (Bits[23:16]) base address  
317
  */ 
318
#define OPTCR_BYTE2_ADDRESS         ((uint32_t)0x40023C16)
319
/** 
320
  * @brief   OPTCR register byte 3 (Bits[31:24]) base address  
321
  */ 
322
#define OPTCR_BYTE3_ADDRESS         ((uint32_t)0x40023C17)
323

    
324
/** 
325
  * @brief   OPTCR1 register byte 0 (Bits[7:0]) base address  
326
  */ 
327
#define OPTCR1_BYTE2_ADDRESS         ((uint32_t)0x40023C1A)
328

    
329
/**
330
  * @}
331
  */ 
332

    
333
/* Exported macro ------------------------------------------------------------*/
334
/* Exported functions --------------------------------------------------------*/ 
335
 
336
/* FLASH Interface configuration functions ************************************/
337
void FLASH_SetLatency(uint32_t FLASH_Latency);
338
void FLASH_PrefetchBufferCmd(FunctionalState NewState);
339
void FLASH_InstructionCacheCmd(FunctionalState NewState);
340
void FLASH_DataCacheCmd(FunctionalState NewState);
341
void FLASH_InstructionCacheReset(void);
342
void FLASH_DataCacheReset(void);
343

    
344
/* FLASH Memory Programming functions *****************************************/   
345
void         FLASH_Unlock(void);
346
void         FLASH_Lock(void);
347
FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);
348
FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange);
349
FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data);
350
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
351
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
352
FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);
353

    
354
/* Option Bytes Programming functions *****************************************/ 
355
void          FLASH_OB_Unlock(void);
356
void         FLASH_OB_Lock(void);
357
void         FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
358
void         FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState);
359
void         FLASH_OB_RDPConfig(uint8_t OB_RDP);
360
void         FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
361
void         FLASH_OB_BORConfig(uint8_t OB_BOR);
362
FLASH_Status FLASH_OB_Launch(void);
363
uint8_t      FLASH_OB_GetUser(void);
364
uint16_t     FLASH_OB_GetWRP(void);
365
uint16_t     FLASH_OB_GetWRP1(void);
366
FlagStatus   FLASH_OB_GetRDP(void);
367
uint8_t      FLASH_OB_GetBOR(void);
368

    
369
/* Interrupts and flags management functions **********************************/
370
void         FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
371
FlagStatus   FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
372
void         FLASH_ClearFlag(uint32_t FLASH_FLAG);
373
FLASH_Status FLASH_GetStatus(void);
374
FLASH_Status FLASH_WaitForLastOperation(void);
375

    
376
#ifdef __cplusplus
377
}
378
#endif
379

    
380
#endif /* __STM32F4xx_FLASH_H */
381

    
382
/**
383
  * @}
384
  */ 
385

    
386
/**
387
  * @}
388
  */ 
389

    
390
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/