stm32f3xx_hal_flash.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @version V1.4.0
  6. * @date 16-December-2016
  7. * @brief Header file of Flash HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F3xx_HAL_FLASH_H
  39. #define __STM32F3xx_HAL_FLASH_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f3xx_hal_def.h"
  45. /** @addtogroup STM32F3xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup FLASH
  49. * @{
  50. */
  51. /** @addtogroup FLASH_Private_Constants
  52. * @{
  53. */
  54. #define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */
  55. /**
  56. * @}
  57. */
  58. /** @addtogroup FLASH_Private_Macros
  59. * @{
  60. */
  61. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  62. ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
  63. ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
  64. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  65. ((__LATENCY__) == FLASH_LATENCY_1) || \
  66. ((__LATENCY__) == FLASH_LATENCY_2))
  67. /**
  68. * @}
  69. */
  70. /* Exported types ------------------------------------------------------------*/
  71. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  72. * @{
  73. */
  74. /**
  75. * @brief FLASH Procedure structure definition
  76. */
  77. typedef enum
  78. {
  79. FLASH_PROC_NONE = 0U,
  80. FLASH_PROC_PAGEERASE = 1U,
  81. FLASH_PROC_MASSERASE = 2U,
  82. FLASH_PROC_PROGRAMHALFWORD = 3U,
  83. FLASH_PROC_PROGRAMWORD = 4U,
  84. FLASH_PROC_PROGRAMDOUBLEWORD = 5U
  85. } FLASH_ProcedureTypeDef;
  86. /**
  87. * @brief FLASH handle Structure definition
  88. */
  89. typedef struct
  90. {
  91. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  92. __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
  93. __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
  94. __IO uint64_t Data; /*!< Internal variable to save data to be programmed */
  95. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  96. __IO uint32_t ErrorCode; /*!< FLASH error code
  97. This parameter can be a value of @ref FLASH_Error_Codes */
  98. } FLASH_ProcessTypeDef;
  99. /**
  100. * @}
  101. */
  102. /* Exported constants --------------------------------------------------------*/
  103. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  104. * @{
  105. */
  106. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  107. * @{
  108. */
  109. #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
  110. #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */
  111. #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
  112. /**
  113. * @}
  114. */
  115. /** @defgroup FLASH_Type_Program FLASH Type Program
  116. * @{
  117. */
  118. #define FLASH_TYPEPROGRAM_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/
  119. #define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
  120. #define FLASH_TYPEPROGRAM_DOUBLEWORD (0x03U) /*!<Program a double word (64-bit) at a specified address*/
  121. /**
  122. * @}
  123. */
  124. /** @defgroup FLASH_Latency FLASH Latency
  125. * @{
  126. */
  127. #define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */
  128. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */
  129. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup FLASH_Flag_definition FLASH Flag definition
  134. * @{
  135. */
  136. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  137. #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
  138. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  139. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
  144. * @{
  145. */
  146. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  147. #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /* Exported macro ------------------------------------------------------------*/
  155. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  156. * @brief macros to control FLASH features
  157. * @{
  158. */
  159. /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
  160. * @brief macros to handle FLASH half cycle
  161. * @{
  162. */
  163. /**
  164. * @brief Enable the FLASH half cycle access.
  165. * @retval None
  166. */
  167. #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA)
  168. /**
  169. * @brief Disable the FLASH half cycle access.
  170. * @retval None
  171. */
  172. #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
  173. /**
  174. * @}
  175. */
  176. /** @defgroup FLASH_EM_Latency FLASH Latency
  177. * @brief macros to handle FLASH Latency
  178. * @{
  179. */
  180. /**
  181. * @brief Set the FLASH Latency.
  182. * @param __LATENCY__ FLASH Latency
  183. * This parameter can be one of the following values:
  184. * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
  185. * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
  186. * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles
  187. * @retval None
  188. */
  189. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
  190. /**
  191. * @brief Get the FLASH Latency.
  192. * @retval FLASH Latency
  193. * This parameter can be one of the following values:
  194. * @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle
  195. * @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle
  196. * @arg @ref FLASH_LATENCY_2 FLASH Two Latency cycles
  197. */
  198. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  199. /**
  200. * @}
  201. */
  202. /** @defgroup FLASH_Prefetch FLASH Prefetch
  203. * @brief macros to handle FLASH Prefetch buffer
  204. * @{
  205. */
  206. /**
  207. * @brief Enable the FLASH prefetch buffer.
  208. * @retval None
  209. */
  210. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
  211. /**
  212. * @brief Disable the FLASH prefetch buffer.
  213. * @retval None
  214. */
  215. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
  216. /**
  217. * @}
  218. */
  219. /** @defgroup FLASH_Interrupt FLASH Interrupts
  220. * @brief macros to handle FLASH interrupts
  221. * @{
  222. */
  223. /**
  224. * @brief Enable the specified FLASH interrupt.
  225. * @param __INTERRUPT__ FLASH interrupt
  226. * This parameter can be any combination of the following values:
  227. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  228. * @arg @ref FLASH_IT_ERR Error Interrupt
  229. * @retval none
  230. */
  231. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__))
  232. /**
  233. * @brief Disable the specified FLASH interrupt.
  234. * @param __INTERRUPT__ FLASH interrupt
  235. * This parameter can be any combination of the following values:
  236. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  237. * @arg @ref FLASH_IT_ERR Error Interrupt
  238. * @retval none
  239. */
  240. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__))
  241. /**
  242. * @brief Get the specified FLASH flag status.
  243. * @param __FLAG__ specifies the FLASH flag to check.
  244. * This parameter can be one of the following values:
  245. * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
  246. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  247. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  248. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  249. * @retval The new state of __FLAG__ (SET or RESET).
  250. */
  251. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  252. /**
  253. * @brief Clear the specified FLASH flag.
  254. * @param __FLAG__ specifies the FLASH flags to clear.
  255. * This parameter can be any combination of the following values:
  256. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  257. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  258. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  259. * @retval none
  260. */
  261. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @}
  267. */
  268. /* Include FLASH HAL Extended module */
  269. #include "stm32f3xx_hal_flash_ex.h"
  270. /* Exported functions --------------------------------------------------------*/
  271. /** @addtogroup FLASH_Exported_Functions
  272. * @{
  273. */
  274. /** @addtogroup FLASH_Exported_Functions_Group1
  275. * @{
  276. */
  277. /* IO operation functions *****************************************************/
  278. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  279. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  280. /* FLASH IRQ handler function */
  281. void HAL_FLASH_IRQHandler(void);
  282. /* Callbacks in non blocking modes */
  283. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  284. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  285. /**
  286. * @}
  287. */
  288. /** @addtogroup FLASH_Exported_Functions_Group2
  289. * @{
  290. */
  291. /* Peripheral Control functions ***********************************************/
  292. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  293. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  294. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  295. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  296. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup FLASH_Exported_Functions_Group3
  301. * @{
  302. */
  303. /* Peripheral State and Error functions ***************************************/
  304. uint32_t HAL_FLASH_GetError(void);
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. /* Private function -------------------------------------------------*/
  312. /** @addtogroup FLASH_Private_Functions
  313. * @{
  314. */
  315. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  316. /**
  317. * @}
  318. */
  319. /**
  320. * @}
  321. */
  322. /**
  323. * @}
  324. */
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. #endif /* __STM32F3xx_HAL_FLASH_H */
  329. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/