stm32l1xx_hal_flash.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 5-September-2014
  7. * @brief Header file of Flash HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 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 __STM32L1xx_HAL_FLASH_H
  39. #define __STM32L1xx_HAL_FLASH_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l1xx_hal_def.h"
  45. /** @addtogroup STM32L1xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup FLASH
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief FLASH Error structure definition
  57. */
  58. typedef enum
  59. {
  60. FLASH_ERROR_SIZE = 0x01,
  61. FLASH_ERROR_OPTV = 0x02,
  62. FLASH_ERROR_OPTVUSR = 0x04,
  63. FLASH_ERROR_PGA = 0x08,
  64. FLASH_ERROR_WRP = 0x10,
  65. FLASH_ERROR_RD = 0x20,
  66. FLASH_ERROR_OPERATION = 0x40
  67. }FLASH_ErrorTypeDef;
  68. /**
  69. * @brief FLASH Procedure structure definition
  70. */
  71. typedef enum
  72. {
  73. FLASH_PROC_NONE = 0,
  74. FLASH_PROC_PAGEERASE,
  75. FLASH_PROC_PROGRAM
  76. } FLASH_ProcedureTypeDef;
  77. /**
  78. * @brief FLASH handle Structure definition
  79. */
  80. typedef struct
  81. {
  82. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*Internal variable to indicate which procedure is ongoing or not in IT context*/
  83. __IO uint32_t NbPagesToErase; /*Internal variable to save the remaining sectors to erase in IT context*/
  84. __IO uint32_t Page; /*Internal variable to define the current sector which is erasing*/
  85. __IO uint32_t Address; /*Internal variable to save address selected for program*/
  86. HAL_LockTypeDef Lock; /* FLASH locking object */
  87. __IO FLASH_ErrorTypeDef ErrorCode; /* FLASH error code */
  88. }FLASH_ProcessTypeDef;
  89. /**
  90. * @}
  91. */
  92. /** @addtogroup FLASH_Internal_Variables
  93. * @{
  94. */
  95. /**
  96. * @brief Variable used for Program/Erase sectors under interruption.
  97. * Put as extern as used also in flash_ex.c.
  98. */
  99. extern FLASH_ProcessTypeDef ProcFlash;
  100. /**
  101. * @}
  102. */
  103. /* Exported constants --------------------------------------------------------*/
  104. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  105. * @{
  106. */
  107. #define HAL_FLASH_TIMEOUT_VALUE ((uint32_t)50000) /* 50 s */
  108. #define FLASH_PAGE_SIZE ((uint32_t)256)
  109. /** @defgroup FLASH_Type_Program FLASH Type Program
  110. * @{
  111. */
  112. #define TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */
  113. #define IS_TYPEPROGRAMFLASH(_VALUE_) (((_VALUE_) == TYPEPROGRAM_WORD))
  114. /**
  115. * @}
  116. */
  117. /** @defgroup FLASH_Latency FLASH Latency
  118. * @{
  119. */
  120. #define FLASH_LATENCY_0 ((uint8_t)0x00) /*!< FLASH Zero Latency cycle */
  121. #define FLASH_LATENCY_1 ((uint8_t)0x01) /*!< FLASH One Latency cycle */
  122. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  123. ((__LATENCY__) == FLASH_LATENCY_1))
  124. /**
  125. * @}
  126. */
  127. /** @defgroup FLASH_Interrupts FLASH Interrupts
  128. * @{
  129. */
  130. #define FLASH_IT_EOP FLASH_PECR_EOPIE /*!< End of programming interrupt source */
  131. #define FLASH_IT_ERR FLASH_PECR_ERRIE /*!< Error interrupt source */
  132. /**
  133. * @}
  134. */
  135. /** @defgroup FLASH_Flags FLASH Flags
  136. * @{
  137. */
  138. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  139. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */
  140. #define FLASH_FLAG_ENDHV FLASH_SR_ENDHV /*!< FLASH End of High Voltage flag */
  141. #define FLASH_FLAG_READY FLASH_SR_READY /*!< FLASH Ready flag after low power mode */
  142. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */
  143. #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */
  144. #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */
  145. #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option Validity error flag */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FLASH_Keys FLASH Keys
  150. * @{
  151. */
  152. #define FLASH_PDKEY1 ((uint32_t)0x04152637) /*!< Flash power down key1 */
  153. #define FLASH_PDKEY2 ((uint32_t)0xFAFBFCFD) /*!< Flash power down key2: used with FLASH_PDKEY1
  154. to unlock the RUN_PD bit in FLASH_ACR */
  155. #define FLASH_PEKEY1 ((uint32_t)0x89ABCDEF) /*!< Flash program erase key1 */
  156. #define FLASH_PEKEY2 ((uint32_t)0x02030405) /*!< Flash program erase key: used with FLASH_PEKEY2
  157. to unlock the write access to the FLASH_PECR register and
  158. data EEPROM */
  159. #define FLASH_PRGKEY1 ((uint32_t)0x8C9DAEBF) /*!< Flash program memory key1 */
  160. #define FLASH_PRGKEY2 ((uint32_t)0x13141516) /*!< Flash program memory key2: used with FLASH_PRGKEY2
  161. to unlock the program memory */
  162. #define FLASH_OPTKEY1 ((uint32_t)0xFBEAD9C8) /*!< Flash option key1 */
  163. #define FLASH_OPTKEY2 ((uint32_t)0x24252627) /*!< Flash option key2: used with FLASH_OPTKEY1 to
  164. unlock the write access to the option byte block */
  165. /**
  166. * @}
  167. */
  168. #if defined ( __ICCARM__ )
  169. #define InterruptType_ACTLR_DISMCYCINT_Msk IntType_ACTLR_DISMCYCINT_Msk
  170. #endif
  171. /**
  172. * @}
  173. */
  174. /* Exported macro ------------------------------------------------------------*/
  175. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  176. * @{
  177. */
  178. /** @defgroup FLASH_Interrupt FLASH Interrupts
  179. * @brief macros to handle FLASH interrupts
  180. * @{
  181. */
  182. /**
  183. * @brief Enable the specified FLASH interrupt.
  184. * @param __INTERRUPT__ : FLASH interrupt
  185. * This parameter can be any combination of the following values:
  186. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  187. * @arg FLASH_IT_ERR: Error Interrupt
  188. * @retval none
  189. */
  190. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) ((FLASH->PECR) |= (__INTERRUPT__))
  191. /**
  192. * @brief Disable the specified FLASH interrupt.
  193. * @param __INTERRUPT__ : FLASH interrupt
  194. * This parameter can be any combination of the following values:
  195. * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
  196. * @arg FLASH_IT_ERR: Error Interrupt
  197. * @retval none
  198. */
  199. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) ((FLASH->PECR) &= ~(uint32_t)(__INTERRUPT__))
  200. /**
  201. * @brief Get the specified FLASH flag status.
  202. * @param __FLAG__: specifies the FLASH flag to check.
  203. * This parameter can be one of the following values:
  204. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  205. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  206. * @arg FLASH_FLAG_ENDHV : FLASH End of High Voltage flag
  207. * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode
  208. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  209. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  210. * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
  211. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error error flag
  212. * @arg FLASH_FLAG_OPTVERRUSR : FLASH Option UserValidity (available only Cat.3, Cat.4 and Cat.5 devices)
  213. * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (available only Cat.2 and Cat.3 devices)
  214. * @retval The new state of __FLAG__ (SET or RESET).
  215. */
  216. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  217. /**
  218. * @brief Clear the specified FLASH flag.
  219. * @param __FLAG__: specifies the FLASH flags to clear.
  220. * This parameter can be any combination of the following values:
  221. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  222. * @arg FLASH_FLAG_EOP : FLASH End of Operation flag
  223. * @arg FLASH_FLAG_ENDHV : FLASH End of High Voltage flag
  224. * @arg FLASH_FLAG_READY: FLASH Ready flag after low power mode
  225. * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
  226. * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
  227. * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
  228. * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error error flag
  229. * @arg FLASH_FLAG_OPTVERRUSR : FLASH Option UserValidity (available only Cat.3, Cat.4 and Cat.5 devices)
  230. * @arg FLASH_FLAG_RDERR : FLASH Read Protection error flag (PCROP) (available only Cat.2 and Cat.3 devices)
  231. * @retval none
  232. */
  233. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__))
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /* Include FLASH HAL Extension module */
  241. #include "stm32l1xx_hal_flash_ex.h"
  242. #include "stm32l1xx_hal_flash_ramfunc.h"
  243. /* Exported functions ------------------------------------------------------- */
  244. /** @addtogroup FLASH_Exported_Functions
  245. * @{
  246. */
  247. /** @addtogroup FLASH_Exported_Functions_Group1
  248. * @{
  249. */
  250. /**
  251. * @brief FLASH memory functions that can be executed from FLASH.
  252. */
  253. /* Program operation functions ***********************************************/
  254. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  255. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  256. /* FLASH IRQ handler function */
  257. void HAL_FLASH_IRQHandler(void);
  258. /* Callbacks in non blocking modes */
  259. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  260. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  261. /**
  262. * @}
  263. */
  264. /** @addtogroup FLASH_Exported_Functions_Group2
  265. * @{
  266. */
  267. /* FLASH Memory Programming functions *****************************************/
  268. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  269. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  270. /* Option Bytes Programming functions *****************************************/
  271. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  272. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  273. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  274. /**
  275. * @}
  276. */
  277. /** @addtogroup FLASH_Exported_Functions_Group3
  278. * @{
  279. */
  280. /* Peripheral State methods **************************************************/
  281. FLASH_ErrorTypeDef HAL_FLASH_GetError(void);
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. /** @addtogroup FLASH_Internal_Functions
  289. * @{
  290. */
  291. /**
  292. * @brief Function used internally by HAL FLASH driver.
  293. */
  294. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  295. /**
  296. * @}
  297. */
  298. /**
  299. * @}
  300. */
  301. /**
  302. * @}
  303. */
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307. #endif /* __STM32L1xx_HAL_FLASH_H */
  308. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/