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.
 
 
 

370 lines
11 KiB

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