stm32f1xx_hal_flash.h 10 KB

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