stm32f1xx_hal_flash.h 10 KB

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