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.
 
 
 

397 lines
14 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of FLASH HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 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 = 0,
  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)0x00000000) /*!< No error */
  90. #define HAL_FLASH_ERROR_ERS ((uint32_t)0x00000002) /*!< Programming Sequence error */
  91. #define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004) /*!< Programming Parallelism error */
  92. #define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008) /*!< Programming Alignment error */
  93. #define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010) /*!< Write protection error */
  94. #define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020) /*!< Operation Error */
  95. /**
  96. * @}
  97. */
  98. /** @defgroup FLASH_Type_Program FLASH Type Program
  99. * @{
  100. */
  101. #define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address */
  102. #define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address */
  103. #define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */
  104. #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!< Program a double word (64-bit) at a specified address */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup FLASH_Flag_definition FLASH Flag definition
  109. * @brief Flag definition
  110. * @{
  111. */
  112. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
  113. #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */
  114. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  115. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
  116. #define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */
  117. #define FLASH_FLAG_ERSERR FLASH_SR_ERSERR /*!< FLASH Erasing Sequence error flag */
  118. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  119. /**
  120. * @}
  121. */
  122. /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
  123. * @brief FLASH Interrupt definition
  124. * @{
  125. */
  126. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  127. #define FLASH_IT_ERR ((uint32_t)0x02000000) /*!< Error Interrupt source */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
  132. * @{
  133. */
  134. #define FLASH_PSIZE_BYTE ((uint32_t)0x00000000)
  135. #define FLASH_PSIZE_HALF_WORD ((uint32_t)FLASH_CR_PSIZE_0)
  136. #define FLASH_PSIZE_WORD ((uint32_t)FLASH_CR_PSIZE_1)
  137. #define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)FLASH_CR_PSIZE)
  138. #define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
  139. /**
  140. * @}
  141. */
  142. /** @defgroup FLASH_Keys FLASH Keys
  143. * @{
  144. */
  145. #define FLASH_KEY1 ((uint32_t)0x45670123)
  146. #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
  147. #define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B)
  148. #define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F)
  149. /**
  150. * @}
  151. */
  152. /**
  153. * @}
  154. */
  155. /* Exported macro ------------------------------------------------------------*/
  156. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  157. * @{
  158. */
  159. /**
  160. * @brief Set the FLASH Latency.
  161. * @param __LATENCY__: FLASH Latency
  162. * The value of this parameter depend on device used within the same series
  163. * @retval none
  164. */
  165. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
  166. MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
  167. /**
  168. * @brief Get the FLASH Latency.
  169. * @retval FLASH Latency
  170. * The value of this parameter depend on device used within the same series
  171. */
  172. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  173. /**
  174. * @brief Enable the FLASH prefetch buffer.
  175. * @retval none
  176. */
  177. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN)
  178. /**
  179. * @brief Disable the FLASH prefetch buffer.
  180. * @retval none
  181. */
  182. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN))
  183. /**
  184. * @brief Enable the FLASH Adaptive Real-Time memory accelerator.
  185. * @note The ART accelerator is available only for flash access on ITCM interface.
  186. * @retval none
  187. */
  188. #define __HAL_FLASH_ART_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
  189. /**
  190. * @brief Disable the FLASH Adaptive Real-Time memory accelerator.
  191. * @retval none
  192. */
  193. #define __HAL_FLASH_ART_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ARTEN)
  194. /**
  195. * @brief Resets the FLASH Adaptive Real-Time memory accelerator.
  196. * @note This function must be used only when the Adaptive Real-Time memory accelerator
  197. * is disabled.
  198. * @retval None
  199. */
  200. #define __HAL_FLASH_ART_RESET() (FLASH->ACR |= FLASH_ACR_ARTRST)
  201. /**
  202. * @brief Enable the specified FLASH interrupt.
  203. * @param __INTERRUPT__ : FLASH interrupt
  204. * This parameter can be any combination of the following values:
  205. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  206. * @arg FLASH_IT_ERR: Error Interrupt
  207. * @retval none
  208. */
  209. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
  210. /**
  211. * @brief Disable the specified FLASH interrupt.
  212. * @param __INTERRUPT__ : FLASH interrupt
  213. * This parameter can be any combination of the following values:
  214. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  215. * @arg FLASH_IT_ERR: Error Interrupt
  216. * @retval none
  217. */
  218. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__))
  219. /**
  220. * @brief Get the specified FLASH flag status.
  221. * @param __FLAG__: specifies the FLASH flag to check.
  222. * This parameter can be one of the following values:
  223. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  224. * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
  225. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  226. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  227. * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
  228. * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
  229. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  230. * @retval The new state of __FLAG__ (SET or RESET).
  231. */
  232. #define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__)))
  233. /**
  234. * @brief Clear the specified FLASH flag.
  235. * @param __FLAG__: specifies the FLASH flags to clear.
  236. * This parameter can be any combination of the following values:
  237. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  238. * @arg FLASH_FLAG_OPERR : FLASH operation Error flag
  239. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  240. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  241. * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
  242. * @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag
  243. * @retval none
  244. */
  245. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__))
  246. /**
  247. * @}
  248. */
  249. /* Include FLASH HAL Extension module */
  250. #include "stm32f7xx_hal_flash_ex.h"
  251. /* Exported functions --------------------------------------------------------*/
  252. /** @addtogroup FLASH_Exported_Functions
  253. * @{
  254. */
  255. /** @addtogroup FLASH_Exported_Functions_Group1
  256. * @{
  257. */
  258. /* Program operation functions ***********************************************/
  259. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  260. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  261. /* FLASH IRQ handler method */
  262. void HAL_FLASH_IRQHandler(void);
  263. /* Callbacks in non blocking modes */
  264. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  265. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  266. /**
  267. * @}
  268. */
  269. /** @addtogroup FLASH_Exported_Functions_Group2
  270. * @{
  271. */
  272. /* Peripheral Control functions **********************************************/
  273. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  274. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  275. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  276. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  277. /* Option bytes control */
  278. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  279. /**
  280. * @}
  281. */
  282. /** @addtogroup FLASH_Exported_Functions_Group3
  283. * @{
  284. */
  285. /* Peripheral State functions ************************************************/
  286. uint32_t HAL_FLASH_GetError(void);
  287. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  288. /**
  289. * @}
  290. */
  291. /**
  292. * @}
  293. */
  294. /* Private types -------------------------------------------------------------*/
  295. /* Private variables ---------------------------------------------------------*/
  296. /** @defgroup FLASH_Private_Variables FLASH Private Variables
  297. * @{
  298. */
  299. /**
  300. * @}
  301. */
  302. /* Private constants ---------------------------------------------------------*/
  303. /** @defgroup FLASH_Private_Constants FLASH Private Constants
  304. * @{
  305. */
  306. /**
  307. * @}
  308. */
  309. /* Private macros ------------------------------------------------------------*/
  310. /** @defgroup FLASH_Private_Macros FLASH Private Macros
  311. * @{
  312. */
  313. /** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters
  314. * @{
  315. */
  316. #define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \
  317. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  318. ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
  319. ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
  320. /**
  321. * @}
  322. */
  323. /**
  324. * @}
  325. */
  326. /* Private functions ---------------------------------------------------------*/
  327. /** @defgroup FLASH_Private_Functions FLASH Private Functions
  328. * @{
  329. */
  330. /**
  331. * @}
  332. */
  333. /**
  334. * @}
  335. */
  336. /**
  337. * @}
  338. */
  339. #ifdef __cplusplus
  340. }
  341. #endif
  342. #endif /* __STM32F7xx_HAL_FLASH_H */
  343. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/