Martin Johnson / STM32F3-Discovery

Dependents:   Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f30x_flash.h Source File

stm32f30x_flash.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f30x_flash.h
00004   * @author  MCD Application Team
00005   * @version V1.2.3
00006   * @date    10-July-2015
00007   * @brief   This file contains all the functions prototypes for the FLASH 
00008   *          firmware library.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00013   *
00014   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00015   * You may not use this file except in compliance with the License.
00016   * You may obtain a copy of the License at:
00017   *
00018   *        http://www.st.com/software_license_agreement_liberty_v2
00019   *
00020   * Unless required by applicable law or agreed to in writing, software 
00021   * distributed under the License is distributed on an "AS IS" BASIS, 
00022   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023   * See the License for the specific language governing permissions and
00024   * limitations under the License.
00025   *
00026   ******************************************************************************
00027   */
00028 
00029 /* Define to prevent recursive inclusion -------------------------------------*/
00030 #ifndef __STM32F30x_FLASH_H
00031 #define __STM32F30x_FLASH_H
00032 
00033 #ifdef __cplusplus
00034  extern "C" {
00035 #endif
00036 
00037 /* Includes ------------------------------------------------------------------*/
00038 #include "stm32f30x.h"
00039 
00040 /** @addtogroup STM32F30x_StdPeriph_Driver
00041   * @{
00042   */
00043 
00044 /** @addtogroup FLASH
00045   * @{
00046   */ 
00047 
00048 /* Exported types ------------------------------------------------------------*/
00049 /** 
00050   * @brief FLASH Status  
00051   */ 
00052 typedef enum
00053 { 
00054   FLASH_BUSY = 1,
00055   FLASH_ERROR_WRP,
00056   FLASH_ERROR_PROGRAM,
00057   FLASH_COMPLETE,
00058   FLASH_TIMEOUT
00059 }FLASH_Status;
00060 
00061 /* Exported constants --------------------------------------------------------*/
00062 
00063 /** @defgroup FLASH_Exported_Constants
00064   * @{
00065   */  
00066 
00067 /** @defgroup Flash_Latency 
00068   * @{
00069   */ 
00070 #define FLASH_Latency_0                ((uint8_t)0x0000)    /*!< FLASH Zero Latency cycle */
00071 #define FLASH_Latency_1                FLASH_ACR_LATENCY_0  /*!< FLASH One Latency cycle */
00072 #define FLASH_Latency_2                FLASH_ACR_LATENCY_1  /*!< FLASH Two Latency cycles */
00073 
00074 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
00075                                    ((LATENCY) == FLASH_Latency_1) || \
00076                                    ((LATENCY) == FLASH_Latency_2))
00077 /**
00078   * @}
00079   */ 
00080 
00081 /** @defgroup FLASH_Interrupts 
00082   * @{
00083   */
00084    
00085 #define FLASH_IT_EOP                   FLASH_CR_EOPIE  /*!< End of programming interrupt source */
00086 #define FLASH_IT_ERR                   FLASH_CR_ERRIE  /*!< Error interrupt source */
00087 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
00088 /**
00089   * @}
00090   */
00091 /** @defgroup FLASH_Address 
00092   * @{
00093   */
00094   
00095 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0803FFFF))
00096 
00097 /**
00098   * @}
00099   */ 
00100 
00101 /** @defgroup FLASH_OB_DATA_ADDRESS 
00102   * @{
00103   */  
00104 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806)) 
00105 
00106 /**
00107   * @}
00108   */
00109 
00110 /** @defgroup Option_Bytes_Write_Protection 
00111   * @{
00112   */
00113   
00114 #define OB_WRP_Pages0to1               ((uint32_t)0x00000001) /* Write protection of page 0 to 1 */
00115 #define OB_WRP_Pages2to3               ((uint32_t)0x00000002) /* Write protection of page 2 to 3 */
00116 #define OB_WRP_Pages4to5               ((uint32_t)0x00000004) /* Write protection of page 4 to 5 */
00117 #define OB_WRP_Pages6to7               ((uint32_t)0x00000008) /* Write protection of page 6 to 7 */
00118 #define OB_WRP_Pages8to9               ((uint32_t)0x00000010) /* Write protection of page 8 to 9 */
00119 #define OB_WRP_Pages10to11             ((uint32_t)0x00000020) /* Write protection of page 10 to 11 */
00120 #define OB_WRP_Pages12to13             ((uint32_t)0x00000040) /* Write protection of page 12 to 13 */
00121 #define OB_WRP_Pages14to15             ((uint32_t)0x00000080) /* Write protection of page 14 to 15 */
00122 #define OB_WRP_Pages16to17             ((uint32_t)0x00000100) /* Write protection of page 16 to 17 */
00123 #define OB_WRP_Pages18to19             ((uint32_t)0x00000200) /* Write protection of page 18 to 19 */
00124 #define OB_WRP_Pages20to21             ((uint32_t)0x00000400) /* Write protection of page 20 to 21 */
00125 #define OB_WRP_Pages22to23             ((uint32_t)0x00000800) /* Write protection of page 22 to 23 */
00126 #define OB_WRP_Pages24to25             ((uint32_t)0x00001000) /* Write protection of page 24 to 25 */
00127 #define OB_WRP_Pages26to27             ((uint32_t)0x00002000) /* Write protection of page 26 to 27 */
00128 #define OB_WRP_Pages28to29             ((uint32_t)0x00004000) /* Write protection of page 28 to 29 */
00129 #define OB_WRP_Pages30to31             ((uint32_t)0x00008000) /* Write protection of page 30 to 31 */
00130 #define OB_WRP_Pages32to33             ((uint32_t)0x00010000) /* Write protection of page 32 to 33 */
00131 #define OB_WRP_Pages34to35             ((uint32_t)0x00020000) /* Write protection of page 34 to 35 */
00132 #define OB_WRP_Pages36to37             ((uint32_t)0x00040000) /* Write protection of page 36 to 37 */
00133 #define OB_WRP_Pages38to39             ((uint32_t)0x00080000) /* Write protection of page 38 to 39 */
00134 #define OB_WRP_Pages40to41             ((uint32_t)0x00100000) /* Write protection of page 40 to 41 */
00135 #define OB_WRP_Pages42to43             ((uint32_t)0x00200000) /* Write protection of page 42 to 43 */
00136 #define OB_WRP_Pages44to45             ((uint32_t)0x00400000) /* Write protection of page 44 to 45 */
00137 #define OB_WRP_Pages46to47             ((uint32_t)0x00800000) /* Write protection of page 46 to 47 */
00138 #define OB_WRP_Pages48to49             ((uint32_t)0x01000000) /* Write protection of page 48 to 49 */
00139 #define OB_WRP_Pages50to51             ((uint32_t)0x02000000) /* Write protection of page 50 to 51 */
00140 #define OB_WRP_Pages52to53             ((uint32_t)0x04000000) /* Write protection of page 52 to 53 */
00141 #define OB_WRP_Pages54to55             ((uint32_t)0x08000000) /* Write protection of page 54 to 55 */
00142 #define OB_WRP_Pages56to57             ((uint32_t)0x10000000) /* Write protection of page 56 to 57 */
00143 #define OB_WRP_Pages58to59             ((uint32_t)0x20000000) /* Write protection of page 58 to 59 */
00144 #define OB_WRP_Pages60to61             ((uint32_t)0x40000000) /* Write protection of page 60 to 61 */
00145 
00146 #ifdef STM32F303xE
00147 #define OB_WRP_Pages62to263            ((uint32_t)0x80000000) /* Write protection of page 62 to 263 */
00148 #else
00149 #define OB_WRP_Pages62to127            ((uint32_t)0x80000000) /* Write protection of page 62 to 127 */
00150 #endif  /* STM32F303xE */
00151 
00152 #define OB_WRP_AllPages                ((uint32_t)0xFFFFFFFF) /*!< Write protection of all Sectors */
00153 
00154 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
00155 
00156 /**
00157   * @}
00158   */
00159 
00160 /** @defgroup Option_Bytes_Read_Protection 
00161   * @{
00162   */ 
00163 
00164 /** 
00165   * @brief  Read Protection Level  
00166   */ 
00167 #define OB_RDP_Level_0   ((uint8_t)0xAA)
00168 #define OB_RDP_Level_1   ((uint8_t)0xBB)
00169 /*#define OB_RDP_Level_2   ((uint8_t)0xCC)*/ /* Warning: When enabling read protection level 2 
00170                                                 it's no more possible to go back to level 1 or 0 */
00171 
00172 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
00173                           ((LEVEL) == OB_RDP_Level_1))/*||\
00174                           ((LEVEL) == OB_RDP_Level_2))*/
00175 /**
00176   * @}
00177   */ 
00178 
00179 /** @defgroup Option_Bytes_IWatchdog 
00180   * @{
00181   */
00182 
00183 #define OB_IWDG_SW                     ((uint8_t)0x01)  /*!< Software IWDG selected */
00184 #define OB_IWDG_HW                     ((uint8_t)0x00)  /*!< Hardware IWDG selected */
00185 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
00186 
00187 /**
00188   * @}
00189   */
00190 
00191 /** @defgroup Option_Bytes_nRST_STOP 
00192   * @{
00193   */
00194 
00195 #define OB_STOP_NoRST                  ((uint8_t)0x02) /*!< No reset generated when entering in STOP */
00196 #define OB_STOP_RST                    ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
00197 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
00198 
00199 /**
00200   * @}
00201   */
00202 
00203 /** @defgroup Option_Bytes_nRST_STDBY 
00204   * @{
00205   */
00206 
00207 #define OB_STDBY_NoRST                 ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */
00208 #define OB_STDBY_RST                   ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
00209 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
00210 
00211 /**
00212   * @}
00213   */
00214 /** @defgroup Option_Bytes_BOOT1
00215   * @{
00216   */
00217 
00218 #define OB_BOOT1_RESET                 ((uint8_t)0x00) /*!< BOOT1 Reset */
00219 #define OB_BOOT1_SET                   ((uint8_t)0x10) /*!< BOOT1 Set */
00220 #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
00221 
00222 /**
00223   * @}
00224   */  
00225 /** @defgroup Option_Bytes_VDDA_Analog_Monitoring
00226   * @{
00227   */
00228 
00229 #define OB_VDDA_ANALOG_ON              ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source ON */
00230 #define OB_VDDA_ANALOG_OFF             ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */
00231 
00232 #define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
00233 
00234 /**
00235   * @}
00236   */ 
00237 
00238 /** @defgroup FLASH_Option_Bytes_SRAM_Parity_Enable 
00239   * @{
00240   */
00241 
00242 #define OB_SRAM_PARITY_SET              ((uint8_t)0x00) /*!< SRAM parity enable Set */
00243 #define OB_SRAM_PARITY_RESET            ((uint8_t)0x40) /*!< SRAM parity enable reset */
00244 
00245 #define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_SRAM_PARITY_SET) || ((PARITY) == OB_SRAM_PARITY_RESET))
00246 
00247 /**
00248   * @}
00249   */ 
00250       
00251 /** @defgroup FLASH_Flags 
00252   * @{
00253   */ 
00254 
00255 #define FLASH_FLAG_BSY                 FLASH_SR_BSY     /*!< FLASH Busy flag */
00256 #define FLASH_FLAG_PGERR               FLASH_SR_PGERR   /*!< FLASH Programming error flag */
00257 #define FLASH_FLAG_WRPERR              FLASH_SR_WRPERR  /*!< FLASH Write protected error flag */
00258 #define FLASH_FLAG_EOP                 FLASH_SR_EOP     /*!< FLASH End of Programming flag */
00259  
00260 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFCB) == 0x00000000) && ((FLAG) != 0x00000000))
00261 
00262 #define IS_FLASH_GET_FLAG(FLAG)  (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_PGERR) || \
00263                                   ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_EOP))
00264 /**
00265   * @}
00266   */ 
00267 /** @defgroup Timeout_definition 
00268   * @{
00269   */ 
00270 #define FLASH_ER_PRG_TIMEOUT         ((uint32_t)0x000B0000)
00271 
00272 /**
00273   * @}
00274   */ 
00275 
00276 /**
00277   * @}
00278   */ 
00279   
00280 /* Exported macro ------------------------------------------------------------*/
00281 /* Exported functions --------------------------------------------------------*/ 
00282 
00283 /* FLASH Interface configuration functions ************************************/
00284 void FLASH_SetLatency(uint32_t FLASH_Latency);
00285 void FLASH_HalfCycleAccessCmd(FunctionalState NewState);
00286 void FLASH_PrefetchBufferCmd(FunctionalState NewState);
00287 
00288 /* FLASH Memory Programming functions *****************************************/   
00289 void FLASH_Unlock(void);
00290 void FLASH_Lock(void);
00291 FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
00292 FLASH_Status FLASH_EraseAllPages(void);
00293 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
00294 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
00295 
00296 /* Option Bytes Programming functions *****************************************/ 
00297 void FLASH_OB_Unlock(void);
00298 void FLASH_OB_Lock(void);
00299 void FLASH_OB_Launch(void);
00300 FLASH_Status FLASH_OB_Erase(void);
00301 FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP);
00302 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP);
00303 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
00304 FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1);
00305 FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG);
00306 FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity);
00307 FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER);
00308 FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
00309 uint8_t FLASH_OB_GetUser(void);
00310 uint32_t FLASH_OB_GetWRP(void);
00311 FlagStatus FLASH_OB_GetRDP(void);
00312 
00313 /* Interrupts and flags management functions **********************************/
00314 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
00315 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
00316 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
00317 FLASH_Status FLASH_GetStatus(void);
00318 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
00319 
00320 #ifdef __cplusplus
00321 }
00322 #endif
00323 
00324 #endif /* __STM32F30x_FLASH_H */
00325 
00326 /**
00327   * @}
00328   */ 
00329 
00330 /**
00331   * @}
00332   */ 
00333 
00334 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/