]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_flash.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_flash.h
1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_flash.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    11-December-2014
7   * @brief   Header file of Flash HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************  
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F0xx_HAL_FLASH_H
40 #define __STM32F0xx_HAL_FLASH_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
48
49 /** @addtogroup STM32F0xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup FLASH
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/ 
58
59 /** @defgroup FLASH_Exported_Types FLASH Exported Types
60   * @{
61   */  
62
63 /**
64   * @brief  FLASH Erase structure definition
65   */
66 typedef struct
67 {
68   uint32_t TypeErase;   /*!< TypeErase: Mass erase or page erase.
69                              This parameter can be a value of @ref FLASH_Type_Erase */
70
71   uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled
72                              This parameter must be a value of @ref FLASHEx_Address */
73   
74   uint32_t NbPages;     /*!< NbPages: Number of pagess to be erased.
75                              This parameter must be a value between 1 and (max number of pages - value of initial page)*/           
76                                                           
77 } FLASH_EraseInitTypeDef;
78
79 /**
80   * @brief  FLASH Options bytes program structure definition
81   */
82 typedef struct
83 {
84   uint32_t OptionType;  /*!< OptionType: Option byte to be configured.
85                              This parameter can be a value of @ref FLASH_OB_Type */
86
87   uint32_t WRPState;    /*!< WRPState: Write protection activation or deactivation.
88                              This parameter can be a value of @ref FLASH_OB_WRP_State */
89
90   uint32_t WRPPage;     /*!< WRPSector: specifies the page(s) to be write protected
91                              This parameter can be a value of @ref FLASHEx_OB_Write_Protection */
92
93   uint8_t RDPLevel;     /*!< RDPLevel: Set the read protection level..
94                              This parameter can be a value of @ref FLASH_OB_Read_Protection */
95
96   uint8_t USERConfig;   /*!< USERConfig: Program the FLASH User Option Byte: 
97                              IWDG / STOP / STDBY / BOOT1 / VDDA_ANALOG / SRAM_PARITY
98                              This parameter can be a combination of @ref FLASH_OB_Watchdog, @ref FLASH_OB_nRST_STOP,
99                              @ref FLASH_OB_nRST_STDBY, @ref FLASH_OB_BOOT1, @ref FLASH_OB_VDDA_Analog_Monitoring and
100                              @ref FLASH_OB_RAM_Parity_Check_Enable */
101
102   uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be prgrammed
103                              This parameter can be a value of @ref FLASH_OB_Data_Address */
104   
105   uint8_t DATAData;     /*!< DATAData: Data to be stored in the option byte DATA
106                              This parameter can have any value */
107   
108 } FLASH_OBProgramInitTypeDef;
109
110 /**
111   * @brief  FLASH Procedure structure definition
112   */
113 typedef enum 
114 {
115   FLASH_PROC_NONE              = 0, 
116   FLASH_PROC_PAGEERASE         = 1,
117   FLASH_PROC_MASSERASE         = 2,
118   FLASH_PROC_PROGRAMHALFWORD   = 3,
119   FLASH_PROC_PROGRAMWORD       = 4,
120   FLASH_PROC_PROGRAMDOUBLEWORD = 5
121 } FLASH_ProcedureTypeDef;
122
123 /** 
124   * @brief  FLASH handle Structure definition  
125   */
126 typedef struct
127 {
128   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
129   
130   __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
131   
132   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
133   
134   __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
135
136   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
137
138   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
139                                                      This parameter can be a value of @ref FLASH_Error  */
140
141 } FLASH_ProcessTypeDef;
142
143 /**
144   * @}
145   */
146
147 /* Exported constants --------------------------------------------------------*/
148
149 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
150   * @{
151   */  
152
153 /** @defgroup FLASH_Error FLASH Error
154   * @{
155   */ 
156 #define FLASH_ERROR_NONE      ((uint32_t)0x00000000)
157 #define FLASH_ERROR_PG        ((uint32_t)0x00000001)
158 #define FLASH_ERROR_WRP       ((uint32_t)0x00000002)
159 /**
160   * @}
161   */
162
163 /** @defgroup FLASH_Type_Erase FLASH Type Erase
164   * @{
165   */ 
166 #define TYPEERASE_PAGES     ((uint32_t)0x00)  /*!<Pages erase only*/
167 #define TYPEERASE_MASSERASE ((uint32_t)0x01)  /*!<Flash mass erase activation*/
168
169 #define IS_TYPEERASE(VALUE) (((VALUE) == TYPEERASE_PAGES) || \
170                              ((VALUE) == TYPEERASE_MASSERASE))  
171 /**
172   * @}
173   */
174
175 /** @defgroup FLASH_Type_Program FLASH Type Program
176   * @{
177   */ 
178 #define TYPEPROGRAM_HALFWORD   ((uint32_t)0x01)  /*!<Program a half-word (16-bit) at a specified address.*/
179 #define TYPEPROGRAM_WORD       ((uint32_t)0x02)  /*!<Program a word (32-bit) at a specified address.*/
180 #define TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03)  /*!<Program a double word (64-bit) at a specified address*/
181
182 #define IS_TYPEPROGRAM(VALUE)  (((VALUE) == TYPEPROGRAM_HALFWORD) || \
183                                 ((VALUE) == TYPEPROGRAM_WORD)     || \
184                                 ((VALUE) == TYPEPROGRAM_DOUBLEWORD))  
185 /**
186   * @}
187   */
188
189 /** @defgroup FLASH_OB_WRP_State FLASH WRP State
190   * @{
191   */ 
192 #define WRPSTATE_DISABLE   ((uint32_t)0x00)  /*!<Disable the write protection of the desired pages*/
193 #define WRPSTATE_ENABLE    ((uint32_t)0x01)  /*!<Enable the write protection of the desired pagess*/
194
195 #define IS_WRPSTATE(VALUE) (((VALUE) == WRPSTATE_DISABLE) || \
196                             ((VALUE) == WRPSTATE_ENABLE))  
197 /**
198   * @}
199   */
200
201 /** @defgroup FLASH_OB_Type FLASH Option Bytes Type
202   * @{
203   */
204 #define OPTIONBYTE_WRP       ((uint32_t)0x01)  /*!<WRP option byte configuration*/
205 #define OPTIONBYTE_RDP       ((uint32_t)0x02)  /*!<RDP option byte configuration*/
206 #define OPTIONBYTE_USER      ((uint32_t)0x04)  /*!<USER option byte configuration*/
207 #define OPTIONBYTE_DATA      ((uint32_t)0x08)  /*!<DATA option byte configuration*/
208
209 #define IS_OPTIONBYTE(VALUE) ((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA))
210 /**
211   * @}
212   */
213
214 /** @defgroup FLASH_Latency FLASH Latency
215   * @{
216   */ 
217 #define FLASH_LATENCY_0            ((uint32_t)0x00000000)    /*!< FLASH Zero Latency cycle */
218 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY         /*!< FLASH One Latency cycle */
219
220 #define IS_FLASH_LATENCY(LATENCY)  (((LATENCY) == FLASH_LATENCY_0) || \
221                                     ((LATENCY) == FLASH_LATENCY_1))
222 /**
223   * @}
224   */ 
225   
226 /** @defgroup FLASH_OB_Data_Address FLASH OB Data Address
227   * @{
228   */  
229 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806)) 
230 /**
231   * @}
232   */
233
234 /** @defgroup FLASH_OB_Read_Protection FLASH OB Read Protection
235   * @{
236   */
237 #define OB_RDP_LEVEL_0             ((uint8_t)0xAA)
238 #define OB_RDP_LEVEL_1             ((uint8_t)0xBB)
239 #define OB_RDP_LEVEL_2             ((uint8_t)0xCC) /*!< Warning: When enabling read protection level 2 
240                                                       it's no more possible to go back to level 1 or 0 */
241 #define IS_OB_RDP_LEVEL(LEVEL)     (((LEVEL) == OB_RDP_LEVEL_0)   ||\
242                                     ((LEVEL) == OB_RDP_LEVEL_1))/*||\
243                                     ((LEVEL) == OB_RDP_LEVEL_2))*/
244 /**
245   * @}
246   */ 
247   
248 /** @defgroup FLASH_OB_Watchdog FLASH OB Watchdog
249   * @{
250   */ 
251 #define OB_WDG_SW                 ((uint8_t)0x01)  /*!< Software WDG selected */
252 #define OB_WDG_HW                 ((uint8_t)0x00)  /*!< Hardware WDG selected */
253 #define IS_OB_WDG_SOURCE(SOURCE)  (((SOURCE) == OB_WDG_SW) || ((SOURCE) == OB_WDG_HW))
254 /**
255   * @}
256   */ 
257   
258 /** @defgroup FLASH_OB_nRST_STOP FLASH OB nRST STOP
259   * @{
260   */ 
261 #define OB_STOP_NO_RST             ((uint8_t)0x02) /*!< No reset generated when entering in STOP */
262 #define OB_STOP_RST                ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
263 #define IS_OB_STOP_SOURCE(SOURCE)  (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
264 /**
265   * @}
266   */ 
267
268 /** @defgroup FLASH_OB_nRST_STDBY FLASH OB nRST STDBY 
269   * @{
270   */ 
271 #define OB_STDBY_NO_RST            ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */
272 #define OB_STDBY_RST               ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
273 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
274 /**
275   * @}
276   */    
277
278 /** @defgroup FLASH_OB_BOOT1 FLASH OB BOOT1
279   * @{
280   */
281 #define OB_BOOT1_RESET             ((uint8_t)0x00) /*!< BOOT1 Reset */
282 #define OB_BOOT1_SET               ((uint8_t)0x10) /*!< BOOT1 Set */
283 #define IS_OB_BOOT1(BOOT1)         (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
284 /**
285   * @}
286   */  
287
288 /** @defgroup FLASH_OB_VDDA_Analog_Monitoring FLASH OB VDDA Analog Monitoring
289   * @{
290   */
291 #define OB_VDDA_ANALOG_ON          ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source ON */
292 #define OB_VDDA_ANALOG_OFF         ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */
293 #define IS_OB_VDDA_ANALOG(ANALOG)  (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
294 /**
295   * @}
296   */ 
297
298 /** @defgroup FLASH_OB_RAM_Parity_Check_Enable FLASH OB RAM Parity Check Enable
299   * @{
300   */
301 #define OB_RAM_PARITY_CHECK_SET    ((uint8_t)0x00) /*!< RAM parity check enable set */
302 #define OB_RAM_PARITY_CHECK_RESET  ((uint8_t)0x40) /*!< RAM parity check enable reset */
303 #define IS_OB_SRAM_PARITY(PARITY)  (((PARITY) == OB_RAM_PARITY_CHECK_SET) || ((PARITY) == OB_RAM_PARITY_CHECK_RESET))
304 /**
305   * @}
306   */ 
307
308 /** @defgroup FLASH_Flag_definition FLASH Flag definition
309   * @{
310   */ 
311 #define FLASH_FLAG_BSY             FLASH_SR_BSY            /*!< FLASH Busy flag                           */ 
312 #define FLASH_FLAG_PGERR           FLASH_SR_PGERR          /*!< FLASH Programming error flag    */
313 #define FLASH_FLAG_WRPERR          FLASH_SR_WRPERR         /*!< FLASH Write protected error flag          */
314 #define FLASH_FLAG_EOP             FLASH_SR_EOP            /*!< FLASH End of Operation flag               */
315 /**
316   * @}
317   */
318   
319 /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
320   * @{
321   */ 
322 #define FLASH_IT_EOP               FLASH_CR_EOPIE          /*!< End of FLASH Operation Interrupt source */
323 #define FLASH_IT_ERR               FLASH_CR_ERRIE  /*!< Error Interrupt source */
324 /**
325   * @}
326   */  
327
328 /** @defgroup FLASH_Timeout_definition  FLASH Timeout definition
329   * @brief FLASH Timeout definition
330   * @{
331   */ 
332 #define HAL_FLASH_TIMEOUT_VALUE   ((uint32_t)50000)/* 50 s */
333 /**
334   * @}
335   */  
336
337 /**
338   * @}
339   */  
340   
341 /* Exported macro ------------------------------------------------------------*/
342
343 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
344  *  @brief macros to control FLASH features 
345  *  @{
346  */
347
348 /** @defgroup FLASH_Latency FLASH Latency
349  *  @brief macros to handle FLASH Latency
350  * @{
351  */ 
352   
353 /**
354   * @brief  Set the FLASH Latency.
355   * @param  __LATENCY__: FLASH Latency                   
356   *         The value of this parameter depend on device used within the same series
357   * @retval None
358   */ 
359 #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
360 /**
361   * @}
362   */
363
364 /** @defgroup FLASH_Prefetch FLASH Prefetch
365  *  @brief macros to handle FLASH Prefetch buffer
366  * @{
367  */   
368 /**
369   * @brief  Enable the FLASH prefetch buffer.
370   * @retval None
371   */ 
372 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
373
374 /**
375   * @brief  Disable the FLASH prefetch buffer.
376   * @retval None
377   */
378 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
379
380 /**
381   * @}
382   */
383
384 /** @defgroup FLASH_Interrupt FLASH Interrupt
385  *  @brief macros to handle FLASH interrupts
386  * @{
387  */ 
388
389 /**
390   * @brief  Enable the specified FLASH interrupt.
391   * @param  __INTERRUPT__ : FLASH interrupt 
392   *         This parameter can be any combination of the following values:
393   *     @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
394   *     @arg FLASH_IT_ERR: Error Interrupt    
395   * @retval none
396   */  
397 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)  (FLASH->CR |= (__INTERRUPT__))
398
399 /**
400   * @brief  Disable the specified FLASH interrupt.
401   * @param  __INTERRUPT__ : FLASH interrupt 
402   *         This parameter can be any combination of the following values:
403   *     @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
404   *     @arg FLASH_IT_ERR: Error Interrupt    
405   * @retval none
406   */  
407 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)  (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
408
409 /**
410   * @brief  Get the specified FLASH flag status. 
411   * @param  __FLAG__: specifies the FLASH flag to check.
412   *          This parameter can be one of the following values:
413   *            @arg FLASH_FLAG_EOP   : FLASH End of Operation flag 
414   *            @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag 
415   *            @arg FLASH_FLAG_PGERR : FLASH Programming error flag
416   *            @arg FLASH_FLAG_BSY   : FLASH Busy flag
417   * @retval The new state of __FLAG__ (SET or RESET).
418   */
419 #define __HAL_FLASH_GET_FLAG(__FLAG__)          ((FLASH->SR & (__FLAG__)) == (__FLAG__))
420
421 /**
422   * @brief  Clear the specified FLASH flag.
423   * @param  __FLAG__: specifies the FLASH flags to clear.
424   *          This parameter can be any combination of the following values:
425   *            @arg FLASH_FLAG_EOP   : FLASH End of Operation flag 
426   *            @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag 
427   *            @arg FLASH_FLAG_PGERR : FLASH Programming error flag 
428   * @retval none
429   */
430 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__)        (FLASH->SR = (__FLAG__))
431
432 /**
433   * @}
434   */ 
435
436 /**
437   * @}
438   */ 
439   
440 /* Include FLASH HAL Extension module */
441 #include "stm32f0xx_hal_flash_ex.h"  
442
443 /* Exported functions --------------------------------------------------------*/
444
445 /** @addtogroup FLASH_Exported_Functions
446   * @{
447   */  
448
449 /** @addtogroup FLASH_Exported_Functions_Group1 
450  *  @brief   Data transfers functions
451  * @{
452  */
453   
454 /* IO operation functions *****************************************************/
455 HAL_StatusTypeDef  HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
456 HAL_StatusTypeDef  HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
457
458 /* FLASH IRQ handler method */
459 void               HAL_FLASH_IRQHandler(void);
460 /* Callbacks in non blocking modes */ 
461 void               HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
462 void               HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
463
464 /**
465   * @}
466   */  
467
468 /** @addtogroup FLASH_Exported_Functions_Group2 
469  *  @brief   management functions 
470  * @{
471  */
472    
473 /* FLASH Memory Programming functions *****************************************/   
474 HAL_StatusTypeDef  HAL_FLASH_Unlock(void);
475 HAL_StatusTypeDef  HAL_FLASH_Lock(void);
476
477 /* Option Bytes Programming functions *****************************************/
478 HAL_StatusTypeDef  HAL_FLASH_OB_Unlock(void);
479 HAL_StatusTypeDef  HAL_FLASH_OB_Lock(void);
480 HAL_StatusTypeDef  HAL_FLASH_OB_Launch(void);
481
482 /**
483   * @}
484   */
485
486 /** @addtogroup FLASH_Exported_Functions_Group3 
487  * @{
488  */
489 /* Peripheral State and Error functions ***************************************/
490 uint32_t HAL_FLASH_GetError(void);
491
492 /**
493   * @}
494   */
495
496 /**
497   * @}
498   */
499
500 /**
501   * @}
502   */
503
504 /**
505   * @}
506   */
507
508 #ifdef __cplusplus
509 }
510 #endif
511
512 #endif /* __STM32F0xx_HAL_FLASH_H */
513
514 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
515