1 /** 2 ****************************************************************************** 3 * @file stm32f37x_flash.h 4 * @author MCD Application Team 5 * @version V1.0.0 6 * @date 20-September-2012 7 * @brief This file contains all the functions prototypes for the FLASH 8 * firmware library. 9 ****************************************************************************** 10 * @attention 11 * 12 * <h2><center>© COPYRIGHT 2012 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 __STM32F37X_FLASH_H 31 #define __STM32F37X_FLASH_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /* Includes ------------------------------------------------------------------*/ 38 #include "stm32f37x.h" 39 40 /** @addtogroup STM32F37x_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_WRP, 56 FLASH_ERROR_PROGRAM, 57 FLASH_COMPLETE, 58 FLASH_TIMEOUT 59 }FLASH_Status; 60 61 /* Exported constants --------------------------------------------------------*/ 62 63 /** @defgroup FLASH_Exported_Constants 64 * @{ 65 */ 66 67 /** @defgroup FLASH_Latency 68 * @{ 69 */ 70 #define FLASH_Latency_0 ((uint8_t)0x0000) /*!< FLASH Zero Latency cycle */ 71 #define FLASH_Latency_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */ 72 #define FLASH_Latency_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */ 73 74 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \ 75 ((LATENCY) == FLASH_Latency_1) || \ 76 ((LATENCY) == FLASH_Latency_2)) 77 /** 78 * @} 79 */ 80 81 /** @defgroup FLASH_Interrupts 82 * @{ 83 */ 84 85 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of programming interrupt source */ 86 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error interrupt source */ 87 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000))) 88 /** 89 * @} 90 */ 91 /** @defgroup FLASH_Address 92 * @{ 93 */ 94 95 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0803FFFF)) 96 97 /** 98 * @} 99 */ 100 101 /** @defgroup FLASH_OB_DATA_ADDRESS 102 * @{ 103 */ 104 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806)) 105 106 /** 107 * @} 108 */ 109 110 /** @defgroup FLASH_Option_Bytes_Write_Protection 111 * @{ 112 */ 113 114 115 #define OB_WRP_Pages0to1 ((uint32_t)0x00000001) /* Write protection of page 0 to 1 */ 116 #define OB_WRP_Pages2to3 ((uint32_t)0x00000002) /* Write protection of page 2 to 3 */ 117 #define OB_WRP_Pages4to5 ((uint32_t)0x00000004) /* Write protection of page 4 to 5 */ 118 #define OB_WRP_Pages6to7 ((uint32_t)0x00000008) /* Write protection of page 6 to 7 */ 119 #define OB_WRP_Pages8to9 ((uint32_t)0x00000010) /* Write protection of page 8 to 9 */ 120 #define OB_WRP_Pages10to11 ((uint32_t)0x00000020) /* Write protection of page 10 to 11 */ 121 #define OB_WRP_Pages12to13 ((uint32_t)0x00000040) /* Write protection of page 12 to 13 */ 122 #define OB_WRP_Pages14to15 ((uint32_t)0x00000080) /* Write protection of page 14 to 15 */ 123 #define OB_WRP_Pages16to17 ((uint32_t)0x00000100) /* Write protection of page 16 to 17 */ 124 #define OB_WRP_Pages18to19 ((uint32_t)0x00000200) /* Write protection of page 18 to 19 */ 125 #define OB_WRP_Pages20to21 ((uint32_t)0x00000400) /* Write protection of page 20 to 21 */ 126 #define OB_WRP_Pages22to23 ((uint32_t)0x00000800) /* Write protection of page 22 to 23 */ 127 #define OB_WRP_Pages24to25 ((uint32_t)0x00001000) /* Write protection of page 24 to 25 */ 128 #define OB_WRP_Pages26to27 ((uint32_t)0x00002000) /* Write protection of page 26 to 27 */ 129 #define OB_WRP_Pages28to29 ((uint32_t)0x00004000) /* Write protection of page 28 to 29 */ 130 #define OB_WRP_Pages30to31 ((uint32_t)0x00008000) /* Write protection of page 30 to 31 */ 131 #define OB_WRP_Pages32to33 ((uint32_t)0x00010000) /* Write protection of page 32 to 33 */ 132 #define OB_WRP_Pages34to35 ((uint32_t)0x00020000) /* Write protection of page 34 to 35 */ 133 #define OB_WRP_Pages36to37 ((uint32_t)0x00040000) /* Write protection of page 36 to 37 */ 134 #define OB_WRP_Pages38to39 ((uint32_t)0x00080000) /* Write protection of page 38 to 39 */ 135 #define OB_WRP_Pages40to41 ((uint32_t)0x00100000) /* Write protection of page 40 to 41 */ 136 #define OB_WRP_Pages42to43 ((uint32_t)0x00200000) /* Write protection of page 42 to 43 */ 137 #define OB_WRP_Pages44to45 ((uint32_t)0x00400000) /* Write protection of page 44 to 45 */ 138 #define OB_WRP_Pages46to47 ((uint32_t)0x00800000) /* Write protection of page 46 to 47 */ 139 #define OB_WRP_Pages48to49 ((uint32_t)0x01000000) /* Write protection of page 48 to 49 */ 140 #define OB_WRP_Pages50to51 ((uint32_t)0x02000000) /* Write protection of page 50 to 51 */ 141 #define OB_WRP_Pages52to53 ((uint32_t)0x04000000) /* Write protection of page 52 to 53 */ 142 #define OB_WRP_Pages54to55 ((uint32_t)0x08000000) /* Write protection of page 54 to 55 */ 143 #define OB_WRP_Pages56to57 ((uint32_t)0x10000000) /* Write protection of page 56 to 57 */ 144 #define OB_WRP_Pages58to59 ((uint32_t)0x20000000) /* Write protection of page 58 to 59 */ 145 #define OB_WRP_Pages60to61 ((uint32_t)0x40000000) /* Write protection of page 60 to 61 */ 146 #define OB_WRP_Pages62to127 ((uint32_t)0x80000000) /* Write protection of page 62 to 127 */ 147 148 #define OB_WRP_AllPages ((uint32_t)0xFFFFFFFF) /*!< Write protection of all Sectors */ 149 150 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000)) 151 152 /** 153 * @} 154 */ 155 156 /** @defgroup FLASH_Option_Bytes_Read_Protection 157 * @{ 158 */ 159 160 /** 161 * @brief FLASH_Read_Protection_Level 162 */ 163 #define OB_RDP_Level_0 ((uint8_t)0xAA) 164 #define OB_RDP_Level_1 ((uint8_t)0xBB) 165 /*#define OB_RDP_Level_2 ((uint8_t)0xCC)*/ /* Warning: When enabling read protection level 2 166 it's no more possible to go back to level 1 or 0 */ 167 168 #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\ 169 ((LEVEL) == OB_RDP_Level_1))/*||\ 170 ((LEVEL) == OB_RDP_Level_2))*/ 171 /** 172 * @} 173 */ 174 175 /** @defgroup FLASH_Option_Bytes_IWatchdog 176 * @{ 177 */ 178 179 #define OB_IWDG_SW ((uint8_t)0x01) /*!< Software IWDG selected */ 180 #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware IWDG selected */ 181 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW)) 182 183 /** 184 * @} 185 */ 186 187 /** @defgroup FLASH_Option_Bytes_nRST_STOP 188 * @{ 189 */ 190 191 #define OB_STOP_NoRST ((uint8_t)0x02) /*!< No reset generated when entering in STOP */ 192 #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */ 193 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST)) 194 195 /** 196 * @} 197 */ 198 199 /** @defgroup FLASH_Option_Bytes_nRST_STDBY 200 * @{ 201 */ 202 203 #define OB_STDBY_NoRST ((uint8_t)0x04) /*!< No reset generated when entering in STANDBY */ 204 #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */ 205 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST)) 206 207 /** 208 * @} 209 */ 210 211 /** @defgroup FLASH_Option_Bytes_BOOT1 212 * @{ 213 */ 214 215 #define OB_BOOT1_RESET ((uint8_t)0x00) /*!< BOOT1 Reset */ 216 #define OB_BOOT1_SET ((uint8_t)0x10) /*!< BOOT1 Set */ 217 #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET)) 218 219 /** 220 * @} 221 */ 222 223 /** @defgroup FLASH_Option_Bytes_VDDA_Analog_Monitoring 224 * @{ 225 */ 226 227 #define OB_VDDA_ANALOG_ON ((uint8_t)0x20) /*!< Analog monitoring on VDDA Power source ON */ 228 #define OB_VDDA_ANALOG_OFF ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */ 229 230 #define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF)) 231 232 /** 233 * @} 234 */ 235 /** @defgroup FLASH_Option_Bytes_VDD_Analog_Monitoring 236 * @{ 237 */ 238 239 #define OB_VDD_SD12_ON ((uint8_t)0x80) /*!< Analog monitoring on VDDA Power source ON */ 240 #define OB_VDD_SD12_OFF ((uint8_t)0x00) /*!< Analog monitoring on VDDA Power source OFF */ 241 242 #define IS_OB_VDD_SD12(MODE) (((MODE) == OB_VDD_SD12_ON) || ((MODE) == OB_VDD_SD12_OFF)) 243 244 /** 245 * @} 246 */ 247 248 /** @defgroup FLASH_Option_Bytes_SRAM_Parity_Enable 249 * @{ 250 */ 251 252 #define OB_SRAM_PARITY_SET ((uint8_t)0x00) /*!< SRAM parity enable Set */ 253 #define OB_SRAM_PARITY_RESET ((uint8_t)0x40) /*!< SRAM parity enable reset */ 254 255 #define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_SRAM_PARITY_SET) || ((PARITY) == OB_SRAM_PARITY_RESET)) 256 257 /** 258 * @} 259 */ 260 261 /** @defgroup FLASH_Flags 262 * @{ 263 */ 264 265 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ 266 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */ 267 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ 268 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */ 269 270 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFC3) == 0x00000000) && ((FLAG) != 0x00000000)) 271 272 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_PGERR) || \ 273 ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_EOP)) 274 /** 275 * @} 276 */ 277 278 /** @defgroup FLASH_Keys 279 * @{ 280 */ 281 #define RDP_KEY ((uint16_t)0x00A5) 282 #define FLASH_KEY1 ((uint32_t)0x45670123) 283 #define FLASH_KEY2 ((uint32_t)0xCDEF89AB) 284 #define FLASH_OPTKEY1 FLASH_KEY1 285 #define FLASH_OPTKEY2 FLASH_KEY2 286 /** 287 * @} 288 */ 289 290 /** @defgroup FLASH_Timeout_definition 291 * @{ 292 */ 293 294 #define FLASH_ER_PRG_TIMEOUT ((uint32_t)0x000B0000) 295 296 /** 297 * @} 298 */ 299 300 /** @defgroup FLASH_Legacy 301 * @{ 302 */ 303 #define FLASH_WRProt_Pages0to1 OB_WRP_Pages0to1 304 #define FLASH_WRProt_Pages2to3 OB_WRP_Pages2to3 305 #define FLASH_WRProt_Pages4to5 OB_WRP_Pages4to5 306 #define FLASH_WRProt_Pages6to7 OB_WRP_Pages6to7 307 #define FLASH_WRProt_Pages8to9 OB_WRP_Pages8to9 308 #define FLASH_WRProt_Pages10to11 OB_WRP_Pages10to11 309 #define FLASH_WRProt_Pages12to13 OB_WRP_Pages12to13 310 #define FLASH_WRProt_Pages14to15 OB_WRP_Pages14to15 311 #define FLASH_WRProt_Pages16to17 OB_WRP_Pages16to17 312 #define FLASH_WRProt_Pages18to19 OB_WRP_Pages18to19 313 #define FLASH_WRProt_Pages20to21 OB_WRP_Pages20to21 314 #define FLASH_WRProt_Pages22to23 OB_WRP_Pages22to23 315 #define FLASH_WRProt_Pages24to25 OB_WRP_Pages24to25 316 #define FLASH_WRProt_Pages26to27 OB_WRP_Pages26to27 317 #define FLASH_WRProt_Pages28to29 OB_WRP_Pages28to29 318 #define FLASH_WRProt_Pages30to31 OB_WRP_Pages30to31 319 #define FLASH_WRProt_Pages32to33 OB_WRP_Pages32to33 320 #define FLASH_WRProt_Pages34to35 OB_WRP_Pages34to35 321 #define FLASH_WRProt_Pages36to37 OB_WRP_Pages36to37 322 #define FLASH_WRProt_Pages38to39 OB_WRP_Pages38to39 323 #define FLASH_WRProt_Pages40to41 OB_WRP_Pages40to41 324 #define FLASH_WRProt_Pages42to43 OB_WRP_Pages42to43 325 #define FLASH_WRProt_Pages44to45 OB_WRP_Pages44to45 326 #define FLASH_WRProt_Pages46to47 OB_WRP_Pages46to47 327 #define FLASH_WRProt_Pages48to49 OB_WRP_Pages48to49 328 #define FLASH_WRProt_Pages50to51 OB_WRP_Pages50to51 329 #define FLASH_WRProt_Pages52to53 OB_WRP_Pages52to53 330 #define FLASH_WRProt_Pages54to55 OB_WRP_Pages54to55 331 #define FLASH_WRProt_Pages56to57 OB_WRP_Pages56to57 332 #define FLASH_WRProt_Pages58to59 OB_WRP_Pages58to59 333 #define FLASH_WRProt_Pages60to61 OB_WRP_Pages60to61 334 #define FLASH_WRProt_Pages62to127 OB_WRP_Pages62to127 335 336 #define FLASH_WRProt_AllPages OB_WRP_AllPages 337 /** 338 * @} 339 */ 340 /** 341 * @} 342 */ 343 /* Exported macro ------------------------------------------------------------*/ 344 /* Exported functions --------------------------------------------------------*/ 345 346 /* FLASH Interface configuration functions ************************************/ 347 void FLASH_SetLatency(uint32_t FLASH_Latency); 348 void FLASH_HalfCycleAccessCmd(FunctionalState NewState); 349 void FLASH_PrefetchBufferCmd(FunctionalState NewState); 350 351 /* FLASH Memory Programming functions *****************************************/ 352 void FLASH_Unlock(void); 353 void FLASH_Lock(void); 354 FLASH_Status FLASH_ErasePage(uint32_t Page_Address); 355 FLASH_Status FLASH_EraseAllPages(void); 356 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data); 357 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data); 358 359 /* FLASH Option Bytes Programming functions *****************************************/ 360 void FLASH_OB_Unlock(void); 361 void FLASH_OB_Lock(void); 362 void FLASH_OB_Launch(void); 363 FLASH_Status FLASH_OB_Erase(void); 364 FLASH_Status FLASH_OB_ProgramData(uint32_t Address, uint8_t Data); 365 FLASH_Status FLASH_OB_EnableWRP(uint32_t OB_WRP); 366 FLASH_Status FLASH_OB_RDPConfig(uint8_t OB_RDP); 367 FLASH_Status FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); 368 FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1); 369 FLASH_Status FLASH_OB_VDDAConfig(uint8_t OB_VDDA_ANALOG); 370 FLASH_Status FLASH_OB_VDD_SD12Config(uint8_t OB_VDD_SD12); 371 FLASH_Status FLASH_OB_SRAMParityConfig(uint8_t OB_SRAM_Parity); 372 FLASH_Status FLASH_OB_WriteUser(uint8_t OB_USER); 373 uint8_t FLASH_OB_GetUser(void); 374 uint32_t FLASH_OB_GetWRP(void); 375 FlagStatus FLASH_OB_GetRDP(void); 376 377 /* FLASH Interrupts and flags management functions **********************************/ 378 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState); 379 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG); 380 void FLASH_ClearFlag(uint32_t FLASH_FLAG); 381 FLASH_Status FLASH_GetStatus(void); 382 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout); 383 384 385 /** @defgroup FLASH_Legacy 386 * @{ 387 */ 388 #define FLASH_EraseOptionBytes FLASH_OB_Erase 389 #define FLASH_EnableWriteProtection FLASH_OB_EnableWRP 390 #define FLASH_UserOptionByteConfig FLASH_OB_UserConfig 391 #define FLASH_ProgramOptionByteData FLASH_OB_ProgramData 392 #define FLASH_GetUserOptionByte FLASH_OB_GetUser 393 #define FLASH_GetWriteProtectionOptionByte FLASH_OB_GetWRP 394 /** 395 * @} 396 */ 397 398 #ifdef __cplusplus 399 } 400 #endif 401 402 #endif /* __STM32F37X_FLASH_H */ 403 404 /** 405 * @} 406 */ 407 408 /** 409 * @} 410 */ 411 412 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 413