stm32g4xx_hal_flash.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. ******************************************************************************
  16. */
  17. /* Define to prevent recursive inclusion -------------------------------------*/
  18. #ifndef STM32G4xx_HAL_FLASH_H
  19. #define STM32G4xx_HAL_FLASH_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32g4xx_hal_def.h"
  25. /** @addtogroup STM32G4xx_HAL_Driver
  26. * @{
  27. */
  28. /** @addtogroup FLASH
  29. * @{
  30. */
  31. /* Exported types ------------------------------------------------------------*/
  32. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  33. * @{
  34. */
  35. /**
  36. * @brief FLASH Erase structure definition
  37. */
  38. typedef struct
  39. {
  40. uint32_t TypeErase; /*!< Mass erase or page erase.
  41. This parameter can be a value of @ref FLASH_Type_Erase */
  42. uint32_t Banks; /*!< Select bank to erase.
  43. This parameter must be a value of @ref FLASH_Banks
  44. (FLASH_BANK_BOTH should be used only for mass erase) */
  45. uint32_t Page; /*!< Initial Flash page to erase when page erase is disabled.
  46. This parameter must be a value between 0 and (max number of pages in the bank - 1)
  47. (eg : 127 for 512KB dual bank) */
  48. uint32_t NbPages; /*!< Number of pages to be erased.
  49. This parameter must be a value between 1 and (max number of pages in the bank - value of initial page)*/
  50. } FLASH_EraseInitTypeDef;
  51. /**
  52. * @brief FLASH Option Bytes Program structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t OptionType; /*!< Option byte to be configured.
  57. This parameter can be a combination of the values of @ref FLASH_OB_Type */
  58. uint32_t WRPArea; /*!< Write protection area to be programmed (used for OPTIONBYTE_WRP).
  59. Only one WRP area could be programmed at the same time.
  60. This parameter can be value of @ref FLASH_OB_WRP_Area */
  61. uint32_t WRPStartOffset; /*!< Write protection start offset (used for OPTIONBYTE_WRP).
  62. This parameter must be a value between 0 and (max number of pages in the bank - 1) */
  63. uint32_t WRPEndOffset; /*!< Write protection end offset (used for OPTIONBYTE_WRP).
  64. This parameter must be a value between WRPStartOffset and (max number of pages in the bank - 1) */
  65. uint32_t RDPLevel; /*!< Set the read protection level.. (used for OPTIONBYTE_RDP).
  66. This parameter can be a value of @ref FLASH_OB_Read_Protection */
  67. uint32_t USERType; /*!< User option byte(s) to be configured (used for OPTIONBYTE_USER).
  68. This parameter can be a combination of @ref FLASH_OB_USER_Type */
  69. uint32_t USERConfig; /*!< Value of the user option byte (used for OPTIONBYTE_USER).
  70. This parameter can be a combination of @ref FLASH_OB_USER_BOR_LEVEL,
  71. @ref FLASH_OB_USER_nRST_STOP, @ref FLASH_OB_USER_nRST_STANDBY,
  72. @ref FLASH_OB_USER_nRST_SHUTDOWN, @ref FLASH_OB_USER_IWDG_SW,
  73. @ref FLASH_OB_USER_IWDG_STOP, @ref FLASH_OB_USER_IWDG_STANDBY,
  74. @ref FLASH_OB_USER_WWDG_SW, @ref FLASH_OB_USER_BFB2 (*),
  75. @ref FLASH_OB_USER_nBOOT1, @ref FLASH_OB_USER_SRAM_PE,
  76. @ref FLASH_OB_USER_CCMSRAM_RST
  77. @note (*) availability depends on devices */
  78. uint32_t PCROPConfig; /*!< Configuration of the PCROP (used for OPTIONBYTE_PCROP).
  79. This parameter must be a combination of @ref FLASH_Banks (except FLASH_BANK_BOTH)
  80. and @ref FLASH_OB_PCROP_RDP */
  81. uint32_t PCROPStartAddr; /*!< PCROP Start address (used for OPTIONBYTE_PCROP).
  82. This parameter must be a value between begin and end of bank
  83. => Be careful of the bank swapping for the address */
  84. uint32_t PCROPEndAddr; /*!< PCROP End address (used for OPTIONBYTE_PCROP).
  85. This parameter must be a value between PCROP Start address and end of bank */
  86. uint32_t BootEntryPoint; /*!< Set the Boot Lock (used for OPTIONBYTE_BOOT_LOCK).
  87. This parameter can be a value of @ref FLASH_OB_Boot_Lock */
  88. uint32_t SecBank; /*!< Bank of securable memory area to be programmed (used for OPTIONBYTE_SEC).
  89. Only one securable memory area could be programmed at the same time.
  90. This parameter can be one of the following values:
  91. FLASH_BANK_1: Securable memory area to be programmed in bank 1
  92. FLASH_BANK_2: Securable memory area to be programmed in bank 2 (*)
  93. @note (*) availability depends on devices */
  94. uint32_t SecSize; /*!< Size of securable memory area to be programmed (used for OPTIONBYTE_SEC),
  95. in number of pages. Securable memory area is starting from first page of the bank.
  96. Only one securable memory could be programmed at the same time.
  97. This parameter must be a value between 0 and (max number of pages in the bank - 1) */
  98. } FLASH_OBProgramInitTypeDef;
  99. /**
  100. * @brief FLASH Procedure structure definition
  101. */
  102. typedef enum
  103. {
  104. FLASH_PROC_NONE = 0,
  105. FLASH_PROC_PAGE_ERASE,
  106. FLASH_PROC_MASS_ERASE,
  107. FLASH_PROC_PROGRAM,
  108. FLASH_PROC_PROGRAM_LAST
  109. } FLASH_ProcedureTypeDef;
  110. /**
  111. * @brief FLASH Cache structure definition
  112. */
  113. typedef enum
  114. {
  115. FLASH_CACHE_DISABLED = 0,
  116. FLASH_CACHE_ICACHE_ENABLED,
  117. FLASH_CACHE_DCACHE_ENABLED,
  118. FLASH_CACHE_ICACHE_DCACHE_ENABLED
  119. } FLASH_CacheTypeDef;
  120. /**
  121. * @brief FLASH handle Structure definition
  122. */
  123. typedef struct
  124. {
  125. HAL_LockTypeDef Lock; /* FLASH locking object */
  126. __IO uint32_t ErrorCode; /* FLASH error code */
  127. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
  128. __IO uint32_t Address; /* Internal variable to save address selected for program in IT context */
  129. __IO uint32_t Bank; /* Internal variable to save current bank selected during erase in IT context */
  130. __IO uint32_t Page; /* Internal variable to define the current page which is erasing in IT context */
  131. __IO uint32_t NbPagesToErase; /* Internal variable to save the remaining pages to erase in IT context */
  132. __IO FLASH_CacheTypeDef CacheToReactivate; /* Internal variable to indicate which caches should be reactivated */
  133. } FLASH_ProcessTypeDef;
  134. /**
  135. * @}
  136. */
  137. /* Exported constants --------------------------------------------------------*/
  138. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  139. * @{
  140. */
  141. /** @defgroup FLASH_Error FLASH Error
  142. * @{
  143. */
  144. #define HAL_FLASH_ERROR_NONE 0x00000000U
  145. #define HAL_FLASH_ERROR_OP FLASH_FLAG_OPERR
  146. #define HAL_FLASH_ERROR_PROG FLASH_FLAG_PROGERR
  147. #define HAL_FLASH_ERROR_WRP FLASH_FLAG_WRPERR
  148. #define HAL_FLASH_ERROR_PGA FLASH_FLAG_PGAERR
  149. #define HAL_FLASH_ERROR_SIZ FLASH_FLAG_SIZERR
  150. #define HAL_FLASH_ERROR_PGS FLASH_FLAG_PGSERR
  151. #define HAL_FLASH_ERROR_MIS FLASH_FLAG_MISERR
  152. #define HAL_FLASH_ERROR_FAST FLASH_FLAG_FASTERR
  153. #define HAL_FLASH_ERROR_RD FLASH_FLAG_RDERR
  154. #define HAL_FLASH_ERROR_OPTV FLASH_FLAG_OPTVERR
  155. #define HAL_FLASH_ERROR_ECCC FLASH_FLAG_ECCC
  156. #define HAL_FLASH_ERROR_ECCD FLASH_FLAG_ECCD
  157. #if defined (FLASH_OPTR_DBANK)
  158. #define HAL_FLASH_ERROR_ECCC2 FLASH_FLAG_ECCC2
  159. #define HAL_FLASH_ERROR_ECCD2 FLASH_FLAG_ECCD2
  160. #endif
  161. /**
  162. * @}
  163. */
  164. /** @defgroup FLASH_Type_Erase FLASH Erase Type
  165. * @{
  166. */
  167. #define FLASH_TYPEERASE_PAGES 0x00U /*!<Pages erase only*/
  168. #define FLASH_TYPEERASE_MASSERASE 0x01U /*!<Flash mass erase activation*/
  169. /**
  170. * @}
  171. */
  172. /** @defgroup FLASH_Banks FLASH Banks
  173. * @{
  174. */
  175. #define FLASH_BANK_1 0x00000001U /*!< Bank 1 */
  176. #if defined (FLASH_OPTR_DBANK)
  177. #define FLASH_BANK_2 0x00000002U /*!< Bank 2 */
  178. #define FLASH_BANK_BOTH (FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2 */
  179. #else
  180. #define FLASH_BANK_BOTH FLASH_BANK_1 /*!< Bank 1 */
  181. #endif
  182. /**
  183. * @}
  184. */
  185. /** @defgroup FLASH_Type_Program FLASH Program Type
  186. * @{
  187. */
  188. #define FLASH_TYPEPROGRAM_DOUBLEWORD 0x00U /*!< Program a double-word (64-bit) at a specified address.*/
  189. #define FLASH_TYPEPROGRAM_FAST 0x01U /*!< Fast program a 32 row double-word (64-bit) at a specified address.
  190. And another 32 row double-word (64-bit) will be programmed */
  191. #define FLASH_TYPEPROGRAM_FAST_AND_LAST 0x02U /*!< Fast program a 32 row double-word (64-bit) at a specified address.
  192. And this is the last 32 row double-word (64-bit) programmed */
  193. /**
  194. * @}
  195. */
  196. /** @defgroup FLASH_OB_Type FLASH Option Bytes Type
  197. * @{
  198. */
  199. #define OPTIONBYTE_WRP 0x01U /*!< WRP option byte configuration */
  200. #define OPTIONBYTE_RDP 0x02U /*!< RDP option byte configuration */
  201. #define OPTIONBYTE_USER 0x04U /*!< USER option byte configuration */
  202. #define OPTIONBYTE_PCROP 0x08U /*!< PCROP option byte configuration */
  203. #define OPTIONBYTE_BOOT_LOCK 0x10U /*!< Boot lock option byte configuration */
  204. #define OPTIONBYTE_SEC 0x20U /*!< Securable memory option byte configuration */
  205. /**
  206. * @}
  207. */
  208. /** @defgroup FLASH_OB_WRP_Area FLASH WRP Area
  209. * @{
  210. */
  211. #define OB_WRPAREA_BANK1_AREAA 0x00U /*!< Flash Bank 1 Area A */
  212. #define OB_WRPAREA_BANK1_AREAB 0x01U /*!< Flash Bank 1 Area B */
  213. #if defined (FLASH_OPTR_DBANK)
  214. #define OB_WRPAREA_BANK2_AREAA 0x02U /*!< Flash Bank 2 Area A */
  215. #define OB_WRPAREA_BANK2_AREAB 0x04U /*!< Flash Bank 2 Area B */
  216. #endif
  217. /**
  218. * @}
  219. */
  220. /** @defgroup FLASH_OB_Boot_Lock FLASH Boot Lock
  221. * @{
  222. */
  223. #define OB_BOOT_LOCK_DISABLE 0x00000000U /*!< Boot Lock Disable */
  224. #define OB_BOOT_LOCK_ENABLE FLASH_SEC1R_BOOT_LOCK /*!< Boot Lock Enable */
  225. /**
  226. * @}
  227. */
  228. /** @defgroup FLASH_OB_Read_Protection FLASH Option Bytes Read Protection
  229. * @{
  230. */
  231. #define OB_RDP_LEVEL_0 0xAAU
  232. #define OB_RDP_LEVEL_1 0xBBU
  233. #define OB_RDP_LEVEL_2 0xCCU /*!< Warning: When enabling read protection level 2
  234. it's no more possible to go back to level 1 or 0 */
  235. /**
  236. * @}
  237. */
  238. /** @defgroup FLASH_OB_USER_Type FLASH Option Bytes User Type
  239. * @{
  240. */
  241. #define OB_USER_BOR_LEV 0x00000001U /*!< BOR reset Level */
  242. #define OB_USER_nRST_STOP 0x00000002U /*!< Reset generated when entering the stop mode */
  243. #define OB_USER_nRST_STDBY 0x00000004U /*!< Reset generated when entering the standby mode */
  244. #define OB_USER_IWDG_SW 0x00000008U /*!< Independent watchdog selection */
  245. #define OB_USER_IWDG_STOP 0x00000010U /*!< Independent watchdog counter freeze in stop mode */
  246. #define OB_USER_IWDG_STDBY 0x00000020U /*!< Independent watchdog counter freeze in standby mode */
  247. #define OB_USER_WWDG_SW 0x00000040U /*!< Window watchdog selection */
  248. #if defined (FLASH_OPTR_DBANK)
  249. #define OB_USER_BFB2 0x00000080U /*!< Dual-bank boot */
  250. #define OB_USER_DBANK 0x00000100U /*!< Single bank with 128-bits data or two banks with 64-bits data */
  251. #endif
  252. #if defined (FLASH_OPTR_PB4_PUPEN)
  253. #define OB_USER_PB4_PUPEN 0x00000100U /*!< USB power delivery dead-battery/TDI pull-up */
  254. #endif
  255. #define OB_USER_nBOOT1 0x00000200U /*!< Boot configuration */
  256. #define OB_USER_SRAM_PE 0x00000400U /*!< SRAM parity check enable (first 32kB of SRAM1 + CCM SRAM) */
  257. #define OB_USER_CCMSRAM_RST 0x00000800U /*!< CCMSRAM Erase when system reset */
  258. #define OB_USER_nRST_SHDW 0x00001000U /*!< Reset generated when entering the shutdown mode */
  259. #define OB_USER_nSWBOOT0 0x00002000U /*!< Software BOOT0 */
  260. #define OB_USER_nBOOT0 0x00004000U /*!< nBOOT0 option bit */
  261. #define OB_USER_NRST_MODE 0x00008000U /*!< Reset pin configuration */
  262. #define OB_USER_IRHEN 0x00010000U /*!< Internal Reset Holder enable */
  263. /**
  264. * @}
  265. */
  266. /** @defgroup FLASH_OB_USER_BOR_LEVEL FLASH Option Bytes User BOR Level
  267. * @{
  268. */
  269. #define OB_BOR_LEVEL_0 FLASH_OPTR_BOR_LEV_0 /*!< Reset level threshold is around 1.7V */
  270. #define OB_BOR_LEVEL_1 FLASH_OPTR_BOR_LEV_1 /*!< Reset level threshold is around 2.0V */
  271. #define OB_BOR_LEVEL_2 FLASH_OPTR_BOR_LEV_2 /*!< Reset level threshold is around 2.2V */
  272. #define OB_BOR_LEVEL_3 FLASH_OPTR_BOR_LEV_3 /*!< Reset level threshold is around 2.5V */
  273. #define OB_BOR_LEVEL_4 FLASH_OPTR_BOR_LEV_4 /*!< Reset level threshold is around 2.8V */
  274. /**
  275. * @}
  276. */
  277. /** @defgroup FLASH_OB_USER_nRST_STOP FLASH Option Bytes User Reset On Stop
  278. * @{
  279. */
  280. #define OB_STOP_RST 0x00000000U /*!< Reset generated when entering the stop mode */
  281. #define OB_STOP_NORST FLASH_OPTR_nRST_STOP /*!< No reset generated when entering the stop mode */
  282. /**
  283. * @}
  284. */
  285. /** @defgroup FLASH_OB_USER_nRST_STANDBY FLASH Option Bytes User Reset On Standby
  286. * @{
  287. */
  288. #define OB_STANDBY_RST 0x00000000U /*!< Reset generated when entering the standby mode */
  289. #define OB_STANDBY_NORST FLASH_OPTR_nRST_STDBY /*!< No reset generated when entering the standby mode */
  290. /**
  291. * @}
  292. */
  293. /** @defgroup FLASH_OB_USER_nRST_SHUTDOWN FLASH Option Bytes User Reset On Shutdown
  294. * @{
  295. */
  296. #define OB_SHUTDOWN_RST 0x00000000U /*!< Reset generated when entering the shutdown mode */
  297. #define OB_SHUTDOWN_NORST FLASH_OPTR_nRST_SHDW /*!< No reset generated when entering the shutdown mode */
  298. /**
  299. * @}
  300. */
  301. /** @defgroup FLASH_OB_USER_IWDG_SW FLASH Option Bytes User IWDG Type
  302. * @{
  303. */
  304. #define OB_IWDG_HW 0x00000000U /*!< Hardware independent watchdog */
  305. #define OB_IWDG_SW FLASH_OPTR_IWDG_SW /*!< Software independent watchdog */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup FLASH_OB_USER_IWDG_STOP FLASH Option Bytes User IWDG Mode On Stop
  310. * @{
  311. */
  312. #define OB_IWDG_STOP_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen in Stop mode */
  313. #define OB_IWDG_STOP_RUN FLASH_OPTR_IWDG_STOP /*!< Independent watchdog counter is running in Stop mode */
  314. /**
  315. * @}
  316. */
  317. /** @defgroup FLASH_OB_USER_IWDG_STANDBY FLASH Option Bytes User IWDG Mode On Standby
  318. * @{
  319. */
  320. #define OB_IWDG_STDBY_FREEZE 0x00000000U /*!< Independent watchdog counter is frozen in Standby mode */
  321. #define OB_IWDG_STDBY_RUN FLASH_OPTR_IWDG_STDBY /*!< Independent watchdog counter is running in Standby mode */
  322. /**
  323. * @}
  324. */
  325. /** @defgroup FLASH_OB_USER_WWDG_SW FLASH Option Bytes User WWDG Type
  326. * @{
  327. */
  328. #define OB_WWDG_HW 0x00000000U /*!< Hardware window watchdog */
  329. #define OB_WWDG_SW FLASH_OPTR_WWDG_SW /*!< Software window watchdog */
  330. /**
  331. * @}
  332. */
  333. #if defined (FLASH_OPTR_DBANK)
  334. /** @defgroup FLASH_OB_USER_BFB2 FLASH Option Bytes User BFB2 Mode
  335. * @{
  336. */
  337. #define OB_BFB2_DISABLE 0x00000000U /*!< Dual-bank boot disable */
  338. #define OB_BFB2_ENABLE FLASH_OPTR_BFB2 /*!< Dual-bank boot enable */
  339. /**
  340. * @}
  341. */
  342. /** @defgroup FLASH_OB_USER_DBANK FLASH Option Bytes User DBANK Type
  343. * @{
  344. */
  345. #define OB_DBANK_128_BITS 0x00000000U /*!< Single-bank with 128-bits data */
  346. #define OB_DBANK_64_BITS FLASH_OPTR_DBANK /*!< Dual-bank with 64-bits data */
  347. /**
  348. * @}
  349. */
  350. #endif
  351. #if defined (FLASH_OPTR_PB4_PUPEN)
  352. /** @defgroup FLASH_OB_USER_PB4_PUPEN FLASH Option Bytes User PB4 PUPEN bit
  353. * @{
  354. */
  355. #define OB_PB4_PUPEN_DISABLE 0x00000000U /*!< USB power delivery dead-battery enabled/ TDI pull-up deactivated */
  356. #define OB_PB4_PUPEN_ENABLE FLASH_OPTR_PB4_PUPEN /*!< USB power delivery dead-battery disabled/ TDI pull-up activated */
  357. /**
  358. * @}
  359. */
  360. #endif
  361. /** @defgroup FLASH_OB_USER_nBOOT1 FLASH Option Bytes User BOOT1 Type
  362. * @{
  363. */
  364. #define OB_BOOT1_SRAM 0x00000000U /*!< Embedded SRAM1 is selected as boot space (if BOOT0=1) */
  365. #define OB_BOOT1_SYSTEM FLASH_OPTR_nBOOT1 /*!< System memory is selected as boot space (if BOOT0=1) */
  366. /**
  367. * @}
  368. */
  369. /** @defgroup FLASH_OB_USER_SRAM_PE FLASH Option Bytes User SRAM Parity Check Type
  370. * @{
  371. */
  372. #define OB_SRAM_PARITY_ENABLE 0x00000000U /*!< SRAM parity check enable (first 32kB of SRAM1 + CCM SRAM) */
  373. #define OB_SRAM_PARITY_DISABLE FLASH_OPTR_SRAM_PE /*!< SRAM parity check disable (first 32kB of SRAM1 + CCM SRAM) */
  374. /**
  375. * @}
  376. */
  377. /** @defgroup FLASH_OB_USER_CCMSRAM_RST FLASH Option Bytes User CCMSRAM Erase On Reset Type
  378. * @{
  379. */
  380. #define OB_CCMSRAM_RST_ERASE 0x00000000U /*!< CCMSRAM erased when a system reset occurs */
  381. #define OB_CCMSRAM_RST_NOT_ERASE FLASH_OPTR_CCMSRAM_RST /*!< CCMSRAM is not erased when a system reset occurs */
  382. /**
  383. * @}
  384. */
  385. /** @defgroup FLASH_OB_USER_nSWBOOT0 FLASH Option Bytes User Software BOOT0
  386. * @{
  387. */
  388. #define OB_BOOT0_FROM_OB 0x00000000U /*!< BOOT0 taken from the option bit nBOOT0 */
  389. #define OB_BOOT0_FROM_PIN FLASH_OPTR_nSWBOOT0 /*!< BOOT0 taken from PB8/BOOT0 pin */
  390. /**
  391. * @}
  392. */
  393. /** @defgroup FLASH_OB_USER_nBOOT0 FLASH Option Bytes User nBOOT0 option bit
  394. * @{
  395. */
  396. #define OB_nBOOT0_RESET 0x00000000U /*!< nBOOT0 = 0 */
  397. #define OB_nBOOT0_SET FLASH_OPTR_nBOOT0 /*!< nBOOT0 = 1 */
  398. /**
  399. * @}
  400. */
  401. /** @defgroup FLASH_OB_USER_NRST_MODE FLASH Option Bytes User NRST mode bit
  402. * @{
  403. */
  404. #define OB_NRST_MODE_INPUT_ONLY FLASH_OPTR_NRST_MODE_0 /*!< Reset pin is in Reset input mode only */
  405. #define OB_NRST_MODE_GPIO FLASH_OPTR_NRST_MODE_1 /*!< Reset pin is in GPIO mode only */
  406. #define OB_NRST_MODE_INPUT_OUTPUT FLASH_OPTR_NRST_MODE /*!< Reset pin is in reset input and output mode */
  407. /**
  408. * @}
  409. */
  410. /** @defgroup FLASH_OB_USER_INTERNAL_RESET_HOLDER FLASH Option Bytes User internal reset holder bit
  411. * @{
  412. */
  413. #define OB_IRH_DISABLE 0x00000000U /*!< Internal Reset holder disable */
  414. #define OB_IRH_ENABLE FLASH_OPTR_IRHEN /*!< Internal Reset holder enable */
  415. /**
  416. * @}
  417. */
  418. /** @defgroup FLASH_OB_PCROP_RDP FLASH Option Bytes PCROP On RDP Level Type
  419. * @{
  420. */
  421. #define OB_PCROP_RDP_NOT_ERASE 0x00000000U /*!< PCROP area is not erased when the RDP level
  422. is decreased from Level 1 to Level 0 */
  423. #define OB_PCROP_RDP_ERASE FLASH_PCROP1ER_PCROP_RDP /*!< PCROP area is erased when the RDP level is
  424. decreased from Level 1 to Level 0 (full mass erase) */
  425. /**
  426. * @}
  427. */
  428. /** @defgroup FLASH_Latency FLASH Latency
  429. * @{
  430. */
  431. #define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero wait state */
  432. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One wait state */
  433. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two wait states */
  434. #define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three wait states */
  435. #define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four wait states */
  436. #define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five wait state */
  437. #define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six wait state */
  438. #define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven wait states */
  439. #define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight wait states */
  440. #define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine wait states */
  441. #define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten wait state */
  442. #define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven wait state */
  443. #define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve wait states */
  444. #define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen wait states */
  445. #define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen wait states */
  446. #define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen wait states */
  447. /**
  448. * @}
  449. */
  450. /** @defgroup FLASH_Keys FLASH Keys
  451. * @{
  452. */
  453. #define FLASH_KEY1 0x45670123U /*!< Flash key1 */
  454. #define FLASH_KEY2 0xCDEF89ABU /*!< Flash key2: used with FLASH_KEY1
  455. to unlock the FLASH registers access */
  456. #define FLASH_PDKEY1 0x04152637U /*!< Flash power down key1 */
  457. #define FLASH_PDKEY2 0xFAFBFCFDU /*!< Flash power down key2: used with FLASH_PDKEY1
  458. to unlock the RUN_PD bit in FLASH_ACR */
  459. #define FLASH_OPTKEY1 0x08192A3BU /*!< Flash option byte key1 */
  460. #define FLASH_OPTKEY2 0x4C5D6E7FU /*!< Flash option byte key2: used with FLASH_OPTKEY1
  461. to allow option bytes operations */
  462. /**
  463. * @}
  464. */
  465. /** @defgroup FLASH_Flags FLASH Flags Definition
  466. * @{
  467. */
  468. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of operation flag */
  469. #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH Operation error flag */
  470. #define FLASH_FLAG_PROGERR FLASH_SR_PROGERR /*!< FLASH Programming error flag */
  471. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protection error flag */
  472. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming alignment error flag */
  473. #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */
  474. #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming sequence error flag */
  475. #define FLASH_FLAG_MISERR FLASH_SR_MISERR /*!< FLASH Fast programming data miss error flag */
  476. #define FLASH_FLAG_FASTERR FLASH_SR_FASTERR /*!< FLASH Fast programming error flag */
  477. #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH PCROP read error flag */
  478. #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option validity error flag */
  479. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  480. #define FLASH_FLAG_ECCC FLASH_ECCR_ECCC /*!< FLASH ECC correction in 64 LSB bits */
  481. #define FLASH_FLAG_ECCD FLASH_ECCR_ECCD /*!< FLASH ECC detection in 64 LSB bits */
  482. #if defined (FLASH_OPTR_DBANK)
  483. #define FLASH_FLAG_ECCC2 FLASH_ECCR_ECCC2 /*!< FLASH ECC correction in 64 MSB bits (mode 128 bits only) */
  484. #define FLASH_FLAG_ECCD2 FLASH_ECCR_ECCD2 /*!< FLASH ECC detection in 64 MSB bits (mode 128 bits only) */
  485. #endif
  486. #define FLASH_FLAG_SR_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \
  487. FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \
  488. FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | FLASH_FLAG_RDERR | \
  489. FLASH_FLAG_OPTVERR)
  490. #if defined (FLASH_OPTR_DBANK)
  491. #define FLASH_FLAG_ECCR_ERRORS (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD | FLASH_FLAG_ECCC2 | FLASH_FLAG_ECCD2)
  492. #else
  493. #define FLASH_FLAG_ECCR_ERRORS (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)
  494. #endif
  495. #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_SR_ERRORS | FLASH_FLAG_ECCR_ERRORS)
  496. /**
  497. * @}
  498. */
  499. /** @defgroup FLASH_Interrupt_definition FLASH Interrupts Definition
  500. * @brief FLASH Interrupt definition
  501. * @{
  502. */
  503. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  504. #define FLASH_IT_OPERR FLASH_CR_ERRIE /*!< Error Interrupt source */
  505. #define FLASH_IT_RDERR FLASH_CR_RDERRIE /*!< PCROP Read Error Interrupt source*/
  506. #define FLASH_IT_ECCC (FLASH_ECCR_ECCIE >> 24U) /*!< ECC Correction Interrupt source */
  507. /**
  508. * @}
  509. */
  510. /**
  511. * @}
  512. */
  513. /* Exported macros -----------------------------------------------------------*/
  514. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  515. * @brief macros to control FLASH features
  516. * @{
  517. */
  518. /**
  519. * @brief Set the FLASH Latency.
  520. * @param __LATENCY__ FLASH Latency.
  521. * This parameter can be one of the following values :
  522. * @arg FLASH_LATENCY_0: FLASH Zero wait state
  523. * @arg FLASH_LATENCY_1: FLASH One wait state
  524. * @arg FLASH_LATENCY_2: FLASH Two wait states
  525. * @arg FLASH_LATENCY_3: FLASH Three wait states
  526. * @arg FLASH_LATENCY_4: FLASH Four wait states
  527. * @arg FLASH_LATENCY_5: FLASH Five wait states
  528. * @arg FLASH_LATENCY_6: FLASH Six wait states
  529. * @arg FLASH_LATENCY_7: FLASH Seven wait states
  530. * @arg FLASH_LATENCY_8: FLASH Eight wait states
  531. * @arg FLASH_LATENCY_9: FLASH Nine wait states
  532. * @arg FLASH_LATENCY_10: FLASH Ten wait state
  533. * @arg FLASH_LATENCY_11: FLASH Eleven wait state
  534. * @arg FLASH_LATENCY_12: FLASH Twelve wait states
  535. * @arg FLASH_LATENCY_13: FLASH Thirteen wait states
  536. * @arg FLASH_LATENCY_14: FLASH Fourteen wait states
  537. * @arg FLASH_LATENCY_15: FLASH Fifteen wait states
  538. * @retval None
  539. */
  540. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__))
  541. /**
  542. * @brief Get the FLASH Latency.
  543. * @retval FLASH_Latency.
  544. * This parameter can be one of the following values :
  545. * @arg FLASH_LATENCY_0: FLASH Zero wait state
  546. * @arg FLASH_LATENCY_1: FLASH One wait state
  547. * @arg FLASH_LATENCY_2: FLASH Two wait states
  548. * @arg FLASH_LATENCY_3: FLASH Three wait states
  549. * @arg FLASH_LATENCY_4: FLASH Four wait states
  550. * @arg FLASH_LATENCY_5: FLASH Five wait states
  551. * @arg FLASH_LATENCY_6: FLASH Six wait states
  552. * @arg FLASH_LATENCY_7: FLASH Seven wait states
  553. * @arg FLASH_LATENCY_8: FLASH Eight wait states
  554. * @arg FLASH_LATENCY_9: FLASH Nine wait states
  555. * @arg FLASH_LATENCY_10: FLASH Ten wait state
  556. * @arg FLASH_LATENCY_11: FLASH Eleven wait state
  557. * @arg FLASH_LATENCY_12: FLASH Twelve wait states
  558. * @arg FLASH_LATENCY_13: FLASH Thirteen wait states
  559. * @arg FLASH_LATENCY_14: FLASH Fourteen wait states
  560. * @arg FLASH_LATENCY_15: FLASH Fifteen wait states
  561. */
  562. #define __HAL_FLASH_GET_LATENCY() READ_BIT(FLASH->ACR, FLASH_ACR_LATENCY)
  563. /**
  564. * @brief Enable the FLASH prefetch buffer.
  565. * @retval None
  566. */
  567. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_PRFTEN)
  568. /**
  569. * @brief Disable the FLASH prefetch buffer.
  570. * @retval None
  571. */
  572. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_PRFTEN)
  573. /**
  574. * @brief Enable the FLASH instruction cache.
  575. * @retval none
  576. */
  577. #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ICEN)
  578. /**
  579. * @brief Disable the FLASH instruction cache.
  580. * @retval none
  581. */
  582. #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICEN)
  583. /**
  584. * @brief Enable the FLASH data cache.
  585. * @retval none
  586. */
  587. #define __HAL_FLASH_DATA_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_DCEN)
  588. /**
  589. * @brief Disable the FLASH data cache.
  590. * @retval none
  591. */
  592. #define __HAL_FLASH_DATA_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_DCEN)
  593. /**
  594. * @brief Reset the FLASH instruction Cache.
  595. * @note This function must be used only when the Instruction Cache is disabled.
  596. * @retval None
  597. */
  598. #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_ICRST); \
  599. CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICRST); \
  600. } while (0)
  601. /**
  602. * @brief Reset the FLASH data Cache.
  603. * @note This function must be used only when the data Cache is disabled.
  604. * @retval None
  605. */
  606. #define __HAL_FLASH_DATA_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_DCRST); \
  607. CLEAR_BIT(FLASH->ACR, FLASH_ACR_DCRST); \
  608. } while (0)
  609. /**
  610. * @brief Enable the FLASH power down during Low-power run mode.
  611. * @note Writing this bit to 1, automatically the keys are
  612. * lost and a new unlock sequence is necessary to re-write it to 0.
  613. */
  614. #define __HAL_FLASH_POWER_DOWN_ENABLE() do { WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY1); \
  615. WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY2); \
  616. SET_BIT(FLASH->ACR, FLASH_ACR_RUN_PD); \
  617. } while (0)
  618. /**
  619. * @brief Disable the FLASH power down during Low-power run mode.
  620. * @note Writing this bit to 0, automatically the keys are
  621. * lost and a new unlock sequence is necessary to re-write it to 1.
  622. */
  623. #define __HAL_FLASH_POWER_DOWN_DISABLE() do { WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY1); \
  624. WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY2); \
  625. CLEAR_BIT(FLASH->ACR, FLASH_ACR_RUN_PD); \
  626. } while (0)
  627. /**
  628. * @brief Enable the FLASH power down during Low-Power sleep mode
  629. * @retval none
  630. */
  631. #define __HAL_FLASH_SLEEP_POWERDOWN_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
  632. /**
  633. * @brief Disable the FLASH power down during Low-Power sleep mode
  634. * @retval none
  635. */
  636. #define __HAL_FLASH_SLEEP_POWERDOWN_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
  637. /**
  638. * @}
  639. */
  640. /** @defgroup FLASH_Interrupt FLASH Interrupts Macros
  641. * @brief macros to handle FLASH interrupts
  642. * @{
  643. */
  644. /**
  645. * @brief Enable the specified FLASH interrupt.
  646. * @param __INTERRUPT__ FLASH interrupt
  647. * This parameter can be any combination of the following values:
  648. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  649. * @arg FLASH_IT_OPERR: Error Interrupt
  650. * @arg FLASH_IT_RDERR: PCROP Read Error Interrupt
  651. * @arg FLASH_IT_ECCC: ECC Correction Interrupt
  652. * @retval none
  653. */
  654. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { SET_BIT(FLASH->ECCR, FLASH_ECCR_ECCIE); }\
  655. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) { SET_BIT(FLASH->CR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); }\
  656. } while (0)
  657. /**
  658. * @brief Disable the specified FLASH interrupt.
  659. * @param __INTERRUPT__ FLASH interrupt
  660. * This parameter can be any combination of the following values:
  661. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  662. * @arg FLASH_IT_OPERR: Error Interrupt
  663. * @arg FLASH_IT_RDERR: PCROP Read Error Interrupt
  664. * @arg FLASH_IT_ECCC: ECC Correction Interrupt
  665. * @retval none
  666. */
  667. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { CLEAR_BIT(FLASH->ECCR, FLASH_ECCR_ECCIE); }\
  668. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) { CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); }\
  669. } while (0)
  670. /**
  671. * @brief Check whether the specified FLASH flag is set or not.
  672. * @param __FLAG__ specifies the FLASH flag to check.
  673. * This parameter can be one of the following values:
  674. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  675. * @arg FLASH_FLAG_OPERR: FLASH Operation error flag
  676. * @arg FLASH_FLAG_PROGERR: FLASH Programming error flag
  677. * @arg FLASH_FLAG_WRPERR: FLASH Write protection error flag
  678. * @arg FLASH_FLAG_PGAERR: FLASH Programming alignment error flag
  679. * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
  680. * @arg FLASH_FLAG_PGSERR: FLASH Programming sequence error flag
  681. * @arg FLASH_FLAG_MISERR: FLASH Fast programming data miss error flag
  682. * @arg FLASH_FLAG_FASTERR: FLASH Fast programming error flag
  683. * @arg FLASH_FLAG_RDERR: FLASH PCROP read error flag
  684. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
  685. * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag
  686. * @arg FLASH_FLAG_ECCC: FLASH one ECC error has been detected and corrected in 64 LSB bits
  687. * @arg FLASH_FLAG_ECCD: FLASH two ECC errors have been detected in 64 LSB bits
  688. * @arg FLASH_FLAG_ECCC2(*): FLASH one ECC error has been detected and corrected in 64 MSB bits (mode 128 bits only)
  689. * @arg FLASH_FLAG_ECCD2(*): FLASH two ECC errors have been detected in 64 MSB bits (mode 128 bits only)
  690. * @note (*) availability depends on devices
  691. * @retval The new state of FLASH_FLAG (SET or RESET).
  692. */
  693. #define __HAL_FLASH_GET_FLAG(__FLAG__) ((((__FLAG__) & FLASH_FLAG_ECCR_ERRORS) != 0U) ? \
  694. (READ_BIT(FLASH->ECCR, (__FLAG__)) == (__FLAG__)) : \
  695. (READ_BIT(FLASH->SR, (__FLAG__)) == (__FLAG__)))
  696. /**
  697. * @brief Clear the FLASH's pending flags.
  698. * @param __FLAG__ specifies the FLASH flags to clear.
  699. * This parameter can be any combination of the following values:
  700. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  701. * @arg FLASH_FLAG_OPERR: FLASH Operation error flag
  702. * @arg FLASH_FLAG_PROGERR: FLASH Programming error flag
  703. * @arg FLASH_FLAG_WRPERR: FLASH Write protection error flag
  704. * @arg FLASH_FLAG_PGAERR: FLASH Programming alignment error flag
  705. * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
  706. * @arg FLASH_FLAG_PGSERR: FLASH Programming sequence error flag
  707. * @arg FLASH_FLAG_MISERR: FLASH Fast programming data miss error flag
  708. * @arg FLASH_FLAG_FASTERR: FLASH Fast programming error flag
  709. * @arg FLASH_FLAG_RDERR: FLASH PCROP read error flag
  710. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
  711. * @arg FLASH_FLAG_ECCC: FLASH one ECC error has been detected and corrected in 64 LSB bits
  712. * @arg FLASH_FLAG_ECCD: FLASH two ECC errors have been detected in 64 LSB bits
  713. * @arg FLASH_FLAG_ECCC2(*): FLASH one ECC error has been detected and corrected in 64 MSB bits (mode 128 bits only)
  714. * @arg FLASH_FLAG_ECCD2(*): FLASH two ECC errors have been detected in 64 MSB bits (mode 128 bits only)
  715. * @arg FLASH_FLAG_SR_ERRORS: FLASH All SR errors flags
  716. * @arg FLASH_FLAG_ECCR_ERRORS: FLASH All ECCR errors flags
  717. * @note (*) availability depends on devices
  718. * @retval None
  719. */
  720. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { if(((__FLAG__) & FLASH_FLAG_ECCR_ERRORS) != 0U) { SET_BIT(FLASH->ECCR, ((__FLAG__) & FLASH_FLAG_ECCR_ERRORS)); }\
  721. if(((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS)) != 0U) { WRITE_REG(FLASH->SR, ((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS))); }\
  722. } while (0)
  723. /**
  724. * @}
  725. */
  726. /* Include FLASH HAL Extended module */
  727. #include "stm32g4xx_hal_flash_ex.h"
  728. #include "stm32g4xx_hal_flash_ramfunc.h"
  729. /* Exported variables --------------------------------------------------------*/
  730. /** @defgroup FLASH_Exported_Variables FLASH Exported Variables
  731. * @{
  732. */
  733. extern FLASH_ProcessTypeDef pFlash;
  734. /**
  735. * @}
  736. */
  737. /* Exported functions --------------------------------------------------------*/
  738. /** @addtogroup FLASH_Exported_Functions
  739. * @{
  740. */
  741. /* Program operation functions ***********************************************/
  742. /** @addtogroup FLASH_Exported_Functions_Group1
  743. * @{
  744. */
  745. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  746. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  747. /* FLASH IRQ handler method */
  748. void HAL_FLASH_IRQHandler(void);
  749. /* Callbacks in non blocking modes */
  750. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  751. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  752. /**
  753. * @}
  754. */
  755. /* Peripheral Control functions **********************************************/
  756. /** @addtogroup FLASH_Exported_Functions_Group2
  757. * @{
  758. */
  759. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  760. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  761. /* Option bytes control */
  762. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  763. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  764. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  765. /**
  766. * @}
  767. */
  768. /* Peripheral State functions ************************************************/
  769. /** @addtogroup FLASH_Exported_Functions_Group3
  770. * @{
  771. */
  772. uint32_t HAL_FLASH_GetError(void);
  773. /**
  774. * @}
  775. */
  776. /**
  777. * @}
  778. */
  779. /** @addtogroup FLASH_Private_Functions
  780. * @{
  781. */
  782. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  783. /**
  784. * @}
  785. */
  786. /* Private constants --------------------------------------------------------*/
  787. /** @defgroup FLASH_Private_Constants FLASH Private Constants
  788. * @{
  789. */
  790. #define FLASH_SIZE_DATA_REGISTER FLASHSIZE_BASE
  791. #if defined (FLASH_OPTR_DBANK)
  792. #define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x200UL << 10U) : \
  793. (((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))
  794. #define FLASH_BANK_SIZE (FLASH_SIZE >> 1)
  795. #define FLASH_PAGE_NB ((FLASH_SIZE == 0x00080000U) ? 128U : \
  796. ((FLASH_SIZE == 0x00040000U) ? 64U : 32U))
  797. #define FLASH_PAGE_SIZE_128_BITS 0x1000U /* 4 KB */
  798. #else
  799. #define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x80UL << 10U) : \
  800. (((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))
  801. #define FLASH_BANK_SIZE (FLASH_SIZE)
  802. #define FLASH_PAGE_NB ((FLASH_SIZE == 0x00080000U) ? 256U : \
  803. ((FLASH_SIZE == 0x00040000U) ? 128U : 64U))
  804. #endif
  805. #define FLASH_PAGE_SIZE 0x800U /* 2 KB */
  806. #define FLASH_TIMEOUT_VALUE 1000U /* 1 s */
  807. /**
  808. * @}
  809. */
  810. /* Private macros ------------------------------------------------------------*/
  811. /** @defgroup FLASH_Private_Macros FLASH Private Macros
  812. * @{
  813. */
  814. #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || \
  815. ((VALUE) == FLASH_TYPEERASE_MASSERASE))
  816. #if defined (FLASH_OPTR_DBANK)
  817. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  818. ((BANK) == FLASH_BANK_2) || \
  819. ((BANK) == FLASH_BANK_BOTH))
  820. #define IS_FLASH_BANK_EXCLUSIVE(BANK) (((BANK) == FLASH_BANK_1) || \
  821. ((BANK) == FLASH_BANK_2))
  822. #else
  823. #define IS_FLASH_BANK(BANK) ((BANK) == FLASH_BANK_1)
  824. #define IS_FLASH_BANK_EXCLUSIVE(BANK) ((BANK) == FLASH_BANK_1)
  825. #endif
  826. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD) || \
  827. ((VALUE) == FLASH_TYPEPROGRAM_FAST) || \
  828. ((VALUE) == FLASH_TYPEPROGRAM_FAST_AND_LAST))
  829. #define IS_FLASH_MAIN_MEM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE+FLASH_SIZE)))
  830. #define IS_FLASH_OTP_ADDRESS(ADDRESS) (((ADDRESS) >= 0x1FFF7000U) && ((ADDRESS) <= 0x1FFF73FFU))
  831. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (IS_FLASH_MAIN_MEM_ADDRESS(ADDRESS) || IS_FLASH_OTP_ADDRESS(ADDRESS))
  832. #define IS_FLASH_PAGE(PAGE) ((PAGE) < FLASH_PAGE_NB)
  833. #define IS_OPTIONBYTE(VALUE) (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_PCROP | \
  834. OPTIONBYTE_BOOT_LOCK | OPTIONBYTE_SEC)))
  835. #if defined (FLASH_OPTR_DBANK)
  836. #define IS_OB_WRPAREA(VALUE) (((VALUE) == OB_WRPAREA_BANK1_AREAA) || ((VALUE) == OB_WRPAREA_BANK1_AREAB) || \
  837. ((VALUE) == OB_WRPAREA_BANK2_AREAA) || ((VALUE) == OB_WRPAREA_BANK2_AREAB))
  838. #else
  839. #define IS_OB_WRPAREA(VALUE) (((VALUE) == OB_WRPAREA_BANK1_AREAA) || ((VALUE) == OB_WRPAREA_BANK1_AREAB))
  840. #endif
  841. #define IS_OB_BOOT_LOCK(VALUE) (((VALUE) == OB_BOOT_LOCK_ENABLE) || ((VALUE) == OB_BOOT_LOCK_DISABLE))
  842. #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
  843. ((LEVEL) == OB_RDP_LEVEL_1) ||\
  844. ((LEVEL) == OB_RDP_LEVEL_2))
  845. #define IS_OB_USER_TYPE(TYPE) (((TYPE) <= 0x1FFFFU) && ((TYPE) != 0U))
  846. #define IS_OB_USER_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL_0) || ((LEVEL) == OB_BOR_LEVEL_1) || \
  847. ((LEVEL) == OB_BOR_LEVEL_2) || ((LEVEL) == OB_BOR_LEVEL_3) || \
  848. ((LEVEL) == OB_BOR_LEVEL_4))
  849. #define IS_OB_USER_STOP(VALUE) (((VALUE) == OB_STOP_RST) || ((VALUE) == OB_STOP_NORST))
  850. #define IS_OB_USER_STANDBY(VALUE) (((VALUE) == OB_STANDBY_RST) || ((VALUE) == OB_STANDBY_NORST))
  851. #define IS_OB_USER_SHUTDOWN(VALUE) (((VALUE) == OB_SHUTDOWN_RST) || ((VALUE) == OB_SHUTDOWN_NORST))
  852. #define IS_OB_USER_IWDG(VALUE) (((VALUE) == OB_IWDG_HW) || ((VALUE) == OB_IWDG_SW))
  853. #define IS_OB_USER_IWDG_STOP(VALUE) (((VALUE) == OB_IWDG_STOP_FREEZE) || ((VALUE) == OB_IWDG_STOP_RUN))
  854. #define IS_OB_USER_IWDG_STDBY(VALUE) (((VALUE) == OB_IWDG_STDBY_FREEZE) || ((VALUE) == OB_IWDG_STDBY_RUN))
  855. #define IS_OB_USER_WWDG(VALUE) (((VALUE) == OB_WWDG_HW) || ((VALUE) == OB_WWDG_SW))
  856. #if defined (FLASH_OPTR_DBANK)
  857. #define IS_OB_USER_BFB2(VALUE) (((VALUE) == OB_BFB2_DISABLE) || ((VALUE) == OB_BFB2_ENABLE))
  858. #define IS_OB_USER_DBANK(VALUE) (((VALUE) == OB_DBANK_128_BITS) || ((VALUE) == OB_DBANK_64_BITS))
  859. #endif
  860. #if defined (FLASH_OPTR_PB4_PUPEN)
  861. #define IS_OB_USER_PB4_PUPEN(VALUE) (((VALUE) == OB_PB4_PUPEN_DISABLE) || ((VALUE) == OB_PB4_PUPEN_ENABLE))
  862. #endif
  863. #define IS_OB_USER_BOOT1(VALUE) (((VALUE) == OB_BOOT1_SRAM) || ((VALUE) == OB_BOOT1_SYSTEM))
  864. #define IS_OB_USER_SRAM_PARITY(VALUE) (((VALUE) == OB_SRAM_PARITY_ENABLE) || ((VALUE) == OB_SRAM_PARITY_DISABLE))
  865. #define IS_OB_USER_CCMSRAM_RST(VALUE) (((VALUE) == OB_CCMSRAM_RST_ERASE) || ((VALUE) == OB_CCMSRAM_RST_NOT_ERASE))
  866. #define IS_OB_USER_SWBOOT0(VALUE) (((VALUE) == OB_BOOT0_FROM_OB) || ((VALUE) == OB_BOOT0_FROM_PIN))
  867. #define IS_OB_USER_BOOT0(VALUE) (((VALUE) == OB_nBOOT0_RESET) || ((VALUE) == OB_nBOOT0_SET))
  868. #define IS_OB_USER_NRST_MODE(VALUE) (((VALUE) == OB_NRST_MODE_GPIO) || ((VALUE) == OB_NRST_MODE_INPUT_ONLY) || \
  869. ((VALUE) == OB_NRST_MODE_INPUT_OUTPUT))
  870. #define IS_OB_USER_IRHEN(VALUE) (((VALUE) == OB_IRH_ENABLE) || ((VALUE) == OB_IRH_DISABLE))
  871. #define IS_OB_PCROP_RDP(VALUE) (((VALUE) == OB_PCROP_RDP_NOT_ERASE) || ((VALUE) == OB_PCROP_RDP_ERASE))
  872. #define IS_OB_SECMEM_SIZE(VALUE) ((VALUE) <= FLASH_PAGE_NB)
  873. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || ((LATENCY) == FLASH_LATENCY_1) || \
  874. ((LATENCY) == FLASH_LATENCY_2) || ((LATENCY) == FLASH_LATENCY_3) || \
  875. ((LATENCY) == FLASH_LATENCY_4) || ((LATENCY) == FLASH_LATENCY_5) || \
  876. ((LATENCY) == FLASH_LATENCY_6) || ((LATENCY) == FLASH_LATENCY_7) || \
  877. ((LATENCY) == FLASH_LATENCY_8) || ((LATENCY) == FLASH_LATENCY_9) || \
  878. ((LATENCY) == FLASH_LATENCY_10) || ((LATENCY) == FLASH_LATENCY_11) || \
  879. ((LATENCY) == FLASH_LATENCY_12) || ((LATENCY) == FLASH_LATENCY_13) || \
  880. ((LATENCY) == FLASH_LATENCY_14) || ((LATENCY) == FLASH_LATENCY_15))
  881. /**
  882. * @}
  883. */
  884. /**
  885. * @}
  886. */
  887. /**
  888. * @}
  889. */
  890. #ifdef __cplusplus
  891. }
  892. #endif
  893. #endif /* STM32G4xx_HAL_FLASH_H */