stm32f4xx_flash.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_flash.h
  4. * @author MCD Application Team
  5. * @version V1.8.0
  6. * @date 04-November-2016
  7. * @brief This file contains all the functions prototypes for the FLASH
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2016 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. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F4xx_FLASH_H
  30. #define __STM32F4xx_FLASH_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f4xx.h"
  36. /** @addtogroup STM32F4xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup FLASH
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief FLASH Status
  45. */
  46. typedef enum
  47. {
  48. FLASH_BUSY = 1,
  49. FLASH_ERROR_RD,
  50. FLASH_ERROR_PGS,
  51. FLASH_ERROR_PGP,
  52. FLASH_ERROR_PGA,
  53. FLASH_ERROR_WRP,
  54. FLASH_ERROR_PROGRAM,
  55. FLASH_ERROR_OPERATION,
  56. FLASH_COMPLETE
  57. }FLASH_Status;
  58. /* Exported constants --------------------------------------------------------*/
  59. /** @defgroup FLASH_Exported_Constants
  60. * @{
  61. */
  62. /** @defgroup Flash_Latency
  63. * @{
  64. */
  65. #define FLASH_Latency_0 ((uint8_t)0x0000) /*!< FLASH Zero Latency cycle */
  66. #define FLASH_Latency_1 ((uint8_t)0x0001) /*!< FLASH One Latency cycle */
  67. #define FLASH_Latency_2 ((uint8_t)0x0002) /*!< FLASH Two Latency cycles */
  68. #define FLASH_Latency_3 ((uint8_t)0x0003) /*!< FLASH Three Latency cycles */
  69. #define FLASH_Latency_4 ((uint8_t)0x0004) /*!< FLASH Four Latency cycles */
  70. #define FLASH_Latency_5 ((uint8_t)0x0005) /*!< FLASH Five Latency cycles */
  71. #define FLASH_Latency_6 ((uint8_t)0x0006) /*!< FLASH Six Latency cycles */
  72. #define FLASH_Latency_7 ((uint8_t)0x0007) /*!< FLASH Seven Latency cycles */
  73. #define FLASH_Latency_8 ((uint8_t)0x0008) /*!< FLASH Eight Latency cycles */
  74. #define FLASH_Latency_9 ((uint8_t)0x0009) /*!< FLASH Nine Latency cycles */
  75. #define FLASH_Latency_10 ((uint8_t)0x000A) /*!< FLASH Ten Latency cycles */
  76. #define FLASH_Latency_11 ((uint8_t)0x000B) /*!< FLASH Eleven Latency cycles */
  77. #define FLASH_Latency_12 ((uint8_t)0x000C) /*!< FLASH Twelve Latency cycles */
  78. #define FLASH_Latency_13 ((uint8_t)0x000D) /*!< FLASH Thirteen Latency cycles */
  79. #define FLASH_Latency_14 ((uint8_t)0x000E) /*!< FLASH Fourteen Latency cycles */
  80. #define FLASH_Latency_15 ((uint8_t)0x000F) /*!< FLASH Fifteen Latency cycles */
  81. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
  82. ((LATENCY) == FLASH_Latency_1) || \
  83. ((LATENCY) == FLASH_Latency_2) || \
  84. ((LATENCY) == FLASH_Latency_3) || \
  85. ((LATENCY) == FLASH_Latency_4) || \
  86. ((LATENCY) == FLASH_Latency_5) || \
  87. ((LATENCY) == FLASH_Latency_6) || \
  88. ((LATENCY) == FLASH_Latency_7) || \
  89. ((LATENCY) == FLASH_Latency_8) || \
  90. ((LATENCY) == FLASH_Latency_9) || \
  91. ((LATENCY) == FLASH_Latency_10) || \
  92. ((LATENCY) == FLASH_Latency_11) || \
  93. ((LATENCY) == FLASH_Latency_12) || \
  94. ((LATENCY) == FLASH_Latency_13) || \
  95. ((LATENCY) == FLASH_Latency_14) || \
  96. ((LATENCY) == FLASH_Latency_15))
  97. /**
  98. * @}
  99. */
  100. /** @defgroup FLASH_Voltage_Range
  101. * @{
  102. */
  103. #define VoltageRange_1 ((uint8_t)0x00) /*!< Device operating range: 1.8V to 2.1V */
  104. #define VoltageRange_2 ((uint8_t)0x01) /*!<Device operating range: 2.1V to 2.7V */
  105. #define VoltageRange_3 ((uint8_t)0x02) /*!<Device operating range: 2.7V to 3.6V */
  106. #define VoltageRange_4 ((uint8_t)0x03) /*!<Device operating range: 2.7V to 3.6V + External Vpp */
  107. #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VoltageRange_1) || \
  108. ((RANGE) == VoltageRange_2) || \
  109. ((RANGE) == VoltageRange_3) || \
  110. ((RANGE) == VoltageRange_4))
  111. /**
  112. * @}
  113. */
  114. /** @defgroup FLASH_Sectors
  115. * @{
  116. */
  117. #define FLASH_Sector_0 ((uint16_t)0x0000) /*!< Sector Number 0 */
  118. #define FLASH_Sector_1 ((uint16_t)0x0008) /*!< Sector Number 1 */
  119. #define FLASH_Sector_2 ((uint16_t)0x0010) /*!< Sector Number 2 */
  120. #define FLASH_Sector_3 ((uint16_t)0x0018) /*!< Sector Number 3 */
  121. #define FLASH_Sector_4 ((uint16_t)0x0020) /*!< Sector Number 4 */
  122. #define FLASH_Sector_5 ((uint16_t)0x0028) /*!< Sector Number 5 */
  123. #define FLASH_Sector_6 ((uint16_t)0x0030) /*!< Sector Number 6 */
  124. #define FLASH_Sector_7 ((uint16_t)0x0038) /*!< Sector Number 7 */
  125. #define FLASH_Sector_8 ((uint16_t)0x0040) /*!< Sector Number 8 */
  126. #define FLASH_Sector_9 ((uint16_t)0x0048) /*!< Sector Number 9 */
  127. #define FLASH_Sector_10 ((uint16_t)0x0050) /*!< Sector Number 10 */
  128. #define FLASH_Sector_11 ((uint16_t)0x0058) /*!< Sector Number 11 */
  129. #define FLASH_Sector_12 ((uint16_t)0x0080) /*!< Sector Number 12 */
  130. #define FLASH_Sector_13 ((uint16_t)0x0088) /*!< Sector Number 13 */
  131. #define FLASH_Sector_14 ((uint16_t)0x0090) /*!< Sector Number 14 */
  132. #define FLASH_Sector_15 ((uint16_t)0x0098) /*!< Sector Number 15 */
  133. #define FLASH_Sector_16 ((uint16_t)0x00A0) /*!< Sector Number 16 */
  134. #define FLASH_Sector_17 ((uint16_t)0x00A8) /*!< Sector Number 17 */
  135. #define FLASH_Sector_18 ((uint16_t)0x00B0) /*!< Sector Number 18 */
  136. #define FLASH_Sector_19 ((uint16_t)0x00B8) /*!< Sector Number 19 */
  137. #define FLASH_Sector_20 ((uint16_t)0x00C0) /*!< Sector Number 20 */
  138. #define FLASH_Sector_21 ((uint16_t)0x00C8) /*!< Sector Number 21 */
  139. #define FLASH_Sector_22 ((uint16_t)0x00D0) /*!< Sector Number 22 */
  140. #define FLASH_Sector_23 ((uint16_t)0x00D8) /*!< Sector Number 23 */
  141. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_Sector_0) || ((SECTOR) == FLASH_Sector_1) ||\
  142. ((SECTOR) == FLASH_Sector_2) || ((SECTOR) == FLASH_Sector_3) ||\
  143. ((SECTOR) == FLASH_Sector_4) || ((SECTOR) == FLASH_Sector_5) ||\
  144. ((SECTOR) == FLASH_Sector_6) || ((SECTOR) == FLASH_Sector_7) ||\
  145. ((SECTOR) == FLASH_Sector_8) || ((SECTOR) == FLASH_Sector_9) ||\
  146. ((SECTOR) == FLASH_Sector_10) || ((SECTOR) == FLASH_Sector_11) ||\
  147. ((SECTOR) == FLASH_Sector_12) || ((SECTOR) == FLASH_Sector_13) ||\
  148. ((SECTOR) == FLASH_Sector_14) || ((SECTOR) == FLASH_Sector_15) ||\
  149. ((SECTOR) == FLASH_Sector_16) || ((SECTOR) == FLASH_Sector_17) ||\
  150. ((SECTOR) == FLASH_Sector_18) || ((SECTOR) == FLASH_Sector_19) ||\
  151. ((SECTOR) == FLASH_Sector_20) || ((SECTOR) == FLASH_Sector_21) ||\
  152. ((SECTOR) == FLASH_Sector_22) || ((SECTOR) == FLASH_Sector_23))
  153. #if defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F469_479xx)
  154. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x081FFFFF)) ||\
  155. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7A0F)))
  156. #endif /* STM32F427_437xx || STM32F429_439xx || STM32F469_479xx */
  157. #if defined (STM32F40_41xxx) || defined(STM32F412xG)
  158. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x080FFFFF)) ||\
  159. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7A0F)))
  160. #endif /* STM32F40_41xxx || STM32F412xG */
  161. #if defined (STM32F401xx)
  162. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0803FFFF)) ||\
  163. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7A0F)))
  164. #endif /* STM32F401xx */
  165. #if defined (STM32F411xE) || defined (STM32F446xx)
  166. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0807FFFF)) ||\
  167. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7A0F)))
  168. #endif /* STM32F411xE || STM32F446xx */
  169. #if defined (STM32F410xx)
  170. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0801FFFF)) ||\
  171. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7A0F)))
  172. #endif /* STM32F410xx */
  173. #if defined(STM32F413_423xx)
  174. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x0817FFFF)) ||\
  175. (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) <= 0x1FFF7BDF)))
  176. #endif /* STM32F413_423xx */
  177. /**
  178. * @}
  179. */
  180. /** @defgroup Option_Bytes_Write_Protection
  181. * @{
  182. */
  183. #define OB_WRP_Sector_0 ((uint32_t)0x00000001) /*!< Write protection of Sector0 */
  184. #define OB_WRP_Sector_1 ((uint32_t)0x00000002) /*!< Write protection of Sector1 */
  185. #define OB_WRP_Sector_2 ((uint32_t)0x00000004) /*!< Write protection of Sector2 */
  186. #define OB_WRP_Sector_3 ((uint32_t)0x00000008) /*!< Write protection of Sector3 */
  187. #define OB_WRP_Sector_4 ((uint32_t)0x00000010) /*!< Write protection of Sector4 */
  188. #define OB_WRP_Sector_5 ((uint32_t)0x00000020) /*!< Write protection of Sector5 */
  189. #define OB_WRP_Sector_6 ((uint32_t)0x00000040) /*!< Write protection of Sector6 */
  190. #define OB_WRP_Sector_7 ((uint32_t)0x00000080) /*!< Write protection of Sector7 */
  191. #define OB_WRP_Sector_8 ((uint32_t)0x00000100) /*!< Write protection of Sector8 */
  192. #define OB_WRP_Sector_9 ((uint32_t)0x00000200) /*!< Write protection of Sector9 */
  193. #define OB_WRP_Sector_10 ((uint32_t)0x00000400) /*!< Write protection of Sector10 */
  194. #define OB_WRP_Sector_11 ((uint32_t)0x00000800) /*!< Write protection of Sector11 */
  195. #define OB_WRP_Sector_12 ((uint32_t)0x00000001) /*!< Write protection of Sector12 */
  196. #define OB_WRP_Sector_13 ((uint32_t)0x00000002) /*!< Write protection of Sector13 */
  197. #define OB_WRP_Sector_14 ((uint32_t)0x00000004) /*!< Write protection of Sector14 */
  198. #define OB_WRP_Sector_15 ((uint32_t)0x00000008) /*!< Write protection of Sector15 */
  199. #define OB_WRP_Sector_16 ((uint32_t)0x00000010) /*!< Write protection of Sector16 */
  200. #define OB_WRP_Sector_17 ((uint32_t)0x00000020) /*!< Write protection of Sector17 */
  201. #define OB_WRP_Sector_18 ((uint32_t)0x00000040) /*!< Write protection of Sector18 */
  202. #define OB_WRP_Sector_19 ((uint32_t)0x00000080) /*!< Write protection of Sector19 */
  203. #define OB_WRP_Sector_20 ((uint32_t)0x00000100) /*!< Write protection of Sector20 */
  204. #define OB_WRP_Sector_21 ((uint32_t)0x00000200) /*!< Write protection of Sector21 */
  205. #define OB_WRP_Sector_22 ((uint32_t)0x00000400) /*!< Write protection of Sector22 */
  206. #define OB_WRP_Sector_23 ((uint32_t)0x00000800) /*!< Write protection of Sector23 */
  207. #define OB_WRP_Sector_All ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */
  208. #define IS_OB_WRP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
  209. /**
  210. * @}
  211. */
  212. /** @defgroup Selection_Protection_Mode
  213. * @{
  214. */
  215. #define OB_PcROP_Disable ((uint8_t)0x00) /*!< Disabled PcROP, nWPRi bits used for Write Protection on sector i */
  216. #define OB_PcROP_Enable ((uint8_t)0x80) /*!< Enable PcROP, nWPRi bits used for PCRoP Protection on sector i */
  217. #define IS_OB_PCROP_SELECT(PCROP) (((PCROP) == OB_PcROP_Disable) || ((PCROP) == OB_PcROP_Enable))
  218. /**
  219. * @}
  220. */
  221. /** @defgroup Option_Bytes_PC_ReadWrite_Protection
  222. * @{
  223. */
  224. #define OB_PCROP_Sector_0 ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector0 */
  225. #define OB_PCROP_Sector_1 ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector1 */
  226. #define OB_PCROP_Sector_2 ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector2 */
  227. #define OB_PCROP_Sector_3 ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector3 */
  228. #define OB_PCROP_Sector_4 ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector4 */
  229. #define OB_PCROP_Sector_5 ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector5 */
  230. #define OB_PCROP_Sector_6 ((uint32_t)0x00000040) /*!< PC Read/Write protection of Sector6 */
  231. #define OB_PCROP_Sector_7 ((uint32_t)0x00000080) /*!< PC Read/Write protection of Sector7 */
  232. #define OB_PCROP_Sector_8 ((uint32_t)0x00000100) /*!< PC Read/Write protection of Sector8 */
  233. #define OB_PCROP_Sector_9 ((uint32_t)0x00000200) /*!< PC Read/Write protection of Sector9 */
  234. #define OB_PCROP_Sector_10 ((uint32_t)0x00000400) /*!< PC Read/Write protection of Sector10 */
  235. #define OB_PCROP_Sector_11 ((uint32_t)0x00000800) /*!< PC Read/Write protection of Sector11 */
  236. #define OB_PCROP_Sector_12 ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector12 */
  237. #define OB_PCROP_Sector_13 ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector13 */
  238. #define OB_PCROP_Sector_14 ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector14 */
  239. #define OB_PCROP_Sector_15 ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector15 */
  240. #define OB_PCROP_Sector_16 ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector16 */
  241. #define OB_PCROP_Sector_17 ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector17 */
  242. #define OB_PCROP_Sector_18 ((uint32_t)0x00000040) /*!< PC Read/Write protection of Sector18 */
  243. #define OB_PCROP_Sector_19 ((uint32_t)0x00000080) /*!< PC Read/Write protection of Sector19 */
  244. #define OB_PCROP_Sector_20 ((uint32_t)0x00000100) /*!< PC Read/Write protection of Sector20 */
  245. #define OB_PCROP_Sector_21 ((uint32_t)0x00000200) /*!< PC Read/Write protection of Sector21 */
  246. #define OB_PCROP_Sector_22 ((uint32_t)0x00000400) /*!< PC Read/Write protection of Sector22 */
  247. #define OB_PCROP_Sector_23 ((uint32_t)0x00000800) /*!< PC Read/Write protection of Sector23 */
  248. #define OB_PCROP_Sector_All ((uint32_t)0x00000FFF) /*!< PC Read/Write protection of all Sectors */
  249. #define IS_OB_PCROP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
  250. /**
  251. * @}
  252. */
  253. /** @defgroup FLASH_Option_Bytes_Read_Protection
  254. * @{
  255. */
  256. #define OB_RDP_Level_0 ((uint8_t)0xAA)
  257. #define OB_RDP_Level_1 ((uint8_t)0x55)
  258. /*#define OB_RDP_Level_2 ((uint8_t)0xCC)*/ /*!< Warning: When enabling read protection level 2
  259. it's no more possible to go back to level 1 or 0 */
  260. #define IS_OB_RDP(LEVEL) (((LEVEL) == OB_RDP_Level_0)||\
  261. ((LEVEL) == OB_RDP_Level_1))/*||\
  262. ((LEVEL) == OB_RDP_Level_2))*/
  263. /**
  264. * @}
  265. */
  266. /** @defgroup FLASH_Option_Bytes_IWatchdog
  267. * @{
  268. */
  269. #define OB_IWDG_SW ((uint8_t)0x20) /*!< Software IWDG selected */
  270. #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware IWDG selected */
  271. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  272. /**
  273. * @}
  274. */
  275. /** @defgroup FLASH_Option_Bytes_nRST_STOP
  276. * @{
  277. */
  278. #define OB_STOP_NoRST ((uint8_t)0x40) /*!< No reset generated when entering in STOP */
  279. #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
  280. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
  281. /**
  282. * @}
  283. */
  284. /** @defgroup FLASH_Option_Bytes_nRST_STDBY
  285. * @{
  286. */
  287. #define OB_STDBY_NoRST ((uint8_t)0x80) /*!< No reset generated when entering in STANDBY */
  288. #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
  289. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
  290. /**
  291. * @}
  292. */
  293. /** @defgroup FLASH_BOR_Reset_Level
  294. * @{
  295. */
  296. #define OB_BOR_LEVEL3 ((uint8_t)0x00) /*!< Supply voltage ranges from 2.70 to 3.60 V */
  297. #define OB_BOR_LEVEL2 ((uint8_t)0x04) /*!< Supply voltage ranges from 2.40 to 2.70 V */
  298. #define OB_BOR_LEVEL1 ((uint8_t)0x08) /*!< Supply voltage ranges from 2.10 to 2.40 V */
  299. #define OB_BOR_OFF ((uint8_t)0x0C) /*!< Supply voltage ranges from 1.62 to 2.10 V */
  300. #define IS_OB_BOR(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
  301. ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
  302. /**
  303. * @}
  304. */
  305. /** @defgroup FLASH_Dual_Boot
  306. * @{
  307. */
  308. #define OB_Dual_BootEnabled ((uint8_t)0x10) /*!< Dual Bank Boot Enable */
  309. #define OB_Dual_BootDisabled ((uint8_t)0x00) /*!< Dual Bank Boot Disable, always boot on User Flash */
  310. #define IS_OB_BOOT(BOOT) (((BOOT) == OB_Dual_BootEnabled) || ((BOOT) == OB_Dual_BootDisabled))
  311. /**
  312. * @}
  313. */
  314. /** @defgroup FLASH_Interrupts
  315. * @{
  316. */
  317. #define FLASH_IT_EOP ((uint32_t)0x01000000) /*!< End of FLASH Operation Interrupt source */
  318. #define FLASH_IT_ERR ((uint32_t)0x02000000) /*!< Error Interrupt source */
  319. #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFCFFFFFF) == 0x00000000) && ((IT) != 0x00000000))
  320. /**
  321. * @}
  322. */
  323. /** @defgroup FLASH_Flags
  324. * @{
  325. */
  326. #define FLASH_FLAG_EOP ((uint32_t)0x00000001) /*!< FLASH End of Operation flag */
  327. #define FLASH_FLAG_OPERR ((uint32_t)0x00000002) /*!< FLASH operation Error flag */
  328. #define FLASH_FLAG_WRPERR ((uint32_t)0x00000010) /*!< FLASH Write protected error flag */
  329. #define FLASH_FLAG_PGAERR ((uint32_t)0x00000020) /*!< FLASH Programming Alignment error flag */
  330. #define FLASH_FLAG_PGPERR ((uint32_t)0x00000040) /*!< FLASH Programming Parallelism error flag */
  331. #define FLASH_FLAG_PGSERR ((uint32_t)0x00000080) /*!< FLASH Programming Sequence error flag */
  332. #define FLASH_FLAG_RDERR ((uint32_t)0x00000100) /*!< Read Protection error flag (PCROP) */
  333. #define FLASH_FLAG_BSY ((uint32_t)0x00010000) /*!< FLASH Busy flag */
  334. #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFE0C) == 0x00000000) && ((FLAG) != 0x00000000))
  335. #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_EOP) || ((FLAG) == FLASH_FLAG_OPERR) || \
  336. ((FLAG) == FLASH_FLAG_WRPERR) || ((FLAG) == FLASH_FLAG_PGAERR) || \
  337. ((FLAG) == FLASH_FLAG_PGPERR) || ((FLAG) == FLASH_FLAG_PGSERR) || \
  338. ((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_RDERR))
  339. /**
  340. * @}
  341. */
  342. /** @defgroup FLASH_Program_Parallelism
  343. * @{
  344. */
  345. #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
  346. #define FLASH_PSIZE_HALF_WORD ((uint32_t)0x00000100)
  347. #define FLASH_PSIZE_WORD ((uint32_t)0x00000200)
  348. #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)0x00000300)
  349. #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
  350. /**
  351. * @}
  352. */
  353. /** @defgroup FLASH_Keys
  354. * @{
  355. */
  356. #define RDP_KEY ((uint16_t)0x00A5)
  357. #define FLASH_KEY1 ((uint32_t)0x45670123)
  358. #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
  359. #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
  360. #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
  361. /**
  362. * @}
  363. */
  364. /**
  365. * @brief ACR register byte 0 (Bits[7:0]) base address
  366. */
  367. #define ACR_BYTE0_ADDRESS ((uint32_t)0x40023C00)
  368. /**
  369. * @brief OPTCR register byte 0 (Bits[7:0]) base address
  370. */
  371. #define OPTCR_BYTE0_ADDRESS ((uint32_t)0x40023C14)
  372. /**
  373. * @brief OPTCR register byte 1 (Bits[15:8]) base address
  374. */
  375. #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
  376. /**
  377. * @brief OPTCR register byte 2 (Bits[23:16]) base address
  378. */
  379. #define OPTCR_BYTE2_ADDRESS ((uint32_t)0x40023C16)
  380. /**
  381. * @brief OPTCR register byte 3 (Bits[31:24]) base address
  382. */
  383. #define OPTCR_BYTE3_ADDRESS ((uint32_t)0x40023C17)
  384. /**
  385. * @brief OPTCR1 register byte 0 (Bits[7:0]) base address
  386. */
  387. #define OPTCR1_BYTE2_ADDRESS ((uint32_t)0x40023C1A)
  388. /**
  389. * @}
  390. */
  391. /* Exported macro ------------------------------------------------------------*/
  392. /* Exported functions --------------------------------------------------------*/
  393. /* FLASH Interface configuration functions ************************************/
  394. void FLASH_SetLatency(uint32_t FLASH_Latency);
  395. void FLASH_PrefetchBufferCmd(FunctionalState NewState);
  396. void FLASH_InstructionCacheCmd(FunctionalState NewState);
  397. void FLASH_DataCacheCmd(FunctionalState NewState);
  398. void FLASH_InstructionCacheReset(void);
  399. void FLASH_DataCacheReset(void);
  400. /* FLASH Memory Programming functions *****************************************/
  401. void FLASH_Unlock(void);
  402. void FLASH_Lock(void);
  403. FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);
  404. FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange);
  405. FLASH_Status FLASH_EraseAllBank1Sectors(uint8_t VoltageRange);
  406. FLASH_Status FLASH_EraseAllBank2Sectors(uint8_t VoltageRange);
  407. FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data);
  408. FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
  409. FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
  410. FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);
  411. /* Option Bytes Programming functions *****************************************/
  412. void FLASH_OB_Unlock(void);
  413. void FLASH_OB_Lock(void);
  414. void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState);
  415. void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState);
  416. void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PcROP);
  417. void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState);
  418. void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState);
  419. void FLASH_OB_RDPConfig(uint8_t OB_RDP);
  420. void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY);
  421. void FLASH_OB_BORConfig(uint8_t OB_BOR);
  422. void FLASH_OB_BootConfig(uint8_t OB_BOOT);
  423. FLASH_Status FLASH_OB_Launch(void);
  424. uint8_t FLASH_OB_GetUser(void);
  425. uint16_t FLASH_OB_GetWRP(void);
  426. uint16_t FLASH_OB_GetWRP1(void);
  427. uint16_t FLASH_OB_GetPCROP(void);
  428. uint16_t FLASH_OB_GetPCROP1(void);
  429. FlagStatus FLASH_OB_GetRDP(void);
  430. uint8_t FLASH_OB_GetBOR(void);
  431. /* Interrupts and flags management functions **********************************/
  432. void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
  433. FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
  434. void FLASH_ClearFlag(uint32_t FLASH_FLAG);
  435. FLASH_Status FLASH_GetStatus(void);
  436. FLASH_Status FLASH_WaitForLastOperation(void);
  437. #ifdef __cplusplus
  438. }
  439. #endif
  440. #endif /* __STM32F4xx_FLASH_H */
  441. /**
  442. * @}
  443. */
  444. /**
  445. * @}
  446. */
  447. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/