]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_flash.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_flash.h
1 /**
2 ******************************************************************************
3 * @file stm32f30x_flash.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 27-February-2014
7 * @brief This file contains all the functions prototypes for the FLASH
8 * firmware library.
9 ******************************************************************************
10 * @attention
11 *
12 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 *
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 ******************************************************************************
37 */
38
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32F30x_FLASH_H
41 #define __STM32F30x_FLASH_H
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32f30x.h"
49
50 /** @addtogroup STM32F30x_StdPeriph_Driver
51 * @{
52 */
53
54 /** @addtogroup FLASH
55 * @{
56 */
57
58 /* Exported types ------------------------------------------------------------*/
59 /**
60 * @brief FLASH Status
61 */
62 typedef enum
63 {
64 FLASH_BUSY = 1,
65 FLASH_ERROR_WRP,
66 FLASH_ERROR_PROGRAM,
67 FLASH_COMPLETE,
68 FLASH_TIMEOUT
69 }FLASH_Status;
70
71 /* Exported constants --------------------------------------------------------*/
72
73 /** @defgroup FLASH_Exported_Constants
74 * @{
75 */
76
77 /** @defgroup Flash_Latency
78 * @{
79 */
80 #define FLASH_Latency_0 ((uint8_t)0x0000) /*!< FLASH Zero Latency cycle */
81 #define FLASH_Latency_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */
82 #define FLASH_Latency_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */
83
84 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
85 ((LATENCY) == FLASH_Latency_1) || \
86 ((LATENCY) == FLASH_Latency_2))
87 /**
88 * @}
89 */
90
91 /** @defgroup FLASH_Interrupts
92 * @{
93 */
94
95 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of programming interrupt source */
96 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error interrupt source */
97 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
98 /**
99 * @}
100 */
101 /** @defgroup FLASH_Address
102 * @{
103 */
104
105 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0803FFFF))
106
107 /**
108 * @}
109 */
110
111 /** @defgroup FLASH_OB_DATA_ADDRESS
112 * @{
113 */
114 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
115
116 /**
117 * @}
118 */
119
120 /** @defgroup Option_Bytes_Write_Protection
121 * @{
122 */
123
124 #define OB_WRP_Pages0to1 ((uint32_t)0x00000001) /* Write protection of page 0 to 1 */
125 #define OB_WRP_Pages2to3 ((uint32_t)0x00000002) /* Write protection of page 2 to 3 */
126 #define OB_WRP_Pages4to5 ((uint32_t)0x00000004) /* Write protection of page 4 to 5 */
127 #define OB_WRP_Pages6to7 ((uint32_t)0x00000008) /* Write protection of page 6 to 7 */
128 #define OB_WRP_Pages8to9 ((uint32_t)0x00000010) /* Write protection of page 8 to 9 */
129 #define OB_WRP_Pages10to11 ((uint32_t)0x00000020) /* Write protection of page 10 to 11 */
130 #define OB_WRP_Pages12to13 ((uint32_t)0x00000040) /* Write protection of page 12 to 13 */
131 #define OB_WRP_Pages14to15 ((uint32_t)0x00000080) /* Write protection of page 14 to 15 */
132 #define OB_WRP_Pages16to17 ((uint32_t)0x00000100) /* Write protection of page 16 to 17 */
133 #define OB_WRP_Pages18to19 ((uint32_t)0x00000200) /* Write protection of page 18 to 19 */
134 #define OB_WRP_Pages20to21 ((uint32_t)0x00000400) /* Write protection of page 20 to 21 */
135 #define OB_WRP_Pages22to23 ((uint32_t)0x00000800) /* Write protection of page 22 to 23 */
136 #define OB_WRP_Pages24to25 ((uint32_t)0x00001000) /* Write protection of page 24 to 25 */
137 #define OB_WRP_Pages26to27 ((uint32_t)0x00002000) /* Write protection of page 26 to 27 */
138 #define OB_WRP_Pages28to29 ((uint32_t)0x00004000) /* Write protection of page 28 to 29 */
139 #define OB_WRP_Pages30to31 ((uint32_t)0x00008000) /* Write protection of page 30 to 31 */
140 #define OB_WRP_Pages32to33 ((uint32_t)0x00010000) /* Write protection of page 32 to 33 */
141 #define OB_WRP_Pages34to35 ((uint32_t)0x00020000) /* Write protection of page 34 to 35 */
142 #define OB_WRP_Pages36to37 ((uint32_t)0x00040000) /* Write protection of page 36 to 37 */
143 #define OB_WRP_Pages38to39 ((uint32_t)0x00080000) /* Write protection of page 38 to 39 */
144 #define OB_WRP_Pages40to41 ((uint32_t)0x00100000) /* Write protection of page 40 to 41 */
145 #define OB_WRP_Pages42to43 ((uint32_t)0x00200000) /* Write protection of page 42 to 43 */
146 #define OB_WRP_Pages44to45 ((uint32_t)0x00400000) /* Write protection of page 44 to 45 */
147 #define OB_WRP_Pages46to47 ((uint32_t)0x00800000) /* Write protection of page 46 to 47 */
148 #define OB_WRP_Pages48to49 ((uint32_t)0x01000000) /* Write protection of page 48 to 49 */
149 #define OB_WRP_Pages50to51 ((uint32_t)0x02000000) /* Write protection of page 50 to 51 */
150 #define OB_WRP_Pages52to53 ((uint32_t)0x04000000) /* Write protection of page 52 to 53 */
151 #define OB_WRP_Pages54to55 ((uint32_t)0x08000000) /* Write protection of page 54 to 55 */
152 #define OB_WRP_Pages56to57 ((uint32_t)0x10000000) /* Write protection of page 56 to 57 */
153 #define OB_WRP_Pages58to59 ((uint32_t)0x20000000) /* Write protection of page 58 to 59 */
154 #define OB_WRP_Pages60to61 ((uint32_t)0x40000000) /* Write protection of page 60 to 61 */
155 #define OB_WRP_Pages62to127 ((uint32_t)0x80000000) /* Write protection of page 62 to 127 */
156
157 #define OB_WRP_AllPages ((uint32_t)0xFFFFFFFF) /*!< Write protection of all Sectors */
158
159 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
160
161 /**
162 * @}
163 */
164
165 /** @defgroup Option_Bytes_Read_Protection
166 * @{
167 */
168
169 /**
170 * @brief Read Protection Level
171 */
172 #define OB_RDP_Level_0 ((uint8_t)0xAA)
173 #define OB_RDP_Level_1 ((uint8_t)0xBB)
174 /*#define OB_RDP_Level_2 ((uint8_t)0xCC)*/ /* Warning: When enabling read protection level 2
175 it's no more possible to go back to level 1 or 0 */
176
177 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
178 ((LEVEL) == OB_RDP_Level_1))/*||\
179 ((LEVEL) == OB_RDP_Level_2))*/
180 /**
181 * @}
182 */
183
184 /** @defgroup Option_Bytes_IWatchdog
185 * @{
186 */
187
188 #define OB_IWDG_SW ((uint8_t)0x01) /*!< Software IWDG selected */
189 #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware IWDG selected */
190 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
191
192 /**
193 * @}
194 */
195
196 /** @defgroup Option_Bytes_nRST_STOP
197 * @{
198 */
199
200 #define OB_STOP_NoRST ((uint8_t)0x02) /*!< No reset generated when entering in STOP */
201 #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
202 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
203
204 /**
205 * @}
206 */
207
208 /** @defgroup Option_Bytes_nRST_STDBY
209 * @{
210 */
211
212 #define OB_STDBY_NoRST ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */
213 #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
214 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
215
216 /**
217 * @}
218 */
219 /** @defgroup Option_Bytes_BOOT1
220 * @{
221 */
222
223 #define OB_BOOT1_RESET ((uint8_t)0x00) /*!< BOOT1 Reset */
224 #define OB_BOOT1_SET ((uint8_t)0x10) /*!< BOOT1 Set */
225 #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
226
227 /**
228 * @}
229 */
230 /** @defgroup Option_Bytes_VDDA_Analog_Monitoring
231 * @{
232 */
233
234 #define OB_VDDA_ANALOG_ON ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source ON */
235 #define OB_VDDA_ANALOG_OFF ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */
236
237 #define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
238
239 /**
240 * @}
241 */
242
243 /** @defgroup FLASH_Option_Bytes_SRAM_Parity_Enable
244 * @{
245 */
246
247 #define OB_SRAM_PARITY_SET ((uint8_t)0x00) /*!< SRAM parity enable Set */
248 #define OB_SRAM_PARITY_RESET ((uint8_t)0x40) /*!< SRAM parity enable reset */
249
250 #define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_SRAM_PARITY_SET) || ((PARITY) == OB_SRAM_PARITY_RESET))
251
252 /**
253 * @}
254 */
255
256 /** @defgroup FLASH_Flags
257 * @{
258 */
259
260 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
261 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
262 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
263 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */
264
265 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFCB) == 0x00000000) && ((FLAG) != 0x00000000))
266
267 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_PGERR) || \
268 ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_EOP))
269 /**
270 * @}
271 */
272 /** @defgroup Timeout_definition
273 * @{
274 */
275 #define FLASH_ER_PRG_TIMEOUT ((uint32_t)0x000B0000)
276
277 /**
278 * @}
279 */
280
281 /**
282 * @}
283 */
284
285 /* Exported macro ------------------------------------------------------------*/
286 /* Exported functions --------------------------------------------------------*/
287
288 /* FLASH Interface configuration functions ************************************/
289 void FLASH_SetLatency(uint32_t FLASH_Latency);
290 void FLASH_HalfCycleAccessCmd(FunctionalState NewState);
291 void FLASH_PrefetchBufferCmd(FunctionalState NewState);
292
293 /* FLASH Memory Programming functions *****************************************/
294 void FLASH_Unlock(void);
295 void FLASH_Lock(void);
296 FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
297 FLASH_Status FLASH_EraseAllPages(void);
298 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
299 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
300
301 /* Option Bytes Programming functions *****************************************/
302 void FLASH_OB_Unlock(void);
303 void FLASH_OB_Lock(void);
304 void FLASH_OB_Launch(void);
305 FLASH_Status FLASH_OB_Erase(void);
306 FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP);
307 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
308 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
309 FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1);
310 FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG);
311 FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity);
312 FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER);
313 FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
314 uint8_t FLASH_OB_GetUser(void);
315 uint32_t FLASH_OB_GetWRP(void);
316 FlagStatus FLASH_OB_GetRDP(void);
317
318 /* Interrupts and flags management functions **********************************/
319 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
320 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
321 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
322 FLASH_Status FLASH_GetStatus(void);
323 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
324
325 #ifdef __cplusplus
326 }
327 #endif
328
329 #endif /* __STM32F30x_FLASH_H */
330
331 /**
332 * @}
333 */
334
335 /**
336 * @}
337 */
338
339 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum