You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

427 lines
15 KiB

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