stm32f7xx_hal_flash.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F7xx_HAL_FLASH_H
  37. #define __STM32F7xx_HAL_FLASH_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal_def.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup FLASH
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief FLASH Procedure structure definition
  55. */
  56. typedef enum
  57. {
  58. FLASH_PROC_NONE = 0U,
  59. FLASH_PROC_SECTERASE,
  60. FLASH_PROC_MASSERASE,
  61. FLASH_PROC_PROGRAM
  62. } FLASH_ProcedureTypeDef;
  63. /**
  64. * @brief FLASH handle Structure definition
  65. */
  66. typedef struct
  67. {
  68. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
  69. __IO uint32_t NbSectorsToErase; /* Internal variable to save the remaining sectors to erase in IT context */
  70. __IO uint8_t VoltageForErase; /* Internal variable to provide voltage range selected by user in IT context */
  71. __IO uint32_t Sector; /* Internal variable to define the current sector which is erasing */
  72. __IO uint32_t Address; /* Internal variable to save address selected for program */
  73. HAL_LockTypeDef Lock; /* FLASH locking object */
  74. __IO uint32_t ErrorCode; /* FLASH error code */
  75. }FLASH_ProcessTypeDef;
  76. /**
  77. * @}
  78. */
  79. /* Exported constants --------------------------------------------------------*/
  80. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  81. * @{
  82. */
  83. /** @defgroup FLASH_Error_Code FLASH Error Code
  84. * @brief FLASH Error Code
  85. * @{
  86. */
  87. #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  88. #define HAL_FLASH_ERROR_ERS ((uint32_t)0x00000002U) /*!< Programming Sequence error */
  89. #define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004U) /*!< Programming Parallelism error */
  90. #define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008U) /*!< Programming Alignment error */
  91. #define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010U) /*!< Write protection error */
  92. #define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020U) /*!< Operation Error */
  93. #define HAL_FLASH_ERROR_RD ((uint32_t)0x00000040U) /*!< Read Protection Error */
  94. /**
  95. * @}
  96. */
  97. /** @defgroup FLASH_Type_Program FLASH Type Program
  98. * @{
  99. */
  100. #define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00U) /*!< Program byte (8-bit) at a specified address */
  101. #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01U) /*!< Program a half-word (16-bit) at a specified address */
  102. #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02U) /*!< Program a word (32-bit) at a specified address */
  103. #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03U) /*!< Program a double word (64-bit) at a specified address */
  104. /**
  105. * @}
  106. */
  107. /** @defgroup FLASH_Flag_definition FLASH Flag definition
  108. * @brief Flag definition
  109. * @{
  110. */
  111. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
  112. #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */
  113. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  114. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
  115. #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
  116. #define FLASH_FLAG_ERSERR FLASH_SR_ERSERR /*!< FLASH Erasing Sequence error flag */
  117. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  118. #if defined (FLASH_OPTCR2_PCROP)
  119. #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH Read protection error flag */
  120. #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
  121. FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR | FLASH_FLAG_RDERR)
  122. #else
  123. #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
  124. FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR)
  125. #endif /* FLASH_OPTCR2_PCROP */
  126. /**
  127. * @}
  128. */
  129. /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
  130. * @brief FLASH Interrupt definition
  131. * @{
  132. */
  133. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  134. #define FLASH_IT_ERR ((uint32_t)0x02000000U) /*!< Error Interrupt source */
  135. /**
  136. * @}
  137. */
  138. /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
  139. * @{
  140. */
  141. #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000U)
  142. #define FLASH_PSIZE_HALF_WORD ((uint32_t)FLASH_CR_PSIZE_0)
  143. #define FLASH_PSIZE_WORD ((uint32_t)FLASH_CR_PSIZE_1)
  144. #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)FLASH_CR_PSIZE)
  145. #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFFU)
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FLASH_Keys FLASH Keys
  150. * @{
  151. */
  152. #define FLASH_KEY1 ((uint32_t)0x45670123U)
  153. #define FLASH_KEY2 ((uint32_t)0xCDEF89ABU)
  154. #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3BU)
  155. #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7FU)
  156. /**
  157. * @}
  158. */
  159. /** @defgroup FLASH_Sectors FLASH Sectors
  160. * @{
  161. */
  162. #if (FLASH_SECTOR_TOTAL == 2)
  163. #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
  164. #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
  165. #elif (FLASH_SECTOR_TOTAL == 4)
  166. #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
  167. #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
  168. #define FLASH_SECTOR_2 ((uint32_t)2U) /*!< Sector Number 2 */
  169. #define FLASH_SECTOR_3 ((uint32_t)3U) /*!< Sector Number 3 */
  170. #else
  171. #define FLASH_SECTOR_0 ((uint32_t)0U) /*!< Sector Number 0 */
  172. #define FLASH_SECTOR_1 ((uint32_t)1U) /*!< Sector Number 1 */
  173. #define FLASH_SECTOR_2 ((uint32_t)2U) /*!< Sector Number 2 */
  174. #define FLASH_SECTOR_3 ((uint32_t)3U) /*!< Sector Number 3 */
  175. #define FLASH_SECTOR_4 ((uint32_t)4U) /*!< Sector Number 4 */
  176. #define FLASH_SECTOR_5 ((uint32_t)5U) /*!< Sector Number 5 */
  177. #define FLASH_SECTOR_6 ((uint32_t)6U) /*!< Sector Number 6 */
  178. #define FLASH_SECTOR_7 ((uint32_t)7U) /*!< Sector Number 7 */
  179. #endif /* FLASH_SECTOR_TOTAL */
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @}
  185. */
  186. /* Exported macro ------------------------------------------------------------*/
  187. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  188. * @{
  189. */
  190. /**
  191. * @brief Set the FLASH Latency.
  192. * @param __LATENCY__ FLASH Latency
  193. * The value of this parameter depend on device used within the same series
  194. * @retval none
  195. */
  196. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
  197. MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
  198. /**
  199. * @brief Get the FLASH Latency.
  200. * @retval FLASH Latency
  201. * The value of this parameter depend on device used within the same series
  202. */
  203. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  204. /**
  205. * @brief Enable the FLASH prefetch buffer.
  206. * @retval none
  207. */
  208. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
  209. /**
  210. * @brief Disable the FLASH prefetch buffer.
  211. * @retval none
  212. */
  213. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
  214. /**
  215. * @brief Enable the FLASH Adaptive Real-Time memory accelerator.
  216. * @note The ART accelerator is available only for flash access on ITCM interface.
  217. * @retval none
  218. */
  219. #define __HAL_FLASH_ART_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
  220. /**
  221. * @brief Disable the FLASH Adaptive Real-Time memory accelerator.
  222. * @retval none
  223. */
  224. #define __HAL_FLASH_ART_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
  225. /**
  226. * @brief Resets the FLASH Adaptive Real-Time memory accelerator.
  227. * @note This function must be used only when the Adaptive Real-Time memory accelerator
  228. * is disabled.
  229. * @retval None
  230. */
  231. #define __HAL_FLASH_ART_RESET() (FLASH->ACR |= FLASH_ACR_ARTRST)
  232. /**
  233. * @brief Enable the specified FLASH interrupt.
  234. * @param __INTERRUPT__ FLASH interrupt
  235. * This parameter can be any combination of the following values:
  236. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  237. * @arg FLASH_IT_ERR: Error Interrupt
  238. * @retval none
  239. */
  240. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
  241. /**
  242. * @brief Disable the specified FLASH interrupt.
  243. * @param __INTERRUPT__ FLASH interrupt
  244. * This parameter can be any combination of the following values:
  245. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  246. * @arg FLASH_IT_ERR: Error Interrupt
  247. * @retval none
  248. */
  249. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
  250. /**
  251. * @brief Get the specified FLASH flag status.
  252. * @param __FLAG__ specifies the FLASH flag to check.
  253. * This parameter can be one of the following values:
  254. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  255. * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
  256. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  257. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  258. * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
  259. * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
  260. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  261. * @retval The new state of __FLAG__ (SET or RESET).
  262. */
  263. #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
  264. /**
  265. * @brief Clear the specified FLASH flag.
  266. * @param __FLAG__ specifies the FLASH flags to clear.
  267. * This parameter can be any combination of the following values:
  268. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  269. * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
  270. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  271. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  272. * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
  273. * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
  274. * @retval none
  275. */
  276. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
  277. /**
  278. * @}
  279. */
  280. /* Include FLASH HAL Extension module */
  281. #include "stm32f7xx_hal_flash_ex.h"
  282. /* Exported functions --------------------------------------------------------*/
  283. /** @addtogroup FLASH_Exported_Functions
  284. * @{
  285. */
  286. /** @addtogroup FLASH_Exported_Functions_Group1
  287. * @{
  288. */
  289. /* Program operation functions ***********************************************/
  290. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  291. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  292. /* FLASH IRQ handler method */
  293. void HAL_FLASH_IRQHandler(void);
  294. /* Callbacks in non blocking modes */
  295. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  296. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup FLASH_Exported_Functions_Group2
  301. * @{
  302. */
  303. /* Peripheral Control functions **********************************************/
  304. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  305. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  306. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  307. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  308. /* Option bytes control */
  309. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  310. /**
  311. * @}
  312. */
  313. /** @addtogroup FLASH_Exported_Functions_Group3
  314. * @{
  315. */
  316. /* Peripheral State functions ************************************************/
  317. uint32_t HAL_FLASH_GetError(void);
  318. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  319. /**
  320. * @}
  321. */
  322. /**
  323. * @}
  324. */
  325. /* Private types -------------------------------------------------------------*/
  326. /* Private variables ---------------------------------------------------------*/
  327. /** @defgroup FLASH_Private_Variables FLASH Private Variables
  328. * @{
  329. */
  330. /**
  331. * @}
  332. */
  333. /* Private constants ---------------------------------------------------------*/
  334. /** @defgroup FLASH_Private_Constants FLASH Private Constants
  335. * @{
  336. */
  337. /**
  338. * @brief OPTCR register byte 1 (Bits[15:8]) base address
  339. */
  340. #define OPTCR_BYTE1_ADDRESS ((uint32_t)0x40023C15)
  341. /**
  342. * @}
  343. */
  344. /* Private macros ------------------------------------------------------------*/
  345. /** @defgroup FLASH_Private_Macros FLASH Private Macros
  346. * @{
  347. */
  348. /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
  349. * @{
  350. */
  351. #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
  352. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  353. ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
  354. ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
  355. /**
  356. * @}
  357. */
  358. /**
  359. * @}
  360. */
  361. /* Private functions ---------------------------------------------------------*/
  362. /** @defgroup FLASH_Private_Functions FLASH Private Functions
  363. * @{
  364. */
  365. /**
  366. * @}
  367. */
  368. /**
  369. * @}
  370. */
  371. /**
  372. * @}
  373. */
  374. #ifdef __cplusplus
  375. }
  376. #endif
  377. #endif /* __STM32F7xx_HAL_FLASH_H */
  378. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/