stm32f1xx_hal_flash.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of Flash HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 __STM32F1xx_HAL_FLASH_H
  19. #define __STM32F1xx_HAL_FLASH_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f1xx_hal_def.h"
  25. /** @addtogroup STM32F1xx_HAL_Driver
  26. * @{
  27. */
  28. /** @addtogroup FLASH
  29. * @{
  30. */
  31. /** @addtogroup FLASH_Private_Constants
  32. * @{
  33. */
  34. #define FLASH_TIMEOUT_VALUE 50000U /* 50 s */
  35. /**
  36. * @}
  37. */
  38. /** @addtogroup FLASH_Private_Macros
  39. * @{
  40. */
  41. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  42. ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \
  43. ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))
  44. #if defined(FLASH_ACR_LATENCY)
  45. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  46. ((__LATENCY__) == FLASH_LATENCY_1) || \
  47. ((__LATENCY__) == FLASH_LATENCY_2))
  48. #else
  49. #define IS_FLASH_LATENCY(__LATENCY__) ((__LATENCY__) == FLASH_LATENCY_0)
  50. #endif /* FLASH_ACR_LATENCY */
  51. /**
  52. * @}
  53. */
  54. /* Exported types ------------------------------------------------------------*/
  55. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  56. * @{
  57. */
  58. /**
  59. * @brief FLASH Procedure structure definition
  60. */
  61. typedef enum
  62. {
  63. FLASH_PROC_NONE = 0U,
  64. FLASH_PROC_PAGEERASE = 1U,
  65. FLASH_PROC_MASSERASE = 2U,
  66. FLASH_PROC_PROGRAMHALFWORD = 3U,
  67. FLASH_PROC_PROGRAMWORD = 4U,
  68. FLASH_PROC_PROGRAMDOUBLEWORD = 5U
  69. } FLASH_ProcedureTypeDef;
  70. /**
  71. * @brief FLASH handle Structure definition
  72. */
  73. typedef struct
  74. {
  75. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  76. __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
  77. __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */
  78. __IO uint64_t Data; /*!< Internal variable to save data to be programmed */
  79. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  80. __IO uint32_t ErrorCode; /*!< FLASH error code
  81. This parameter can be a value of @ref FLASH_Error_Codes */
  82. } FLASH_ProcessTypeDef;
  83. /**
  84. * @}
  85. */
  86. /* Exported constants --------------------------------------------------------*/
  87. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  88. * @{
  89. */
  90. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  91. * @{
  92. */
  93. #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */
  94. #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */
  95. #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */
  96. #define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup FLASH_Type_Program FLASH Type Program
  101. * @{
  102. */
  103. #define FLASH_TYPEPROGRAM_HALFWORD 0x01U /*!<Program a half-word (16-bit) at a specified address.*/
  104. #define FLASH_TYPEPROGRAM_WORD 0x02U /*!<Program a word (32-bit) at a specified address.*/
  105. #define FLASH_TYPEPROGRAM_DOUBLEWORD 0x03U /*!<Program a double word (64-bit) at a specified address*/
  106. /**
  107. * @}
  108. */
  109. #if defined(FLASH_ACR_LATENCY)
  110. /** @defgroup FLASH_Latency FLASH Latency
  111. * @{
  112. */
  113. #define FLASH_LATENCY_0 0x00000000U /*!< FLASH Zero Latency cycle */
  114. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_0 /*!< FLASH One Latency cycle */
  115. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_1 /*!< FLASH Two Latency cycles */
  116. /**
  117. * @}
  118. */
  119. #else
  120. /** @defgroup FLASH_Latency FLASH Latency
  121. * @{
  122. */
  123. #define FLASH_LATENCY_0 0x00000000U /*!< FLASH Zero Latency cycle */
  124. /**
  125. * @}
  126. */
  127. #endif /* FLASH_ACR_LATENCY */
  128. /**
  129. * @}
  130. */
  131. /* Exported macro ------------------------------------------------------------*/
  132. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  133. * @brief macros to control FLASH features
  134. * @{
  135. */
  136. /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
  137. * @brief macros to handle FLASH half cycle
  138. * @{
  139. */
  140. /**
  141. * @brief Enable the FLASH half cycle access.
  142. * @note half cycle access can only be used with a low-frequency clock of less than
  143. 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
  144. * @retval None
  145. */
  146. #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE() (FLASH->ACR |= FLASH_ACR_HLFCYA)
  147. /**
  148. * @brief Disable the FLASH half cycle access.
  149. * @note half cycle access can only be used with a low-frequency clock of less than
  150. 8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
  151. * @retval None
  152. */
  153. #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
  154. /**
  155. * @}
  156. */
  157. #if defined(FLASH_ACR_LATENCY)
  158. /** @defgroup FLASH_EM_Latency FLASH Latency
  159. * @brief macros to handle FLASH Latency
  160. * @{
  161. */
  162. /**
  163. * @brief Set the FLASH Latency.
  164. * @param __LATENCY__ FLASH Latency
  165. * The value of this parameter depend on device used within the same series
  166. * @retval None
  167. */
  168. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
  169. /**
  170. * @brief Get the FLASH Latency.
  171. * @retval FLASH Latency
  172. * The value of this parameter depend on device used within the same series
  173. */
  174. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  175. /**
  176. * @}
  177. */
  178. #endif /* FLASH_ACR_LATENCY */
  179. /** @defgroup FLASH_Prefetch FLASH Prefetch
  180. * @brief macros to handle FLASH Prefetch buffer
  181. * @{
  182. */
  183. /**
  184. * @brief Enable the FLASH prefetch buffer.
  185. * @retval None
  186. */
  187. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE)
  188. /**
  189. * @brief Disable the FLASH prefetch buffer.
  190. * @retval None
  191. */
  192. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. /* Include FLASH HAL Extended module */
  200. #include "stm32f1xx_hal_flash_ex.h"
  201. /* Exported functions --------------------------------------------------------*/
  202. /** @addtogroup FLASH_Exported_Functions
  203. * @{
  204. */
  205. /** @addtogroup FLASH_Exported_Functions_Group1
  206. * @{
  207. */
  208. /* IO operation functions *****************************************************/
  209. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  210. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  211. /* FLASH IRQ handler function */
  212. void HAL_FLASH_IRQHandler(void);
  213. /* Callbacks in non blocking modes */
  214. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  215. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  216. /**
  217. * @}
  218. */
  219. /** @addtogroup FLASH_Exported_Functions_Group2
  220. * @{
  221. */
  222. /* Peripheral Control functions ***********************************************/
  223. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  224. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  225. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  226. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  227. void HAL_FLASH_OB_Launch(void);
  228. /**
  229. * @}
  230. */
  231. /** @addtogroup FLASH_Exported_Functions_Group3
  232. * @{
  233. */
  234. /* Peripheral State and Error functions ***************************************/
  235. uint32_t HAL_FLASH_GetError(void);
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /* Private function -------------------------------------------------*/
  243. /** @addtogroup FLASH_Private_Functions
  244. * @{
  245. */
  246. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  247. #if defined(FLASH_BANK2_END)
  248. HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout);
  249. #endif /* FLASH_BANK2_END */
  250. /**
  251. * @}
  252. */
  253. /**
  254. * @}
  255. */
  256. /**
  257. * @}
  258. */
  259. #ifdef __cplusplus
  260. }
  261. #endif
  262. #endif /* __STM32F1xx_HAL_FLASH_H */